Board index » delphi » class in class?

class in class?

Hi,

i sow that compiler accepts code like this:

...

type T = class

 class procedure p;  

end;

I don't know what is the difference of "class procedure p" and
"procedure p"

Someone can help me?

e-mail: sk...@dei.unipd.it

 

Re:class in class?


Quote

> type T = class
>  class procedure p;  
> end;

> I don't know what is the difference of "class procedure p" and
> "procedure p"

This is described in on-line help. The main difference between a simple
method ("procedure p") and a class method ("class procedure p") is that you
do not have to instanciate T before calling p.

Consider the following:

type
  T = class
    class procedure p1;
    procedure p2;
  end;
var
  x: T;
begin
  T.p1;   // this is legal
  T.p2;   // GPFault !
  x := T.Create;  // you hav to do this
  x.p2;   // and this
  x.p1;  
  x.Free;
end;

Hope this helps. :)

Re:class in class?


Quote
> I don't know what is the difference of "class procedure p" and
> "procedure p"

> Someone can help me?

A class procedure or function does not operate on the class data.
Attempting to do so will result in a compile error.  You can ( and usually
will ) pass a reference to an instance of the class, and access the
instance's public and published items.  From a coding standpoint, you can
use them in a similar manner as regular old global functions and
procedures.  But as members of a class, they benefit from being able to be
declared as abstract, virtual, override, etc.
--
Chris Lincoln
Ultrax, Inc.

Other Threads