Reader Writer TFiller Objects what is their purpose why not use TStringList directly

Reader Writer TFiller Objects what is their purpose why not use TStringList directly
is their something that they organize
What power do they offer to my code or how do I use them?
I’m missing their point of use or purpose

Do you mean things like TFileStream ?

Assuming your Delphi SKU comes with the RTL and VCL source code, I’d suggest that you search in the source code folders to see how these classes are used

For Delphi 12 the relevant folder is

C:\Program Files (x86)\Embarcadero\Studio\23.0\source

The short answer is you should be using TStringList directly in your application. You’re not supposed to be using TFiler, TWriter and TReader in your day to day code, it even says so in the help.

Note: Most of the filer properties and methods have public visibility for convenience within the streaming system. The majority of them are never called directly by applications.

If you’re writing a custom TStringList component (or any other component) you may have reason to use these classes but otherwise stay away from them.

Excellent answer. Added to this OP might want to read up on Abstract classes, which is what TFiler is for example. The TStringList savetofile type methods are ‘concrete’ implementations of the Abstract class’ methods which is why you should be using those.

a TStringList component with TFiler, TWriter and TReader is what I’m directly looking at

What Services can TFiler, TWriter and TReader offer on top of TStringList - what can it do for my code? Why the waring as TFiler, TWriter and TReader has been around way back in the Delphi 7. You say its a abstract class meaning it has no use but to build from its base design. So what can I build with it is what I’m asking?

MyStringList.SaveToFile(somefilename.ext);

MyStringList.LoadFromFile(anotherfilename.ext);

An abstract class does not ‘have no use’, it means it’s effectively a template for other descendant classes to build on to add in functionality which is specialized to the class so, in this case, the SaveToFile and LoadFromFile methods act on the TStrings property - in a TStringList this is the Items property - and saves them to and loads them from a text file with appropriate file handling and line endings encapsulated.

So, as I said, the TFiler and TWriter classes are not really something you use in that context, they are already appropriately implemented on the TStringList class. You could override the methods to make the string list do something funky like write out HTML or markdown - and that would be interesting, but in of itself those classes are not something you usually use directly like MyFiler := TFiler.Create or something along those lines. The fact they are abstract pretty much gives you a big hint that is the case.

So I can use TFiler and TWriter classes to write a reformatting of the Stringlist’s data with an unlimited option to the types of reformatting for my object so it preformatted to my objects use. That is interesting indeed. I have always thought build the object to hold the data. Rather than see TStringList as the container to all my data and TFiler and TWriter classes simply translates the data to my objects use.

Unless you are wrriting components which need to stream properties in a custom format, there is absolutely ZERO need use TReader or TWriter. They are designed for doing fancy stuff when persisting components when saving/loading forms/datamodules. I would say that 90% of delphi users have never used these classes directly.

If you want to persist/load the values of a TStringList, then just do as Ian suggested and use the SaveToFile/LoadFromFile.

1 Like