Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This Form of method call only allowed for class methods error

Tags:

delphi

I keep getting this error. On FGetZoneData I have:

var
   SelectedDept: String;

implementation

procedure TFGetZoneDept.GetClick1(Sender: TObject);
var
  azone: string;
  adept: string;
  bstats,
  bname,
  btop,
  bleft,
  bnumber,
  basset: string;
  machine : TMachine;
begin
  fdb.count := 0;  //keeps track of number of machines in zone
  azone := Combobox1.Text;    //gets name of zone
  adept := TfDB.GetDeptDBName(SelectedDept); //gets name of dept from a function
  fdeptlayout.ListBox1.Clear;
end;

and on TFdB I have a function declared in public:

public
    Function GetDeptDBName(name :string):String;
end;

Any idea why this would not work?

like image 917
Glen Morse Avatar asked Feb 08 '13 10:02

Glen Morse


1 Answers

You're calling the method on a class (I assume TfDB is a class name) not on an instance. Only class methods can be called that way. What you have to do is to create an instance, then call the method on it:

var DB: TfDB;
begin
  DB := TfDB.Create(); // create an instance
  adept := DB.GetDeptDBName(SelectedDept); // call the method

See the E2076 This form of method call only allowed for class methods topic in docwiki.

like image 181
ain Avatar answered Sep 30 '22 21:09

ain