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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating multiple instances of a custom class

Status
Not open for further replies.

kingosticks

Programmer
Apr 21, 2005
5
GB
Hello, have been looking for a decent delphi forum for my problem, hopefuly my search is over. I have the type

TMsgFrame : class(Tframe)

with a bunch of procedures, components etc contained within it. i also have the following record on my main form:

TPost = record
PMWin : TTabSheet;
PMFrame : TMsgFrame;
end;

and Users which is an array of TPost.

when a certain event happens (message recieved from a socket) i want to create a new tabsheet and a new frame on this tabsheet to display some info about the recieved message so i have done this:

Users[index].PMWin:=TTabSheet.Create(self);
Users[index].PMWin.Caption:=Users[index].Nick;
Users[index].PMWin.PageControl:=PgeCtrlSearch;
Users[index].PMFrame:=TMsgFrame.Create(self);
Users[index].PMFrame.Parent:=Users[index].PMWin;

it can create the first tab and frame ok but when another message is received i get the error "A component named MsgFrame already exists". Im a little confused to why i can create the tabsheets but not the MsgFrames. i dont even need a name for it seeing as it will only be referenced using the record in the Users array anyway. any help would be much appreciated, this has left me rather stuck!

 

I think you may be confusing Parent with Owner.

Set a break point and use Ctrl-F7 to open the Evaluate/Modify window and see who the Owner is for your MsgFrame (after adding the first one).

You may need to add a line something like this:
[tt]
Users[index].PMFrame.Owner:=Users[index].PMWin;
[/tt]
 
Thanks for your quick reply, Iv'e not used the evaluate/modify window before so it is quite possible I'm doing it wrong but I get ([csInheritable]) as the PMFrame owner. Does that actualy mean anything?
 
I just changed
Users[index].PMFrame:=TMsgFrame.Create(self);
to
Users[index].PMFrame:=TMsgFrame.Create(Users[index].PMWin);

So.. the PMWin now owns the PMFrame and that stops the error. I think its time I had a read about owners and parents, I never really noticed the difference! Thanks very much for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top