这种形式的方法调用仅允许类方法错误 [英] This Form of method call only allowed for class methods error

查看:138
本文介绍了这种形式的方法调用仅允许类方法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到此错误。在 FGetZoneData 上,我有:

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;

TFdB 上我声明了一个函数在公共场所:

and on TFdB I have a function declared in public:

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

有人知道为什么这行不通吗?

Any idea why this would not work?

推荐答案

不是在实例上,而是在类(我假设 TfDB 是类名)上调用方法。只能以这种方式调用类方法。您要做的是创建一个实例,然后在其上调用该方法:

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

请参见 E2076这种方法调用形式仅适用于docwiki中的类方法主题。

这篇关于这种形式的方法调用仅允许类方法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆