BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

cannot fond the object when ComponentState is csDesigning,cs

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
Emmanuel
Guest





PostPosted: Wed Jan 03, 2007 8:58 am    Post subject: cannot fond the object when ComponentState is csDesigning,cs Reply with quote



I have write a component,say C1.
one of the property,say p1, is link to a TComponent,say C2, which is owner
by other TForm ,say FormA,
I find that when the ComponentState is csDesigning, and the FormA have not
open, the C1->p1 will set to be NULL
eventhough C1->p1=FormA->C2 in the dfm file.
How can I solve it?


__published:
__property
TERPRemoteServer*RemoteServerLink={read=FRemoteServerLink,write=SetLinkRemoteServer};




void __fastcall
TERPRemoteServer::SetLinkRemoteServer(TERPRemoteServer*Value)
{if(Value==this)
{return;
}
//for test only
Application->MessageBox(((AnsiString)(int)Value).c_str(),"FRemoteServerLink",MB_OK); if(Value!=NULL) {Application->MessageBox(Value->Name.c_str(),"FRemoteServerLink->Name",MB_OK); }....}it will Claim Value = NULLApplication->MessageBox("0","FRemoteServerLink",MB_OK);in fact, it is not NULL in dfm fileHow can I solve it?
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Jan 03, 2007 9:11 am    Post subject: Re: cannot fond the object when ComponentState is csDesignin Reply with quote



"Emmanuel" <emmanuel (AT) erphk (DOT) com> wrote in message
news:459b1b27 (AT) newsgroups (DOT) borland.com...

Quote:
I have write a component,say C1.
one of the property,say p1, is link to a TComponent,say C2, which is
owner
by other TForm ,say FormA,
I find that when the ComponentState is csDesigning, and the FormA
have not
open, the C1->p1 will set to be NULL
eventhough C1->p1=FormA->C2 in the dfm file.

As it should be, as FormA has not been loaded yet, and the reference
to C2 has not been resolved yet..

Quote:
How can I solve it?

There is nothing to solve. The streaming is doing exactly what it is
supposed to be doing. You are simply trying to access the external
component too soon. The SetLinkRemoteServer() method will be
triggered immediately when the DFM is streamed. But if FormA hasn't
been loaded yet, it cannot pass a valid component pointer to
SetLinkRemoteServer(), so you get NULL. You have to wait until your
component's Loaded() method has been called before the reference will
be valid. For example:

private:
TERPRemoteServer* FRemoteServerLink;
protected:
virtual void __fastcall Loaded();
__published:
__property TERPRemoteServer* RemoteServerLink =
{read=FRemoteServerLink, write=SetLinkRemoteServer};

void __fastcall TERPRemoteServer::Loaded()
{
YourBaseComponent::Loaded();

Application->MessageBox(IntToStr(Value).c_str(), "Loaded:
FRemoteServerLink", MB_OK);
if( FRemoteServerLink )
Application->MessageBox(FRemoteServerLink->Name.c_str(),
"Loaded: FRemoteServerLink->Name", MB_OK);
}

void __fastcall
TERPRemoteServer::SetLinkRemoteServer(TERPRemoteServer*Value)
{
if( FRemoteServerLink != Value )
{
FRemoteServerLink = Value;

Application->MessageBox(IntToStr(Value).c_str(), "Set:
FRemoteServerLink", MB_OK);
if( FRemoteServerLink )

Application->MessageBox(FRemoteServerLink->Name.c_str(), "Set:
FRemoteServerLink->Name", MB_OK);
}
}

The DFM streaming code maintains a list of cross references that it
has to resolve after all components have been created. So
SetLinkRemoteServer() may get called more than once during the
streaming of your component.


Gambit
Back to top
Emmanuel
Guest





PostPosted: Mon Jan 08, 2007 9:43 pm    Post subject: Re: cannot fond the object when ComponentState is csDesignin Reply with quote



No Solution?
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Jan 10, 2007 2:00 am    Post subject: Re: cannot fond the object when ComponentState is csDesignin Reply with quote

"Emmanuel" <emmanuel (AT) erphk (DOT) com> wrote in message
news:45a265e1 (AT) newsgroups (DOT) borland.com...

Quote:
No Solution?

I already gave you an answer a week ago.


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.