home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / handson / archive / Issue145 / Delphi / DDPrj / ddmemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-07-31  |  1.5 KB  |  61 lines

  1. unit Ddmemo;
  2.  
  3.  
  4. interface
  5.  
  6. uses
  7.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  8.   Forms, Dialogs, StdCtrls, FileCtrl;
  9.  
  10. type
  11.   TMemoForm = class(TForm)
  12.     Memo1: TMemo;
  13.     procedure Memo1DragDrop(Sender, Source: TObject; X, Y: Integer);
  14.     procedure Memo1DragOver(Sender, Source: TObject; X, Y: Integer;
  15.       State: TDragState; var Accept: Boolean);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22. var
  23.   MemoForm: TMemoForm;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28.  
  29. procedure TMemoForm.Memo1DragDrop(Sender, Source: TObject; X, Y: Integer);
  30. { Check that the Source of the drag operation is a File List Box. If so,
  31.   load the contents of that file into the memo }
  32. var
  33.   filename : string;
  34. begin
  35.  if Source is TFileListBox then
  36.  begin
  37.     filename := (Source as TFileListBox).Items.Strings[
  38.                 (Source as TFileListBox).ItemIndex];
  39.     if FileExists(filename) Then
  40.       begin
  41.           Memo1.Lines.LoadFromFile(filename);
  42.           Caption := filename;
  43.       end
  44.       else
  45.         MessageDlg('Sorry. Can''t find the file. '+ filename + '!',
  46.                         mtInformation, [mbOK], 0);
  47.     end;
  48.  
  49. end;
  50.  
  51. procedure TMemoForm.Memo1DragOver(Sender, Source: TObject; X, Y: Integer;
  52.   State: TDragState; var Accept: Boolean);
  53. { Accept determines whether the Sender (the target of the drag-drop operation)
  54.   can respond to the Source (the object which initiated the drag-drop operation)
  55.   Accept defaults to false. }
  56. begin
  57.   Accept := true;
  58. end;
  59.  
  60. end.
  61.