Polymorphic TCollection or ?

I'm looking for some info and/or source on class and property editor for something like TCollection, but with an ability to accept different classes and with a full design-time support. Unfortunately, in design-time, TCollection and it's editor may operate with only one class type (ItemClass property).

Something similar to my target can be found in GLScene unit by Mike Lischke, where one can add different classes in design-time, but the code is a bit buggy and I can not find enough info to remove those bugs, or create my own editor.

Even Delphi's source code (colnedit.pas) refers to some strange TToolbarDesignWindow class which I can not find in Delphi destribution.

I would really appreciate any help with some good advice or source code sample.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hehe the code is  a bit buggy..maybe mike will be along to have a look .
What, where, how...? Nothing is buggy. My code is always totally bug free ;-))

But seriously, we need to clarify some things before I can propose a solution. If you only have a TCollection class with self defined item classes then you don't need an own property editor as the one in Delphi handles this case automatically. The editor isn't the coolest one but it does its job.

Ciao, Mike
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

AlexDenAuthor Commented:
Here is what I mean:

Suppose you define
TMyObject form TCollectionItem,
TMyObjects from TCollection,
and some contol with Objects: TMyObjects property.

In constructor of TMyObjects, I assign TMyObject to its ItemClass property.

After that, I can add TMyObject objects in design time just by hitting "Add new" button in default TCollection property editor.

After that, suppose I derive a new type TMyObject2 = class(TMyObject);

In runtime, I would add TMyObject2 objects using the Items property (TMyObjects.Add or TMyObjects.Insert functions seem not suitable since they may only return TMyObject classes).

But what should I do in design time? The GLScene by Mike Lischke looks just fine except a few bugs (they are really very small, Mike but I can not find them... yet... still trying). Its tree-like structure is even better than the simple list used in TCollection.

Alex, you should be aware that the scene editor is totally selfmade and relies of course on the structure build the scene objects. This has nothing to do with collections and will never work with them because you would need a parent-child relationship between items. This is not the intention for collections so you will always only be able to manage a dynamic list of items.

For your TMyObject2 I can tell you that you don't have to worry about what is returned. We are talking here about polymorphism which means the class returned by the Add function can safely be casted to your own class (to be safe use the "as" operator).

Ciao, Mike
comment: Have you ever looked at the Delhpi Streaming for TCollections? - Good Luck / Look !!!
aacrg. #;c)
AlexDenAuthor Commented:
Mike, actually I am not very much interested in TCollection itself. I'm interested only in property editor for such things. And I'm OK with that kind of parent-child stuff. And I took that collection stuff only as an example (well, maybe not the best).

As to your last comment, of course I agree, but I need that kind of polymorphism in design time. In that example I can only get access to TMyObject properties.

It means that in my dreams, I would like to have a property editor with several buttons for adding different classes (or as you did it with popup menus). My case is even simplier since I will have a fixed set of classes to add, so I do not need something like Object Inspector in your case.

And Mike, in order to clerify my intensions, I am rewriting my own OpenGL components which are somehow similar to your GLScene, but with rendering in a separate thread, and without any Euler angles (quaternions only).
AlexDenAuthor Commented:
Adjusted points to 85
Hi Alex,

although you tried to make it clearer to me what you need I'm still not sure. To your OpenGL lib just a hint: Instead of using quaternions you can also use the up/direction approach (as in GLScene). This might look like Euler angles but it isn't and quaternions aren't quite an improvment in that context and are really hard to understand when it comes to specify values manually. Anyway, do what you like to do :-)

Now to the classes. Why don't you just look at the sources for my GLScene editor? It is so trivial. Just create your scene objects as you like and use the designer of your component editor to select the components (they must be derived at least from TPersistent!). Keep also in mind that classes which are to be worked on at design time must be registered with RegisterNoIcon if you don't have registered them with RegisterComponents. The latter call is to register a class with the component palette while the first one is for "invisible" components (like TMenuItem).

Ciao, Mike

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlexDenAuthor Commented:
Ok, Mike,
I had some time this weekend and I think I understood how all that stuff works. But here are your points anyway... just for some good piece of work.

Regarding quaternions... they are essentially necessary for rotation interpolation... which is in turn necessary for smooth motion and more or less consistent physics modelling (I do not mean some serious physics here, just inertia, etc.). As for their understanding, I use QuaternionToRotation and RotationToQuaternion conversions so that quaternions are interfaced through rotation vectors. I think the same was done in Caligari TrueSpace and it looks pretty much convenient.

.... and in your code ...

unit GLSceneEdit;

I think, should be changed to


Some other bugs do exist but they are not so essential.
Thank you Alex,

yes there are still quite a few bugs but for now I have frozen the development because I'm now in the compiler builder business.

Ciao, Mike
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.