Board index » cppbuilder » ReadComponent and WriteComponent

ReadComponent and WriteComponent


2003-08-16 09:58:41 PM
cppbuilder83
Hi,
I asked a similar question a while ago, but I didn't get a
reply so I'll state the question in another way and hope that
someone can help me. I am trying to stream a form to a file,
which I successfully do. Then I try and stream it and all of
its properties back at a later stage. I keep getting an
exception saying that "Panel1 already exists". Panel1 is a
component on the form. I use the following code:
Saving:
if (SaveDialog->Execute()) {
TFileStream *fileStream = new TFileStream(SaveDialog->FileName, fmCreate);
fileStream->WriteComponent(SurnameCrit);
delete fileStream;
ShowMessage("Criteria saved.");
}
Loading:
if (OpenDialog->Execute()) {
TFileStream *fileStream = new TFileStream(OpenDialog->FileName, fmOpenRead);
fileStream->ReadComponent(SurnameCrit);
delete fileStream;
}
Am I missing a concept about streaming or something? If no one
can help me, can someone at least refer me to a good
TFileStream help source which I also don't seem to find. Thanks
for your help!
 
 

Re:ReadComponent and WriteComponent

"Andrew" < XXXX@XXXXX.COM >wrote:
Quote
[...] I keep getting an exception saying that "Panel1 already
exists". Panel1 is a component on the form.
Do you mean that prior to ReadComponent, a control named Panel1
already exists on the form?
Based on the IDE's behavior when copying and pasting controls,
I'm guessing that the problem is that when you read in the
component, another component of the same name exists so it
tries to change the name to a generic one and that name also
exists so it stops trying and throws an exception.
Quote
Am I missing a concept about streaming or something?
I doubt that it has anything to do with streaming the component.
~ JD
 

Re:ReadComponent and WriteComponent

Quote
Do you mean that prior to ReadComponent, a control named
Panel1 already exists on the form?
Yes, if I change the name of Panel1 to PrettyPanel or whatever
it throws an exception saying PrettyPanel already exists. It
does that with every form I try to stream in. The first
component in the creation order of the form throws the
exception.
 

{smallsort}

Re:ReadComponent and WriteComponent

"Andrew" < XXXX@XXXXX.COM >wrote:
Quote
[...] The first component in the creation order of the form
throws the exception.
After reading the help and a brief search of the web, it
appears to me that you're mis-using ReadComponent. It returns
a TComponent that (in all of the examples I saw) was used to
create the component.
You're solution may be as simple as dynamically creating the
component that you use with WriteComponent, then delete it and
try to ReadComponent.
I also saw an example where TReader was subclassed to prevent
exceptions being thrown when the new component didn't have all
of the properties of the streamed component.
I've never used these methods myself and since I'm not inclined
to test them to figure out exactly how to use them, the best
advice that I can give you is to start over by (re)reading the
help combined with some searching of archives:
www.tamaracka.com/search.htm
www.mers.com/searchsite.html
~ JD