Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TPageControl.PageCount vs constructor override...

Status
Not open for further replies.

rcloutie

Programmer
May 26, 2005
164
CA
Hello,

I've built a VCL based on TPageControl in which a constructor (Create override) initializes some variables.

One of these variables is an array corresponding to each TabSheet. That is, I use SetLength(bTabEdit, PageCount) to set dimensions of the array. The problem is that within Create, the PageCount property is not set yet (=0), even if all TTabSheet are created in design mode

Is there another way to initialize variable after the TPageControl have created its TTabSheet list (for the PageCount to be valid)?

Something like a Initilize constructor called by the Create constructor?

Thanks in advance,

Rej Cloutier
 
You could do this be overriding the ReadState procedure. This protected procedure is part of TComponent and is responsible for its creation. e.g.

Code:
TMyPageControl = class(TPageControl)
protected
  procedure ReadState(Reader: TReader); override;
end;

procedure TMyPageControl.ReadState(Reader: TReader);
begin
  inherited;
  SetLength(bTabEdit, PageCount);
end;

Be careful though, the ReadState procedure is very 'core' Delphi code! It may be better to try and think of an alternative way to achieve what you want to do.

Steve
 
Hi Steve and thanks for reply.

Caution will be taken. I need the same functionnality from within a TreeView based VCL. Can I override the ReadState procedure of the TreeView too?

Have a nice day,

Rej Cloutier
 
TTreeView is also a descendant of TComponent, so yes you can, in exactly the same way.

Steve
 
Seems to work for TPageControl but not for TTreeView: Items.Count always=0 from ReadState procedure... So, I've simply put a flag which I checked out from within the Change procedure...

A patch is a patch... but hey, who cares but me...?!%&*()

Thanks anyway...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top