Recent

Author Topic: Drag and Drop a TButton object on the Form  (Read 16066 times)

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Drag and Drop a TButton object on the Form
« Reply #15 on: August 23, 2009, 03:11:19 am »
I don't really get what you're after, but this seems like a logical problem in your code, not really a Pascal/Lazarus problem.
try
Brain.Enabled:=true;
;-)

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Drag and Drop a TButton object on the Form
« Reply #16 on: August 23, 2009, 08:21:53 am »

Quote
Brain.Enabled:=true;

I agree with you, but none of the components have this property. :)
Thanks.

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Drag and Drop a TButton object on the Form
« Reply #17 on: August 24, 2009, 08:47:14 am »

@theo, I have a simple question.
I want to trigger ButtonsClick from inside the FormClick procedure?
How can I trigger any event?
Thanks.

procedure TForm1.ButtonsClick(Sender: TObject);
begin
  indexno:=(Sender as TButton).ComponentIndex;
  StatusBar1.SimpleText:=inttostr(indexno);
end;

procedure TForm1.FormClick(Sender: TObject);
begin
     if buttonclick then
        begin
     With TButton.Create(self) do
          begin
               Parent:=self;
               Name:='';
               Left:=p.x;
               Top:=p.y;
               Width:=60;
               Height:=20;
               OnClick:=@ButtonsClick;
               OnMouseDown:=@ButtonsMouseDown;
          end;
        end;

     buttonclick:=false;
     BitBtn1.Enabled:=true;
end;                                               

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Drag and Drop a TButton object on the Form
« Reply #18 on: August 24, 2009, 11:14:11 am »
I want to trigger ButtonsClick from inside the FormClick procedure?
How can I trigger any event?

Do you really want to trigger it or just call the event handler?
I guess it's the latter, so just call
ButtonsClick(MyButton);

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Drag and Drop a TButton object on the Form
« Reply #19 on: August 24, 2009, 12:37:43 pm »

I used like this in the Procedure FormClick:

procedure TForm1.FormClick(Sender: TObject);
begin
     if buttonclick then
        begin
     With TButton.Create(self) do
          begin
               Parent:=self;
               Name:='';
               Left:=p.x;
               Top:=p.y;
               Width:=60;
               Height:=20;
               OnClick:=@ButtonsClick;
               OnMouseDown:=@ButtonsMouseDown;
          end;
        end;
ButtonsClick(Components[indexno]);
     buttonclick:=false;
     BitBtn1.Enabled:=true;
end;                                               

When I execute the application and put a tbutton on the form, I get the following error at the line   indexno:=(Sender as TButton).ComponentIndex; 
Project project1 raised exception class 'RunError(219)'.
Thanks

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Drag and Drop a TButton object on the Form
« Reply #20 on: August 24, 2009, 02:06:53 pm »
Then don't use "with".

Code: [Select]
aButton:=TButton.Create(self);
aButton.Parent:=self;
...
ButtonsClick(aButton);

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Drag and Drop a TButton object on the Form
« Reply #21 on: August 24, 2009, 06:32:50 pm »

@theo, thank for your help, without 'with' works perfect.
Best Regards.

rocotilos

  • New Member
  • *
  • Posts: 24
Re: Drag and Drop a TButton object on the Form
« Reply #22 on: September 05, 2009, 08:50:08 pm »
Other way is to use the TAG property. So u can refer the button with the tag number. Eg, if u have 10 buttons. button 1 have a tag of 1, etc..

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Drag and Drop a TButton object on the Form
« Reply #23 on: September 07, 2009, 08:38:56 am »

Thanks for the information,
Anyway I have another question, Is it possible to drop a tbutton on the TImage on runtime?

aButton:=TButton.Create(self);
Can I use aButton.Parent:=Image1 instead of aButton.Parent:=self;
Thanks


 

TinyPortal © 2005-2018