Jump to content
David Schwartz

stream object to / from INI file using latest RTTI stuff

Recommended Posts

I had a unit somewhere that let me stream basic Delphi object instances to and from an INI file, but now I can't seem to find it.

 

Google is turning up stuff from 2009. The newer RTTI stuff is a lot simpler.

 

Can anybody point me to something that uses the latest RTTI stuff?

Share this post


Link to post

An .ini file has no hierarchy. How are you going to serialize nested objects like 

TMyObject = class
	someData: TBytes;
	someReference: TMyObject; // can be nil
end;

Formats like XML or JSON can properly deal with this, not sure how INI could be a good choice here.

Share this post


Link to post

I don't need to. As I said, "... stream basic Delphi object instances ..."

 

I can already handle stringlists easily, and arrays of basic types should be easy to handle anyway, although I don't have any at this point.

 

I will have collections of objects, but I'll deal with them one-by-one.

Edited by David Schwartz

Share this post


Link to post
57 minutes ago, Der schöne Günther said:

An .ini file has no hierarchy. How are you going to serialize nested objects like 

For example the same way as registry files do

  • Like 1

Share this post


Link to post
6 hours ago, FPiette said:

Why not start from this example to convert your component to string and the store the string in the INI file?

They're fairly simple data objects derived from TObject, not from TComponent. I could derive from TComponent instead, but it buys me lots of overhead with little if any value.

Edited by David Schwartz

Share this post


Link to post

As I said, I've got code that uses the old RTTI methods introduced in D2010. I'm looking for something that uses the newer RTTI methods. Not an entirely different approach.

 

They're simple classes with no embedded objects, but there are some enums.

Share this post


Link to post

Enumerate the members of interest and persist them. If these classes are really that simple, what is the difficulty? What are you stuck with? Using the RTTI? Or working with INI files? 

  • Like 2
  • Thanks 1

Share this post


Link to post

it's a 2 min copy&paste task from the link above, I can't see why would anyone reinvent the wheel just to avoid using the json library? Is it for some embedded computer?

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×