delphi – 这种方法调用形式只允许类方法错误

前端之家收集整理的这篇文章主要介绍了delphi – 这种方法调用形式只允许类方法错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直收到这个错误.在FGetZoneData上我有:
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;

在TFdB上我有一个公开声明的函数

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

知道为什么这不起作用吗?

解决方法

你在一个类上调用方法(我假设TfDB是一个类名)而不是在一个实例上.这样只能调用 class methods.你要做的是创建一个实例,然后在其上调用方法
var DB: TfDB;
begin
  DB := TfDB.Create(); // create an instance
  adept := DB.GetDeptDBName(SelectedDept); // call the method

请参阅docwiki中的E2076 This form of method call only allowed for class methods主题.

原文链接:https://www.f2er.com/delphi/101535.html

猜你在找的Delphi相关文章