Page 1 of 1

SimpleGraph's new object save to file

PostPosted: August 19th, 2008, 1:48 am
by BlackJack
Kambiz,I have some new questions,please help me.

I create some new Objects, want to save to file,but when I use SaveToFile mothed,find it can't to save ](*,) .I viewed the source of SimpleGraph.pas,which is save the List of TObject.if i want to save my Objects to file,i should to modefy the source of SimpleGraph.pas,shouldn't I? :cry:

I really don't want to modefy the source of SimpleGraph.pas,because if i do it , :-k the Component will lost commonality,do you have a good idea?

Thanks~~~ :)

PostPosted: August 19th, 2008, 3:39 am
by Kambiz
Your objects and their published properties should be saved automatically, without need to modify SG.

The objects are not saved, or they cannot be loaded? Do you get any error message?

PostPosted: August 19th, 2008, 6:07 am
by BlackJack
no error messages

i define new object by subclassing from existing objects, add some new properties.

i viewed the source of SG, the SaveToFile mothed read all objects as TObjects, but TObjects don't have my properties in my new Objects, so it can't be save i think.

PostPosted: August 19th, 2008, 7:16 am
by Kambiz
As you can see in the SG code, all graph object clsses are derived from TGraphObject class, and SG saves/loads them correctly. So, there must be a problem in your definition.

By the way, did you register your class to SG by calling TSimpleGraph.Register static method?

PostPosted: August 19th, 2008, 9:15 am
by BlackJack
Thanks Kambiz.
You are right , i'm wrong.
I don't put my new properties in published,I put them in public.
By the way, what's distinction of them?
Thank you again~~~

PostPosted: August 19th, 2008, 7:16 pm
by Kambiz
When a property is published, Delphi keeps its runtime type information (RTTI) and saves/loads its value to/from streams.

For example, if you look at DFM file of a form, all stored properties are published by the form or components/controls on the form.

PostPosted: August 20th, 2008, 1:15 am
by BlackJack
I know it, Thanks~~~.