Board index » delphi » OOP problem with object types, inheritance and association between objects
Johan Larsson
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
|
Johan Larsson
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
OOP problem with object types, inheritance and association between objectsHi all you Pascal programmers! I'm working on a huge OOP tool. I wonder how I would like it to be something like; function IsAssociation (What : ObjectType) : boolean; I've been trying lot's of things with VMT access and Any suggestions or hints? Greetings, Johan PS. Please send a message to my personal mail box as well as to |
Frank Heckenba
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:OOP problem with object types, inheritance and association between objectsQuoteJohan Larsson <j...@ts.umu.se> writes: not objects.) Quote> I would like it to be something like; Quote> I've been trying lot's of things with VMT access and many weaknesses of TP's object concept - besides the "strange" scoping ("Private"), that I'd rather call a bug, and other things... (Btw, does Delphi address this problem - anyone knows?) I could think of a solution requiring registering each class with its parent Hope this helps, |
Johan Larsso
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:OOP problem with object types, inheritance and association between objectsQuote> > I'm working on a huge OOP tool. I wonder how object instances, or just "objects" (both). In C, i thought the terms class and instance was used. Are you sure? Quote> > I would like it to be something like; (classes...). Quote> > I've been trying lot's of things with VMT access and pivate fields are accessable in the current unit, but not outside it. It must be this way if Borland don't use some "friend"-C-thing. Quote> I could think of a solution requiring registering each class with its p= bit ugly and I am a bit pedantic about these things. But, when a method inside a object calls it's parent object by the following code; Inherited SomeMethodFromParent; The object must know the address of the parent method. Therefor, the All these VMT things is a bit fuzzy. I've tried the following approach 1. Go to the VMT start address This is very primitive, since it not works always (at least one virtual /J PS. Please forward answers to my mail address; j...@ts.umu.se. Also |
V.V.Nestero
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:OOP problem with object types, inheritance and association between objectsQuoteJohan Larsson wrote: TParent.SomeMethod; and I afraid TP7.0 simply finds parent during the compilation time when -- |
Johan Larsso
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:OOP problem with object types, inheritance and association between objectsQuote> function IsAssociation(what: ObjectType): Boolean; that you've got a object hierarchy like a --- b If you call IsAssociation in b with d as a parameter, it won't procedure a.IsAssociation (What : ObjectPointerType) : boolean; But this I believe will not work either, beacuse it's endless But I don't think it's impossible to do this association thing. /J |
Jon Shemit
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:OOP problem with object types, inheritance and association between objectsIn a message that I haven't seen, someone wrote: Quote> I'm working on a huge OOP tool. I wonder how use "dynamic" methods. It's a bit clunky, but each class that has at least one dynamic method will have its own DMT. Each DMT contains a pointer to an ancestral DMT. So, all you'd have to do is compare DMT pointers; if they don't match, you'd walk the chain until they do match or until you reach a Nil ancestral pointer. VMT/DMT formats are well documented in the Inside Borland Pascal chapter. -- http://www.midnightbeach.com/jon Personal Pages |
Frank Heckenba
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:OOP problem with object types, inheritance and association between objectsQuoteJohan Larsson <j...@ts.umu.se> writes: order to distinguish from non-object types. However, I haven't heard "object" used instead of "type" (resp. "class") - Quote> > > I would like it to be something like; BTW, if you have a parent class (which is usual), then of course all classes would be "associated", at least remotely... Quote> > > I've been trying lot's of things with VMT access and private to this very class. Of course, I'd also need "protected" for child classes. There may also be a need for "friends", though I haven't found that need too often (and when, I made the relevant things public and commented them appropriately, like I have to do with the protected things). Anyway, I don't find it very senseful to assume that all friends are in the same unit, and everything in this unit are friends... At last, your comment shows me a little bit of reason for this kind of But still, I think you'd agree, the scoping is far from perfect, and much Quote> > I could think of a solution requiring registering each class with its p= AFAIK, "Inherited Method" calls are compiled to absolute calls to the parent's method. At runtime, the information about the parent seems simply not available. I'm not absolutely sure about it, but like you I've tried much (also thought about using "Inherited" somehow), but didn't find anything... - Hide quoted text - - Show quoted text - Quote> All these VMT things is a bit fuzzy. I've tried the following approach But wait... there's something... I was surprised about that nil pointer you mentioned. I didn't know of that. However, you can make something out of that. If you require that each class If a class doesn't declare a new dynamic method, it will use the same DMT as As another advantage, you could use this index that the dynamic method must You could also put some other class data in this pseudo procedure, to address type TMyClass procedure TMyClass.MyClassInfo; assembler; Just fantasizing... (of course, you'd have to make sure this layout is the Surely, this is far from perfect, but you can't make a bad language (bad, of Followup to another part of this thread: Quote> > function IsAssociation(what: ObjectType): Boolean; a) You need a termination condition, i.e. implement it without the "inherited" branch for the top class. b) Instead of "Typeof(Self)" you'd have to write "Typeof(<this class>)" with Quote> Your idea is very interesting. But it doesn't seem to work. Pretend to return False since b and d are not directly inherited out of each other. If you want to check any association, and have a general parent class, I suggest the following: const IsAssiociation=True;-) Quote> procedure a.IsAssociation (What : ObjectPointerType) : boolean; always terminate. But, as said above, I don't see a sense in this kind of checking. Quote> Also I am sceptical to the TypeOf operator. Are you really sure Quote> Isn't the type of Quote> But I don't think it's impossible to do this association thing. reference (somehow) to the parent class without explicitly coding it for each class. The compiler simply doesn't seem to generate such references (except the DMT stuff), though they'd be quite useful... However, if you do find something out, let me know! Frank Quote> PS. Please forward answers to my mail address; j...@ts.umu.se. Also |
1. OOP: Object within an Object
2. Copying contents of an object to another object of the same type
3. Idea for Delphi 3.0: object repository for all object types
4. Copying contents of an object to another object of the same type
5. Activate object via file association
6. Objects, Objects, Objects...
7. OOP: insert objects in a container
8. OOP - books about object oriented programming in BP7.
9. Which object is best 2 explain OOP?
10. OOP-Plugins: sharing class definitions and objects betrween exe and dll