Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-06

Manually creating a form

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Koenraad Lelong

Hi,

I'm trying to manually create a form and in it's OnCreate event populate it with controls. But I'm doing somehing wrong.
This is my creating sequence :

  form2:=Tform2.Create(nil);
  form2.ShowModal;
  Form2.Destroy;

Nothing special I think.

This is a sample of the create-code :

procedure TForm2.FormCreate(Sender: TObject);
var
   i : integer;
   upper : integer;
begin
upper:=10;
for i:=0 to 4 do
  begin
    form2.Height:=form2.height+25;
    edits[i]:=Tedit.Create(self);
    edits[i].Parent:=form2;
    edits[i].Top:=upper;
    edits[i].Left:=10;
    upper:=upper+25;
  end;
end;

But when I run the code, I get a segfault at the location where I modify the form's height. If I remove that, I get the form but the edits do not show.

When I modify the code to automatically create the form this works. So I'm clearly missing something.

Any tips, links to documentation ?

Thanks,

Koenraad Lelong.

Reply by email

zeljko
to Koenraad Lelong
Koenraad Lelong wrote 42 lines
Hi, I'm trying to manually create a form and in it's OnCreate event populate it with controls. But I'm doing somehing wrong. This is my creating sequence : form2:=Tform2.Create(nil); form2.ShowModal; Form2.Destroy; Nothing special I think. This is a sample of the create-code : procedure TForm2.FormCreate(Sender: TObject); var i : integer; upper : integer; begin upper:=10; for i:=0 to 4 do begin form2.Height:=form2.height+25; edits[i]:=Tedit.Create(self); edits[i].Parent:=form2; edits[i].Top:=upper; edits[i].Left:=10; upper:=upper+25; end; end; But when I run the code, I get a segfault at the location where I modify the form's height. If I remove that, I get the form but the edits do not show. When I modify the code to automatically create the form this works. So I'm clearly missing something. Any tips, links to documentation ?

Do not use variable in OnCreate(). Sender parameter is your form. So instead of using Form2.Height := , use TCustomForm(Sender).Height or whatever. That should work.

zeljko

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120629/170f95e8/attachment.html>

Reply by email

Antonio Fortuny
to Koenraad Lelong: I'm trying to manually create a form and in it's OnCreate event populate it with…

Le 29/06/2012 11:16, Koenraad Lelong a ?crit :

Show quoted text 28 lines
Hi, I'm trying to manually create a form and in it's OnCreate event populate it with controls. But I'm doing somehing wrong. This is my creating sequence : form2:=Tform2.Create(nil); form2.ShowModal; Form2.Destroy; Nothing special I think. This is a sample of the create-code : procedure TForm2.FormCreate(Sender: TObject); var i : integer; upper : integer; begin upper:=10; for i:=0 to 4 do begin form2.Height:=form2.height+25; edits[i]:=Tedit.Create(self); edits[i].Parent:=form2;
         edits[i].Parent:=Self;
Show quoted text 24 lines
edits[i].Top:=upper; edits[i].Left:=10; upper:=upper+25; end; end; But when I run the code, I get a segfault at the location where I modify the form's height. If I remove that, I get the form but the edits do not show. When I modify the code to automatically create the form this works. So I'm clearly missing something. Any tips, links to documentation ? Thanks, Koenraad Lelong. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

zeljko
to zeljko: Do not use variable in OnCreate(). Sender parameter is your form. So instead of using…
zeljko wrote 52 lines
On Friday 29 of June 2012 11:16:06 Koenraad Lelong wrote: > Hi, > > I'm trying to manually create a form and in it's OnCreate event populate > it with controls. But I'm doing somehing wrong. > > This is my creating sequence : > form2:=Tform2.Create(nil); > form2.ShowModal; > Form2.Destroy; > > Nothing special I think. > > This is a sample of the create-code : > > procedure TForm2.FormCreate(Sender: TObject); > > var > > i : integer; > upper : integer; > > begin > > upper:=10; > for i:=0 to 4 do > > begin > > form2.Height:=form2.height+25; > edits[i]:=Tedit.Create(self); > edits[i].Parent:=form2; > edits[i].Top:=upper; > edits[i].Left:=10; > upper:=upper+25; > > end; > > end; > > But when I run the code, I get a segfault at the location where I modify > the form's height. If I remove that, I get the form but the edits do not > show. > > When I modify the code to automatically create the form this works. So > I'm clearly missing something. > > Any tips, links to documentation ? Do not use variable in OnCreate(). Sender parameter is your form. So instead of using Form2.Height := , use TCustomForm(Sender).Height or whatever. That should work.

Or better to avoid casting, use Self like Antonio mentioned.

zeljko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120629/44d3f555/attachment-0001.html>

Reply by email