I have devised a very simple method: to use the 'objects' property, that is not used for other purposes
That is hardly a new trick. People have been using this trick for decades. Also note that
TStringList has an
AddObject() method:
Lst.AddObject('aaa', TObject(False));
Lst.AddObject('bbb', TObject(True));
Though, a
TFPGList<record with String and Boolean> or a
TFPGMap<String, Boolean> might make more sense to use, unless you really need the
TStrings interface.
Do you think this approach is reliable?
Yes, it is. At least in FreePascal, and in Delphi on desktop platforms, where ARC (automatic reference counting) is not used on
TObject. In Delphi on mobile platforms (iOs and Android), this approach would NOT work (at least until Delphi 10.4 comes out, as ARC on
TObject will be removed in that version). FreePascal does not support ARC on
TObject. But you can run into a similar problem if you set
TStringList.OwnsObjects=True, like simone mentioned. Just be aware of how your fake
TObject pointers are being used, don't use them anywhere that real
TObject pointers are expected.