[fpc-devel]TWriter.WriteProperties
Judison
jueca at brturbo.com
Wed Dec 18 08:34:47 CET 2002
Hi,
I have to write some instances of a TA class(TPersistent) in a property of TB class(TComponent)...
I mean:
object MyB: TB
...
Items = <
item
Caption = 'Hello'
ImageIndex = 3
end
item
Caption = 'Bye'
ImageIndex = 4
end
>
end
But I can't (don't want) use TColletion/TCollectionItem in this specific case...
I have it working now, but I need to use a bad programming trick because I use the WriteProperties method of TWriter that is protected, so, I have a
type
TFakeWriter = class(TWriter)
end;
TFakeReader = class(TReader)
end;
Just to use use this method by casting the Writer (and the Reader for ReadProperty)
I don't like to do this kind of thing
and.. I my mother see it, I'm a dead guy ;)
My WriteData method looks like this:
procedure TB.WriteData(Writer: TWriter);
var
I: Integer;
begin
Writer.Driver.BeginCollection;
for i := 0 to ItemCount - 1 do
begin
Writer.Driver.BeginList;
TFakeWriter(Writer).WriteProperties(GetItem(I));
Writer.Driver.EndList;
end;
Writer.Driver.EndList;
end;
There is other way to do this?
I think about a lot of BeginProperty / WriteXXX / EndProperty but if I do this, I'll have problems creating another class(TA), if I add some properties to this new class.
I hope you understand my bad english.... :)
TIA
Your friend,
Judison
More information about the fpc-devel
mailing list