We help IT Professionals succeed at work.

static method question

Dmitry_ asked
I have a function:
class function CalcIntervalsPerHr(AIntervals: Intervals): integer;
When I'm trying to use class containing this function on the C++ Builder, the C++ Builder is generating the following code in the hpp file:
static int __fastcall CalcIntervalsPerHr(TMetaClass* vmt, Jzcwcommon::TIntervals AIntervals);
What is the vmt paramether and what value should I pass to this parameter?
Watch Question


your 'function' is in fact a class method.

the vmt parameter is the implicit class reference.

Delphi equivalent is the hidden Self parameter (passed on the stack of every method) which in case of normal methods points to the object's instance, and in case of class methods points to the class reference (because there may be no instance; class functions can be called without an instance).

This is hidden in Delphi but in CBuilder it's obviously not. I guess you should pass the class reference to the vmt parameter because that's how it works in Delphi behind the scenes.

Maybe you don't even have to typecast, e.g.

CalcIntervalsPerHr(TMyObject, SomeIntervals);

perhaps you have to typecast, e.g.

CalcIntervalsPerHr((TMetaClass*) TMyObject, SomeIntervals);

where TMyObject is your class where you declared the CalcIntervalsPerHr method.

Something like this - I'm not sure; my experience with CBuilder has been very brief.



this is a _static_ class function
The static class functions haven't Self paramether and can't access object's instance.

Hi Dmitry,

I was talking about Delphi.
For class methods, Delphi uses 'Self' as the class reference. According to your posting, CBuilder uses 'vmt'.
In Delphi 'Self' is implicit and hidden (not used in the declaration). In CBuilder, it's not.
I believe they are the same, although the names are different.

'static function' used in a CBuilder class declaration = 'class method' in Delphi.

In case it's not clear, here's a recap:

- can only be invoked on an instance
- first parameter (EAX) receives the instance pointer

class method
- can be invoked without an instance
- first parameter (EAX) receives the class reference

Therefore, you need to pass the class reference to the vmt parameter, that's all.
How to do that, I'm not sure. I haven't used CBuilder much.
I gave you some tips already.

Hi, I've just seen this on Borland newsgroups, perhaps this will do it:


Why B? :-)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.