Board index » cppbuilder » What is a proper approach for streaming and loading data and state of VCL components?

What is a proper approach for streaming and loading data and state of VCL components?


2003-12-16 10:30:32 PM
cppbuilder7
I have lots of VCL controls on Form1 that contains some data.
For example I have...
1) 'Edit1' with some '->Text' that has been entered.
2) 'RadioButton1' that has '->Checked' that could be changed
3) 'Image1' with some '->Picture' that is loaded and maybe
'->Transparent', '->Centred' or '->Stretched' changed.
4) 'RichEdit1' with '->Lines', '->PlainText' and other significant
attributes
5) etc...
...and I want to implement some Save/Open functionality for these
data. Is there an ordinary way to Stream (Save) the current state
(definitely not all attributes) and data of VCL components and then
Load it when needed.
I have already made my custom Save/Open routine that writes or reads
data contained between specially formatted segment marks:
[$1$]This is a Text from Edit1->Text[$2$]0[$3$]The last ZERO
was FALSE of CheckBox->Checked[$4$]
etc...
That works fine for me but it must me some better way... I found this
piece of code on net (Bojan Mitov web site I think...):
// *******************************************************
// Save to a file stream
TFileStream *Fstr = new TFileStream ("C:\\Boza.txt", fmOpenReadWrite |
fmCreate );
Fstr->Write ( Label1->Font, Label1->Font->InstanceSize () );
delete Fstr;
.....
.....
// Load from a file stream
Byte *Buffer = new Byte [ InstanceSize(__classid(TFont)) ];
TFileStream *Fstr1 = new TFileStream ("C:\\Boza.txt", fmOpenReadWrite );
Fstr1->Read ( Buffer, InstanceSize(__classid(TFont)) );
delete Fstr1;
Label2->Font->Assign ( (TFont *)Buffer );
delete Buffer;
// *******************************************************
I wonder can this be used. It seems to be easy when I know
the 'InstanceSize' size in advance, but what about some data
with not known length when reading. What is a proper approach
to resolve this?
Thanks.
Vladimir.
XXXX@XXXXX.COM
Serbia & Montenegro
 
 

Re:What is a proper approach for streaming and loading data and state of VCL components?

"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
Quote
I want to implement some Save/Open functionality for these
data. Is there an ordinary way to Stream (Save) the current
state (definitely not all attributes) and data of VCL components
and then Load it when needed.
No, but there are third-party components for doing that, though.
Quote
I found this piece of code on net (Bojan Mitov web site I think...):
That is a very dangerous piece of code. I'm surprised he would write such a
thing in the first place.
Quote
Fstr->Write ( Label1->Font, Label1->Font->InstanceSize () );
You cannot store a TFont like that. You have to store each indivudual
property value one at a time, and then read them back again one at a time
later.
Gambit
 

Re:What is a proper approach for streaming and loading data and state of VCL components?

Quote
>I want to implement some Save/Open functionality for these
>data. Is there an ordinary way to Stream (Save) the current
>state (definitely not all attributes) and data of VCL components
>and then Load it when needed.

No, but there are third-party components for doing that, though.

Why coding have to be so hard :)
 

{smallsort}