[Lazarus] Inserting new pages into a TPageControl

Mark Morgan Lloyd markMLl.lazarus at telemetry.co.uk
Sun Oct 13 21:28:19 CEST 2013


Howard Page-Clark wrote:
> 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]




More information about the Lazarus mailing list