On 08 Mar 2009, at 19:10, dmitry boyarintsev wrote:

yeah, i've seen description of 'static' usage at the mailing list
(subj: crashing _self parameter)

This is a new feature for FPC, right? (catching up with new delphi syntax?)

The static keyword been available forever in FPC (probably from before Delphi had it, we first used it in TP-style objects). What is new is making the behaviour of adding of "static" to class methods Delphi- compatible.

a few questions about that:
1) 'static' methods are regular procedures/functions, but bound to a
class rather than a unit?

A class method becomes indeed a regular function/procedure within the scope of a class if you add "static;".

2) it's possible to pass 'static'-methods as procedure variables?

Try it. I don't know. It will probably cause compiler errors because of type incompatibilities. If Delphi accepts it in some form, please file a bug report with a compilable example program. It should probably also be tested that class methods are not assignable to a "procedure of object"-style procvar (although I don't know whether that's normally possible for class methods).

3) only class methods can be 'static'? it's impossible to declare a
method like:
TMyObject = class
 procedure MyMethod; static;
end;

It's possible to declare this, but it doesn't change anything currently (a method without self-parameter would be indistinguishable from a class method without its hidden vmt-parameter -- which is also called self, for that matter). I don't see any use for this.

4) no Self parameter is available inside the 'static' method. (since
it's regular procuder or function)

That's the whole point of using static.

5) 'static' keyword is used only if compiler -St switch specified?

Yes, or {$static on)

6) how are they actually named? because there're two kind of static
methods available:

TMyObject = class
  class function MyClassProc;  // static class method

This is a regular class method.

  class function MyClassVirtualProc; virtual; // virtual class
method. can be overriden.
  class function MyClassVirtualProc; dynamic; // dynamic class
method. can be overriden too
  class function MyClassProc; static; // "static" class method?

And this is a static class method.

7) 'static' keyword is available for both {$mode objfpc} and {$mode delphi}

It's available in every mode, as long as you add -St or {$static on}


Jonas
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to