Dragmode and ComponentIndex Chaos lazarus / 8-Other ---------------------------------------------------------------------- IndianaJones · 2009-08-31 19:14 Hi all, May be simple but irritating problem, i create a TButton (as usual) component like this.                a:=TButton.Create(self);                a.Parent:=self;                a.Name:='';                a.Left:=p.x;                a.Top:=p.y;                a.Width:=60;                a.Height:=20;                a.OnClick:=@ButtonsClick;                a.OnMouseDown:=@ButtonsMouseDown; and when click on the TButton object, i get the right ComponentIndex number, so works perfect. But if I add the following line for dragging and dropping object, ButtonsClick doesnt work so I get the wrong ComponentIndex (cos it doesnt work) What could be the problem? a.DragMode:= dmAutomatic; Thanks ---------------------------------------------------------------------- theo · 2009-08-31 19:20 I think it's time to read this: http://catb.org/esr/faqs/smart-questions.html#goal ;-) ---------------------------------------------------------------------- IndianaJones · 2009-08-31 19:57 Here is the detail. Hope it helps. 1) Each time clicking on the Form creates TButtons 2) p.x and p.y are the mouse coordinates of the TButtons that want to create. 3) Clicking every TButton returns indexno 4) So triggering ButtonsClick gives the right indexno 5) After Adding a.DragMode:= dmAutomatic; to the source 6) ButtonsClick doesnt work procedure TForm1.ButtonsClick(Sender: TObject); begin   indexno:=(Sender as TButton).ComponentIndex; end; procedure TForm1.FormClick(Sender: TObject); var   a: TButton; begin                a:=TButton.Create(self);                a.Parent:=self;                a.Name:='';                a.Left:=p.x;                a.Top:=p.y;                a.Width:=60;                a.Height:=20;                a.OnClick:=@ButtonsClick;                a.OnMouseDown:=@ButtonsMouseDown;                ButtonsClick(a); //               a.DragMode:= dmAutomatic; end; procedure TForm1.FormDragDrop(Sender, Source: TObject; X, Y: Integer); begin   if Source is TButton then     begin         TButton(Source).Left:=X;         TButton(Source).Top:=Y;     end; end; procedure TForm1.FormDragOver(Sender, Source: TObject; X, Y: Integer;   State: TDragState; var Accept: Boolean); begin     Accept:=(Source is TButton); end; ---------------------------------------------------------------------- theo · 2009-08-31 20:03 Quote from: IndianaJones on August 31, 2009, 09:57:30 pmHere is the detail. Hope it helps. No, not the detail, the goal! You said you want to code a diagram drawing application. But why do you need TButtons for drawing a diagram? ---------------------------------------------------------------------- IndianaJones · 2009-08-31 20:56 QuoteYou said you want to code a diagram drawing application.Yes, I want to code like a diagram drawing application. QuoteBut why do you need TButtons for drawing a diagram?Cos, User can drag drop, delete, rename, and make relation between two TButtons with drawing lines.(if possible. ) So these method much more simple than drawing onto form canvas. Briefly, putting TButtons to the Form and writing these informations (like: Top, Left, Caption or Name and Line relations, etc) to the database on the fly. P.S. Before you asked a question like that, why are you just drawing to the canvas and need TLine component? Because you cant resize, pull, bend or drag a canvas line. Thanks. ---------------------------------------------------------------------- theo · 2009-08-31 21:15 Not sure if good, but its your decision. About your orig. question: Do the same as in OnClick in OnStartDrag. ---------------------------------------------------------------------- IndianaJones · 2009-08-31 21:45 Sorry @theo, I didnt follow you, what do you mean? Do the same as in OnClick in OnStartDrag. ---------------------------------------------------------------------- IndianaJones · 2009-09-01 10:15 @theo, pardon me but can you explain what it means? Do the same as in OnClick in OnStartDrag. ---------------------------------------------------------------------- theo · 2009-09-01 14:59 Phew, obviously OnClick doesn't trigger when you start dragging, so why not use the OnStartDrag event for executing the code in ButtonsClick. Remember: Set Brain.Enabled:=True;