home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / handson / archive / Issue145 / Delphi / CopyDelp.exe / DDPrj / ddfman.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-07-13  |  2.2 KB  |  81 lines

  1. unit Ddfman;
  2.  
  3.  
  4. { Simple Drag & Drop demo program, accompanying PC Plus (UK)
  5.   magazine's Delphi programming column.
  6.   Author: Huw Collingbourne
  7.  
  8.   Purpose:
  9.   This illustrates how to use Drag and Drop events to let the
  10.   user pick a file from a filelist and drop it into a memo
  11.   shown in a separate window. The text of the file will then
  12.   be loaded into the memo.
  13.  
  14.   Usage:
  15.   Select a text-file (e,g. a .PAS or .TXT file) from the
  16.   listing. Then, keeping the left mouse button pressed down, drag
  17.   the cursor over the memo window. 
  18.  
  19.   NOTE:
  20.   This application does no error checking or exception-
  21.   handling. A real-world app would need to disallow inappropriate
  22.   file-types (possibly loading bitmap files into a TImage
  23.   component). Delphi 1 users may also want to disallow or truncate long
  24.   text files, since the Delphi 1 memo component has a limit of 32K. This
  25.   limit is about 64K in Delphi 2 and above.
  26. }
  27.  
  28.  
  29. interface
  30.  
  31. uses
  32.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  33.   Forms, Dialogs, FileCtrl, StdCtrls,
  34.   DDMemo;
  35.  
  36. type
  37.   TForm1 = class(TForm)
  38.     FileListBox1: TFileListBox;
  39.     DirectoryListBox1: TDirectoryListBox;
  40.     procedure FormShow(Sender: TObject);
  41.     procedure FileListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  42.       Shift: TShiftState; X, Y: Integer);
  43.     procedure DirectoryListBox1Change(Sender: TObject);
  44.   private
  45.     { Private declarations }
  46.   public
  47.     { Public declarations }
  48.   end;
  49.  
  50. var
  51.   Form1: TForm1;
  52.  
  53. implementation
  54.  
  55. {$R *.DFM}
  56.  
  57. procedure TForm1.FormShow(Sender: TObject);
  58. begin
  59.  MemoForm.Show;
  60. end;
  61.  
  62. procedure TForm1.FileListBox1MouseDown(Sender: TObject;
  63.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  64. begin
  65.     with Sender as TFileListBox do
  66.     begin
  67.       if ItemAtPos(Point(X, Y), True) >= 0 then    { if an item is selected }
  68.         BeginDrag(True);                    { start dragging it      }
  69.     end;
  70.  
  71. end;
  72.  
  73. procedure TForm1.DirectoryListBox1Change(Sender: TObject);
  74. { if the directory is changed in the DirectoryListBox, show the list of }
  75. { files in the new directory.                                           }
  76. begin
  77.   FileListBox1.Directory := DirectoryListBox1.Directory;
  78. end;
  79.  
  80. end.
  81.