RAD Studio (Common)
ContentsIndex
PreviousUpNext
E2076: This form of method call only allowed for class methods (Delphi)

You were trying to call a normal method by just supplying the class type, not an actual instance. 

This is only allowed for class methods and constructors, not normal methods and destructors.

program Produce;

type
  TMyClass = class
  (*...*)
  end;
var
  MyClass: TMyClass;

begin
  MyClass := TMyClass.Create;  (*Fine, constructor*)
  Writeln(TMyClass.ClassName); (*Fine, class method*)
  TMyClass.Destroy;            (*<-- Error message here*)
end.

The example tries to destroy the type TMyClass - this doesn't make sense and is therefore illegal.

program Solve;
type
  TMyClass = class
  (*...*)
  end;
var
  MyClass: TMyClass;

begin
  MyClass := TMyClass.Create;  (*Fine, constructor*)
  Writeln(TMyClass.ClassName); (*Fine, class method*)
  MyClass.Destroy;             (*Fine, called on instance*)
end.

As you can see, we really meant to destroy the instance of the type, not the type itself.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!