Target.pas 1.7 KB

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