[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

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.
0
AlexDen
Asked:
AlexDen
1 Solution
 
rwilson032697Commented:
Listening
0
 
intheCommented:
hehe the code is  a bit buggy..maybe mike will be along to have a look .
0
 
LischkeCommented:
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
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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.

0
 
LischkeCommented:
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
0
 
aacrgCommented:
Listening...
comment: Have you ever looked at the Delhpi Streaming for TCollections? - Good Luck / Look !!!
aacrg. #;c)
0
 
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).
0
 
AlexDenAuthor Commented:
Adjusted points to 85
0
 
LischkeCommented:
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
0
 
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;
TGLSceneEditorForm.TreeDragOver:
Assigned(DropTarget.Data)

I think, should be changed to

Assigned(Target.Data)

Some other bugs do exist but they are not so essential.
0
 
LischkeCommented:
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
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now