Frank Heckenbach wrote:
I'd consider it perhaps a misfeature, but I think it will keep working, as long as you use explicit linker names (as you do), and take care of the parameter list ("Self" last, in contrast to BP where it's first, no difference in the example).
...?
Let me get this straight: If I defined a method like this:
tFoo = object Procedure bar ( baz: cinteger ); attribute ( name = 'foo_bar' ); end (* tFoo *);
and linked it from a C library, would the header then be
external void foo_bar ( int baz, void *self );
or
external void foo_bar ( void *self, int baz );?
I'm only asking because I've been using the latter one for years, and it worked fine.
However, actually "Self" is a reference parameter of object type, not a value parameter ob object pointer type. Though both are implemented the same, and this is also unlikely to change, the example can easily be changed to avoid depending on this.
Good to know, thanks!
Yes, the first problem is to define a syntax. I think there might have been some suggestions before, but nothing concrete so far AFAIR. Do other dialects have something like that, if so which syntax?
Maurice mentioned the Delphi syntax. I already thought about it myself, but I think you've been right when you said:
So IIUC, the difference to Markus' way is that here the procedural variable also contains the object, while there it only points to the method, and can be applied to any object (of matching type), right?
I would need the latter solution indeed.
Here's an alternative:
gFoo:= tFooFunc (@tTestObj.foo);
#-) Thanks again! I could have thought of something like that myself. Hmm... In fact, this might turn out even more useful for my purposes than a "real" method variable type. A syntax solution would tie me (resp. my potential library users) to always use objects. This one leaves the choice to use arbitrary data sets instead.
So if tFooFunc was a "method" type with a parameter list, what would be the correct declaration?
tFooFunc = Procedure ( aParam: integer; aSelf: pTestObj );
or
tFooFunc = Procedure ( aSelf: pTestObj; aParam: integer );?
For a compiler-implemented solution, polymorphy would also be an issue, and AFAICS, the compiler would need to emit such a wrapper routine automatically then. That might not be too difficult per se (just some work to do ...), but the important question is, when and where to emit such wrappers (looks a bit like the C++ template problems). We could emit one on each usage, at the danger of emitting the same one several times (might even be in different units). Or emit one for each virtual method, at the danger of emitting some (often many) that aren't used at all. Of course, it's not a huge issue (just a few bytes per routine), but since a manual solution is available, I'd first wonder if the effort is justified for a feature that might not be used all that often ...
True. You've halfway convinced me to stick with the wrappers; I'm not sure if the flaws I'd catch by using method variables (syntax-approved or not) wouldn't more than outweigh their possible benefits. At least with the wrappers, I have a well-defined and most flexible way of handling "method" vars, and the overhead is, though sometimes annoying, acceptable altogether. I'll have to sleep over it.
Best,
Markus