Prof A Olowofoyeku (The African Chief) wrote:
Actually, there is a documented way of accessing the dynamic method index. I found it in the Delphi help file, and you won't like it - the access method is via asm. In any case, below is the documentation - and you can do with it (or not) as you deem fit. In the example given, "message MYMESSAGE" is the same thing as the BP "virtual methodindex".
Well, GPC's `asm' in incompatible to BP's -- that's known, and not likely to change. (And even if it would, such an implementation would be unnecessarily(*) nonportable by the use of asm.)
(*) In some low-level cases, such as accessing I/O hardware ports, the use of assembler code is unavoidable (though it is debatable whether it should be inlined in Pascal, or linked separately, but that's not the point here), but here we have a feature that can be described in high-level terms and in principle be implemented in high-level ways (`case' etc. ...), so the use of `asm' is an unnecessary restriction.
So, I won't do anything with it now. I still think an (automatically generated) `case' statement can work.
procedure DynamicMethod; dynamic;
This syntax seems to be new in Delphi (BP doesn't allow it). Should I just treat is as equivalent to `virtual'? (Since there's no index there, I suppose the dispatch issues don't apply here, and this time it's really equivalent, apart from memory and speed issues.)
Then the Delphi help file provides extra information about the features of dynamic methods, as follows:
- "Dynamic methods are virtual methods with a slightly different
dispatch mechanism. Because dynamic methods don't have entries in the object's virtual method table, they can reduce the amount of memory that objects consume. However, dispatching dynamic methods is somewhat slower than dispatching regular virtual methods. If a method is called frequently, or if its execution is time-critical, you should probably declare it as virtual rather than dynamic.
Objects must store the addresses of their dynamic methods. But instead of receiving entries in the virtual method table, dynamic methods are listed separately. The dynamic method list contains entries only for methods introduced or overridden by a particular class. (The virtual method table, in contrast, includes all of the object's virtual methods, both inherited and introduced.) Inherited dynamic methods are dispatched by searching each ancestor's dynamic method list, working backwards through the inheritance tree.
To make a method dynamic, add the directive dynamic after the method declaration."
That's about the same that BP 7 says. I.e., no semantic difference.
- "Virtual versus dynamic
Virtual and dynamic methods are semantically equivalent.
Ha! :-)
Frank