Source.pas 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. unit Source;
  2. interface
  3. uses
  4. DragDrop,
  5. DropSource,
  6. DragDropFormats,
  7. DragDropText,
  8. DragDropTimeOfDay,
  9. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  10. ExtCtrls, StdCtrls;
  11. type
  12. TFormSource = class(TForm)
  13. Panel1: TPanel;
  14. PanelSource: TPanel;
  15. Timer1: TTimer;
  16. DropTextSource1: TDropTextSource;
  17. Panel3: TPanel;
  18. Memo1: TMemo;
  19. Panel4: TPanel;
  20. procedure Timer1Timer(Sender: TObject);
  21. procedure PanelSourceMouseDown(Sender: TObject; Button: TMouseButton;
  22. Shift: TShiftState; X, Y: Integer);
  23. procedure FormCreate(Sender: TObject);
  24. private
  25. { Private declarations }
  26. TimeOfDayDataFormat: TTimeOfDayDataFormat;
  27. public
  28. { Public declarations }
  29. end;
  30. var
  31. FormSource: TFormSource;
  32. implementation
  33. {$R *.DFM}
  34. procedure TFormSource.FormCreate(Sender: TObject);
  35. begin
  36. // Add our custom data and clipboard format to the drag/drop component.
  37. // This needs to be done for both the drop source and target.
  38. TimeOfDayDataFormat := TTimeOfDayDataFormat.Create(DropTextSource1);
  39. end;
  40. procedure TFormSource.Timer1Timer(Sender: TObject);
  41. begin
  42. PanelSource.Caption := FormatDateTime('hh:nn:ss.zzz', Now);
  43. PanelSource.Color := random($FFFFFF);
  44. PanelSource.Font.Color := not(PanelSource.Color) and $FFFFFF;
  45. end;
  46. procedure TFormSource.PanelSourceMouseDown(Sender: TObject;
  47. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  48. var
  49. TOD: TTimeOfDay;
  50. begin
  51. Timer1.Enabled := False;
  52. try
  53. if (DragDetectPlus(Handle, Point(X,Y))) then
  54. begin
  55. // Transfer time as text. This is not nescessary and is only done to offer
  56. // maximum flexibility in case the user wishes to drag our data to some
  57. // other application (e.g. a word processor).
  58. DropTextSource1.Text := PanelSource.Caption;
  59. // Store the current time in a structure. This structure is our custom
  60. // data format.
  61. DecodeTime(Now, TOD.hours, TOD.minutes, TOD.seconds, TOD.milliseconds);
  62. TOD.color := PanelSource.Color;
  63. // Transfer the structure to the drop source data object and execute the drag.
  64. TimeOfDayDataFormat.TOD := TOD;
  65. DropTextSource1.Execute;
  66. end;
  67. finally
  68. Timer1.Enabled := True;
  69. end;
  70. end;
  71. end.