Board index » delphi » How can I create an Editfield during runtime?

How can I create an Editfield during runtime?

Hi
Friend of mine wrote the following code

Type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    t : TEdit;
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

Var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  t := TEdit.Create(Form1);
  t.Left := 30;
  t.Top := 10;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  t.Destroy;
  Close;
end;

The Program should create - and show - an EditField at the defined position
in the Form by clicking button1
and remove it with button2.
The Editfield is not visible when I execute this program but I can handle
with its properties?
How can I make it visible???

Thanks in advance

steno

 

Re:How can I create an Editfield during runtime?


It doesn't show until you set it's parent property.

steno <e9725...@stud3.tuwien.ac.at> skrev i en
nyhedsmeddelelse:7gkst6$g0...@news.tuwien.ac.at...

Quote
> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   t := TEdit.Create(Form1);
>   t.Left := 30;
>   t.Top := 10;
> end;
> How can I make it visible???

Re:How can I create an Editfield during runtime?


Set t.parent to Form1.
/js

In article <7gkst6$g0...@news.tuwien.ac.at>, "steno"

Quote
<e9725...@stud3.tuwien.ac.at> writes:
>Hi
>Friend of mine wrote the following code

>Type
>  TForm1 = class(TForm)
>    Button1: TButton;
>    Button2: TButton;
>    procedure Button1Click(Sender: TObject);
>    procedure Button2Click(Sender: TObject);
>  private
>    t : TEdit;
>    { Private-Deklarationen }
>  public
>    { Public-Deklarationen }
>  end;

>Var
>  Form1: TForm1;

>implementation

>{$R *.DFM}

>procedure TForm1.Button1Click(Sender: TObject);
>begin
>  t := TEdit.Create(Form1);
>  t.Left := 30;
>  t.Top := 10;
>end;

>procedure TForm1.Button2Click(Sender: TObject);
>begin
>  t.Destroy;
>  Close;
>end;

>The Program should create - and show - an EditField at the defined position
>in the Form by clicking button1
>and remove it with button2.
>The Editfield is not visible when I execute this program but I can handle
>with its properties?
>How can I make it visible???

>Thanks in advance

>steno

Re:How can I create an Editfield during runtime?


Isn't it better to use InsertComponent ? I'm wondering if the controls will
be freed from memory if it's not in the form's component-list.

Other Threads