home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sibdemo3.zip / SAMPLES.DAT / SAMPLES / DRAGDROP / INTERN / DRAGU1.PAS next >
Pascal/Delphi Source File  |  1997-07-28  |  3KB  |  76 lines

  1. Unit DragU1;
  2.  
  3. Interface
  4.  
  5. Uses
  6.   Classes, Forms, Graphics, StdCtrls, Buttons;
  7.  
  8. Type
  9.   TDragForm = Class (TForm)
  10.     Label1: TLabel;
  11.     Label2: TLabel;
  12.     Container1: TListBox;
  13.     Container2: TListBox;
  14.     Label3: TLabel;
  15.     Procedure ContainerOnEndDrag (Sender: TObject; Target: TObject;
  16.                                   X: LongInt; Y: LongInt);
  17.     Procedure ContainerOnDragDrop (Sender: TObject; Source: TObject;
  18.                                    X: LongInt; Y: LongInt);
  19.     Procedure ContainerOnDragOver (Sender: TObject; Source: TObject; X: LongInt;
  20.                                    Y: LongInt; State: TDragState;
  21.                                    Var Accept: Boolean);
  22.     Procedure ContainerOnCanDrag (Sender: TObject; X: LongInt; Y: LongInt;
  23.                                   Var Accept: Boolean);
  24.   Private
  25.     {Insert private declarations here}
  26.   Public
  27.     {Insert public declarations here}
  28.   End;
  29.  
  30. Var
  31.   DragForm: TDragForm;
  32.  
  33. Implementation
  34.  
  35. Procedure TDragForm.ContainerOnEndDrag (Sender: TObject; Target: TObject;
  36.                                         X: LongInt; Y: LongInt);
  37. Var t:LongInt;
  38. Begin
  39.    //remove items from source container
  40.    If ((Target=Container1)Or(Target=Container2)) And (Sender<>Target) Then
  41.      For t:=TListBox(Sender).Items.Count-1 DownTo 0 Do
  42.        If TListBox(Sender).Selected[t] Then TListBox(Sender).Items.Delete(t);
  43. End;
  44.  
  45. Procedure TDragForm.ContainerOnDragDrop (Sender: TObject; Source: TObject;
  46.                                       X: LongInt; Y: LongInt);
  47. Var t:LongInt;
  48. Begin
  49.     If ((Source=Container1)Or(Source=Container2)) Then
  50.      If ((Sender=Container1)Or(Sender=Container2)) Then
  51.        If Sender<>Source Then
  52.     Begin
  53.        //insert items into target container
  54.        For t:=0 To TListBox(Source).Items.Count-1 Do
  55.         If TListBox(Source).Selected[t] Then
  56.           TListBox(Sender).Items.Add(TListBox(Source).Items[t]);
  57.     End;
  58. End;
  59.  
  60. Procedure TDragForm.ContainerOnDragOver (Sender: TObject; Source: TObject;
  61.                                       X: LongInt; Y: LongInt;
  62.                                       State: TDragState; Var Accept: Boolean);
  63. Begin
  64.   Accept:=((Source=Container1)Or(Source=Container2)) And (Sender<>Source);
  65. End;
  66.  
  67. Procedure TDragForm.ContainerOnCanDrag (Sender: TObject; X: LongInt; Y: LongInt;
  68.                                      Var Accept: Boolean);
  69. Begin
  70.   Accept:=TListBox(Sender).SelCount>0;
  71. End;
  72.  
  73. Initialization
  74.   RegisterClasses ([TDragForm, TLabel, TListBox]);
  75. End.
  76.