thrutch
thrutch

Reputation: 13

Delphi 11, tDictionary containing tObjects

I have a tDictionary of variant items, I can add anything I wish, including objects.

My app has a "render" function that iterates through the dictionary and converts whatever it finds into string and finally displays them all as a single document.

I also have a number of classes that ALL have a "render" function that returns a string. I can add the class objects to my main dictionary if I explicitly render them: myDict['foo'] := mySubClass.render();

What I want is to add the class object: myDict['foo'] := mySubClass;

When the main render operation discovers an object, it should call the "render" function of that object. Similarly, if said object also contains objects, they should be rendered in turn. Like a coiled spring unwinding.

In PHP I simply used "if(is_object($itemArr[idx]) then $itemArr[idx]->render()"

I can't do this in Delphi, because the IDE does not know what the object is at design time.

How can I resolve this?

edited to show that I don't want to itemise the classes.

Upvotes: 0

Views: 270

Answers (0)

Related Questions