[Lazarus] TPageControl - how to use it?

Mattias Gaertner nc-gaertnma at netcologne.de
Sat Jan 28 22:00:18 CET 2012


On Sat, 28 Jan 2012 20:13:34 +0000
Howard Page-Clark <hdpc at talktalk.net> wrote:

> 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




More information about the Lazarus mailing list