Sign in Join

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

Mailing lists / lazarus / 2013-10

Inserting new pages into a TPageControl

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Mark Morgan Lloyd

Assuming that TPageControl remains the preferred way to organise a tabbed "notebook", I'm left with porting some older code and also trying to tune something I'm currently working on. I'm trying to stick to Lazarus 1.0, since particularly if I publish a program as being of use to non-Lazarus developers (e.g. an RJE workstation for the IBM mainframe crowd) I think that sticking to a major release is a benefit.

Given a TPageControl with several existing pages, how does one insert a page at a specified position rather than at the end?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Howard Page-Clark
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote
Given a TPageControl with several existing pages, how does one insert a page at a specified position rather than at the end?

This function should do it:

uses ComCtrls;
function InsertAt(ExistingIndex: integer;
                   aPageControl: TPageControl): TTabSheet;
begin
   Result:=nil;
   if (ExistingIndex<0) or (ExistingIndex>aPageControl.PageCount-1) then
     Exit;
   Result:= aPageControl.AddTabSheet;
   if aPageControl.IndexOf(Result)  ExistingIndex then
     TNBPages(TCustomTabControl(aPageControl).Pages).Move(
                 aPageControl.IndexOf(Result), ExistingIndex);
end;

Reply by email

Mark Morgan Lloyd
to Howard Page-Clark
Howard Page-Clark wrote 20 lines
On 11/10/2013 22:00, Mark Morgan Lloyd wrote: > Given a TPageControl with several existing pages, how does one insert > a page at a specified position rather than at the end? This function should do it: uses ComCtrls; function InsertAt(ExistingIndex: integer; aPageControl: TPageControl): TTabSheet; begin Result:=nil; if (ExistingIndex<0) or (ExistingIndex>aPageControl.PageCount-1) then Exit; Result:= aPageControl.AddTabSheet; if aPageControl.IndexOf(Result) ExistingIndex then TNBPages(TCustomTabControl(aPageControl).Pages).Move( aPageControl.IndexOf(Result), ExistingIndex); end;

Thanks Howard, a slight variant of that is working. Any residual problems are my own doing :-)

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email