这种写法有无问题?
function TMainForm.Fun_DeptEmpCount(const TabNa,FieldNa:String;
ConditionStr:string):Integer;
var
iStr:String;
const
ivarString='Select * from %s where %s like %s';
begin
ConditionStr:='"'+ConditionStr+'%'+'"';
ShowMessage('Condition为 '+ConditionStr);
with DM1.DBQry do
try
Close;
SQL.Clear;
SQL.Add(Format(iVarString,[TabNa,FieldNa,ConditionStr]));
Prepared:=True;
Open;
Result:=RecordCount;
Finally
Prepared:=False;
Close;
end;
end;
调用:
procedure TWageDataFrm.ButRefModalClick(Sender: TObject);
var
iEmpGradeID,EmpGrade:String;
begin
with DM1.XXADODataSet do begin
iEmoGradeID:=Trim(Fields[3].Value);
EmpGrade:='"'+Copy(iEmpGradeID,1,2)+'"';
EmpAmount:=TMainForm.fun_DeptEmpCount('WageModal','GradeID',EmpGrade);
// 该处编译时报错
end;
end;
错误信息:
[Error] WageDataPas.pas(455): This form of method call only allowed for class
methods
[Fatal Error] GZMain.pas(49): Could not compile used unit 'WageDataPas.pas'
为什么会这样?