tags:

views:

182

answers:

1

Hello,

My parent class is a form(TParent) ,here's the code:

type
TChild = class(TParent)
private
  procedure Handle(sock:integer);static; //error
end;

implementation

The error is "STATIC can only be used on non-virtual methods"

Is there any possible way of doing this?

If not, can I make the Parent Class(TForm) static?

The TParent class is a form used for WSAAsyncSelect() and it's hidden(its not the main form).It's only used for the message loop.

+1  A: 

try this :

type
TChild = class(TParent)
private
 class procedure Handle(sock:integer); static;
end;
Adinochestva
No,same error with both.
John
sorry i forgot to put class before procedure , test it again , it should work
Adinochestva
export; should not be there
Lars Truijens
Do you really need the "static" keyword here?. The procedure is already "static" in the C sense of the word by declaring it as a "class procedure". As I understand it, the "static" keyword was introduced a while back for compatibility with .NET and has the effect of disallowing references to variables declared outside the current procedure, and suppressing the implicit "Self" parameter. The "static" keyword seems to introduce unnecessary restrictions in native code.
MikeJ-UK
Yes, Mike, `static` is important. Delphi's class methods have a "Self" parameter, just like ordinary methods. It holds the class reference, such as `TChild`, in this example. It's *not* the same as C++'s static member functions; you need Delphi's `static` for that. Static class methods cannot be virtual, but they can be used in situations that would ordinarily require standalone procedures. However, we really have no idea whether `static` is required *here* because we haven't been told anything about what the `Handle` function is supposed to do.
Rob Kennedy
Calling the procedure Handle is also confusing, as it is the name of a property of TForm (inherited from TWinControl)
Gerry
@Rob. Yes I agree that I was being a bit presumptuous since we do not know the context of the example procedure, but the rest of your comment seems to agree with my point. I think I will post a new question on this subject.
MikeJ-UK