Delphi: Save TList of objects in text file?

You're on the right track. What you're trying to do is called serialization turning an object into a streamable form like a file.

You're on the right track. What you're trying to do is called serialization, turning an object into a streamable form like a file. You need to develop a format.

Exactly what the format is doesn't matter, as long as it's consistent and preserves all of the data that you require to reconstruct the object. You say you want a text file, so you can take a bit of a shortcut in this case by using a TStringList, which has file IO built in. Try something like this: procedure TSong.

Serialize(serializer: TStringList); begin serializer. Add(format('%s///%s: %s', Artist, Title, Filename)); //add a filename member! You need one!

End; procedure TPlaylist. Serialize(const filename: string); var serializer: TStringList; i: integer; begin serializer := TStringList. Create; try for I := 0 to Count - 1 do TSong(selfi).

Serialize(serializer); serializer. SaveToFile(filename); finally serializer. Free; end; end; You'll also want to implement the inverse, deserialization.It shouldn't be too difficult.

1 You can also Google "delphi serialization" for some RTTI-based options. See also stackoverflow. Com/questions/73895/… – TrueWill Feb 14 '10 at 19:28 2 Yeah, and that's definitely more useful for a general case.

But for something this simple, using RTTI is probably overkill. – Mason Wheeler Feb 14 '10 at 19:46 Thank you so much, works fine! – Marco W.

Feb 14 '10 at 22:34.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions