procedure TForm1.FormCreate(Sender: TObject);
begin
//本来は設計時に設定してください
Listbox1.DragMode :=dmAutomatic;
end;
procedure TForm1.Edit1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
//ドラッグ元がTListboxで項目が選択されている場合のみ受入れ可に
Accept :=(Source is TListbox) and
(Listbox1.ItemIndex <> -1);
end;
procedure TForm1.Edit1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
//ListBox1の選択文字列ををEdit1にコピー
Edit1.Text :=(Source as TListBox).Items[Listbox1.ItemIndex];
end; |