Target.pas 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. unit Target;
  2. interface
  3. uses
  4. DragDrop,
  5. DropTarget,
  6. DragDropFormats,
  7. DragDropText,
  8. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  9. ExtCtrls, StdCtrls;
  10. type
  11. TFormTarget = class(TForm)
  12. Panel2: TPanel;
  13. PanelDest: TPanel;
  14. DropTextTarget1: TDropTextTarget;
  15. Panel5: TPanel;
  16. procedure DropTextTarget1Drop(Sender: TObject; ShiftState: TShiftState;
  17. Point: TPoint; var Effect: Integer);
  18. procedure FormCreate(Sender: TObject);
  19. private
  20. { Private declarations }
  21. TimeDataFormatTarget: TGenericDataFormat;
  22. public
  23. { Public declarations }
  24. end;
  25. var
  26. FormTarget: TFormTarget;
  27. implementation
  28. {$R *.DFM}
  29. uses
  30. DragDropTimeOfDay; // defines the TTimeOfDay structure.
  31. procedure TFormTarget.FormCreate(Sender: TObject);
  32. begin
  33. // Define and register our custom clipboard format.
  34. // This needs to be done for both the drop source and target.
  35. TimeDataFormatTarget := TGenericDataFormat.Create(DropTextTarget1);
  36. TimeDataFormatTarget.AddFormat(sTimeOfDayName);
  37. end;
  38. procedure TFormTarget.DropTextTarget1Drop(Sender: TObject;
  39. ShiftState: TShiftState; Point: TPoint; var Effect: Integer);
  40. var
  41. TOD: TTimeOfDay;
  42. Time: TDateTime;
  43. begin
  44. // Determine if we got our custom format.
  45. if (TimeDataFormatTarget.HasData) then
  46. begin
  47. // Extract the dropped data into our custom struct.
  48. TimeDataFormatTarget.GetDataHere(TOD, sizeof(TOD));
  49. // Convert the time-of-day info to a TDateTime so we can display it.
  50. Time := EncodeTime(TOD.hours, TOD.minutes, TOD.seconds, TOD.milliseconds);
  51. // Display the data.
  52. PanelDest.Caption := FormatDateTime('hh:nn:ss.zzz', Time);
  53. PanelDest.Color := TOD.color;
  54. PanelDest.Font.Color := not(PanelDest.Color) and $FFFFFF;
  55. end else
  56. PanelDest.Caption := TDropTextTarget(Sender).Text;
  57. end;
  58. end.