home *** CD-ROM | disk | FTP | other *** search
- unit Ddfman;
-
-
- { Simple Drag & Drop demo program, accompanying PC Plus (UK)
- magazine's Delphi programming column.
- Author: Huw Collingbourne
-
- Purpose:
- This illustrates how to use Drag and Drop events to let the
- user pick a file from a filelist and drop it into a memo
- shown in a separate window. The text of the file will then
- be loaded into the memo.
-
- Usage:
- Select a text-file (e,g. a .PAS or .TXT file) from the
- listing. Then, keeping the left mouse button pressed down, drag
- the cursor over the memo window.
-
- NOTE:
- This application does no error checking or exception-
- handling. A real-world app would need to disallow inappropriate
- file-types (possibly loading bitmap files into a TImage
- component). Delphi 1 users may also want to disallow or truncate long
- text files, since the Delphi 1 memo component has a limit of 32K. This
- limit is about 64K in Delphi 2 and above.
- }
-
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, FileCtrl, StdCtrls,
- DDMemo;
-
- type
- TForm1 = class(TForm)
- FileListBox1: TFileListBox;
- DirectoryListBox1: TDirectoryListBox;
- procedure FormShow(Sender: TObject);
- procedure FileListBox1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure DirectoryListBox1Change(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.FormShow(Sender: TObject);
- begin
- MemoForm.Show;
- end;
-
- procedure TForm1.FileListBox1MouseDown(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- with Sender as TFileListBox do
- begin
- if ItemAtPos(Point(X, Y), True) >= 0 then { if an item is selected }
- BeginDrag(True); { start dragging it }
- end;
-
- end;
-
- procedure TForm1.DirectoryListBox1Change(Sender: TObject);
- { if the directory is changed in the DirectoryListBox, show the list of }
- { files in the new directory. }
- begin
- FileListBox1.Directory := DirectoryListBox1.Directory;
- end;
-
- end.
-