Source.pas 2.3 KB

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