Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 这种形式的方法调用只允许类方法出错_Delphi - Fatal编程技术网

Delphi 这种形式的方法调用只允许类方法出错

Delphi 这种形式的方法调用只允许类方法出错,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

我一直在犯这个错误。在
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
是类名)上调用该方法,而不是在实例上。只能这样说。您需要做的是创建一个实例,然后对其调用方法:

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

请参阅docwiki中的主题。

call
adept:=fdb.GetDeptDBName()
。调用
TfDB.GetDeptDBName()
假定使用类方法。谢谢您的回答,我可以接受。。。我不知道我是怎么错过的,但我想它已经回答正确了。没有必要重复他的回答。