Recent

Author Topic: How to put a component  (Read 8780 times)

LazaruX

  • Hero Member
  • *****
  • Posts: 597
  • Lazarus original cheetah.The cheetah doesn't cheat
How to put a component
« on: October 16, 2007, 12:01:25 pm »
I would like to know how to put a new component in the form without dragging it, but writing a code for it.
I though something like this:
Code: [Select]

application.create(tbutton);

but this does not work. any suggestions?
I only need to put imag components

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: How to put a component
« Reply #1 on: October 16, 2007, 12:17:37 pm »
Take a look at the hello example.

ssamayoa

  • Full Member
  • ***
  • Posts: 163
How to put a component
« Reply #2 on: October 16, 2007, 04:47:58 pm »
Code: [Select]

procedure TForm1.SomeMethod...
var
  Button: TButton;
begin
  Button := TButton.Create(Self);
  Button.Parent := Self;
  Button.Top := 50;
  Button.Left := 50;
  ...
end;

antonio

  • Hero Member
  • *****
  • Posts: 605
How to put a component
« Reply #3 on: October 16, 2007, 04:57:30 pm »
After use, you need to free it.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2707
How to put a component
« Reply #4 on: October 16, 2007, 06:25:37 pm »
You don't need to free it if you pass an owner (like in the example). Then the component is freed when the owner is freed
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

antonio

  • Hero Member
  • *****
  • Posts: 605
How to put a component
« Reply #5 on: October 16, 2007, 07:19:29 pm »
Sure. Sorry.

LazaruX

  • Hero Member
  • *****
  • Posts: 597
  • Lazarus original cheetah.The cheetah doesn't cheat
How to put a component
« Reply #6 on: October 17, 2007, 12:31:03 pm »
OK, thanks for your replies, and now another question before you understand what I mean better that I explain what I am making:
I am making a program that add's some things to the unit1.pas file, it add's this code:

procedure FormCreate.....
begin
...
....
end;

but then I need to click on the OnCreate event, otherwise the code will not work.
Is there a way to code the clicking of the OnCreate event?

I hope you understand what I mean.

ssamayoa

  • Full Member
  • ***
  • Posts: 163
How to put a component
« Reply #7 on: October 17, 2007, 06:21:17 pm »
CreateForm() event is called after form is created and components are loaded:

Code: [Select]

procedure TForm1.FormCreate(Sender: TObject);
begin
  // Put here your custom control creation
end;


Check in object inspector if form's event OnCreate is linked to FormCreate method.

LazaruX

  • Hero Member
  • *****
  • Posts: 597
  • Lazarus original cheetah.The cheetah doesn't cheat
How to put a component
« Reply #8 on: October 17, 2007, 06:53:29 pm »
Hi, thanks for the reply,
maybe I have not been clear, I will try to explain again what I mean:
is there a way to link the Object Inspector On create event directly to the FormCreate, without the need to go to the Object Inspector and click ther? Is there a way to code this linking?

antonio

  • Hero Member
  • *****
  • Posts: 605
How to put a component
« Reply #9 on: October 17, 2007, 07:24:01 pm »
form1.oncreate := @formcreate;

 

TinyPortal © 2005-2018