Sign in Join

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

Mailing lists / lazarus / 2012-01

TPageControl - how to use it?

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Bernd

There is documentation about how to add tabs and controls in the designer but I could not find any explanation of how to do the same programatically. I have a TPageControl on my form and at runtime I want to add a new page with a SynEdit on it.

This is what I have so far:

procedure TForm1.AddTab(AFileName: String);
var
  Sheet: TTabSheet;
  Ed: TSynEdit;
begin
  Sheet := PageControl.AddTabSheet;
  Sheet.Caption := 'Unnamed';
  Ed := TSynEdit.Create(Sheet);
end;

But it does not work. It will add a new Tab and set its caption but the tab will be empty. I have tried Ed.Show and also tried to change its position and size but nothing helps. I also tried with a simple TButton instead of a TSynEdit but this also does not work. What am I missing here?

Bernd

Reply by email

Howard Page-Clark
to Bernd: There is documentation about how to add tabs and controls in the designer but I could not…
Bernd wrote 6 lines
I have a TPageControl on my form and at runtime I want to add a new page with a SynEdit on it. This is what I have so far: ... But it does not work.

Try this:

procedure TForm1.AddTab(AFileName: String);
var
   Sheet: TTabSheet;
   Ed: TSynEdit;
begin
   Sheet := TTabSheet.Create(pagecontrol1);
   sheet.Parent := PageControl1;
   Sheet.Caption := 'Unnamed';
   Ed := TSynEdit.Create(Sheet);
   ed.Parent := Sheet;
   ed.BoundsRect := sheet.BoundsRect;
   ed.LineText := 'specimen line';
   PageControl1.ActivePage := Sheet;
end;

Reply by email

Mattias Gaertner
to Howard Page-Clark
Show quoted text 24 lines
On 28/1/12 7:50, Bernd wrote: > I have a TPageControl on my form and at runtime I > want to add a new page with a SynEdit on it. > > This is what I have so far: > ... > But it does not work. Try this: procedure TForm1.AddTab(AFileName: String); var Sheet: TTabSheet; Ed: TSynEdit; begin Sheet := TTabSheet.Create(pagecontrol1); sheet.Parent := PageControl1; Sheet.Caption := 'Unnamed'; Ed := TSynEdit.Create(Sheet); ed.Parent := Sheet; ed.BoundsRect := sheet.BoundsRect; ed.LineText := 'specimen line'; PageControl1.ActivePage := Sheet; end;

Hint:
You don't need the Delphism "set Parent first" under LCL. The above will create a lot of updates.

procedure TForm1.AddTab(AFileName: String);
var
  Sheet: TTabSheet;
  Ed: TSynEdit;
begin
  Sheet := TTabSheet.Create(pagecontrol1);
  Sheet.Caption := 'Unnamed';
  Ed := TSynEdit.Create(Sheet);
  ed.Align := alClient; // fill the whole sheet
  ed.LineText := 'specimen line';
  ed.Parent := Sheet;
  PageControl1.ActivePage := Sheet;
  sheet.Parent := PageControl1; // set Parent as last to reduce updates
end;

Mattias

Reply by email

Howard Page-Clark
to Mattias Gaertner
Mattias Gaertner wrote 18 lines
Hint: You don't need the Delphism "set Parent first" under LCL. The above will create a lot of updates. procedure TForm1.AddTab(AFileName: String); var Sheet: TTabSheet; Ed: TSynEdit; begin Sheet := TTabSheet.Create(pagecontrol1); Sheet.Caption := 'Unnamed'; Ed := TSynEdit.Create(Sheet); ed.Align := alClient; // fill the whole sheet ed.LineText := 'specimen line'; ed.Parent := Sheet; PageControl1.ActivePage := Sheet; sheet.Parent := PageControl1; // set Parent as last to reduce updates end;

Thanks for the hint. I would not have known that from reading the wiki - I think it is worth documenting there somewhere.

Reply by email

Mattias Gaertner
to Howard Page-Clark
Show quoted text 22 lines
On 28/1/12 9:00, Mattias Gaertner wrote: > Hint: > You don't need the Delphism "set Parent first" under LCL. The above will > create a lot of updates. > > procedure TForm1.AddTab(AFileName: String); > var > Sheet: TTabSheet; > Ed: TSynEdit; > begin > Sheet := TTabSheet.Create(pagecontrol1); > Sheet.Caption := 'Unnamed'; > Ed := TSynEdit.Create(Sheet); > ed.Align := alClient; // fill the whole sheet > ed.LineText := 'specimen line'; > ed.Parent := Sheet; > PageControl1.ActivePage := Sheet; > sheet.Parent := PageControl1; // set Parent as last to reduce updates > end; Thanks for the hint. I would not have known that from reading the wiki - I think it is worth documenting there somewhere.

I added a note to TWinControl.Parent.

Mattias

Reply by email