我定义了两个重载函数如下:
//判断编辑框信息不能为空 for Example :if IsEmptyEdit(Edi1,'注意','商品代码不能为空') then Exit
function IsEmptyEdit(Edit:TEdit;sShowText,sShowCaption:String):Boolean;overload;
begin
  Result:=False;
  if (Edit.ClassName='TEdit') or (Edit.ClassName='TDBEdit') then
  begin
    if Edit.Text='' then
    begin
      Application.MessageBox(PChar(sShowText+'信息不能为空!'),PChar(sShowCaption),MB_ICONINFORMATION+MB_OK);
      Result:=True;
      Edit.SetFocus ;
      Exit;
    end;
  end;
end;function IsEmptyEdit(Edit:TDBEdit;sShowText,sShowCaption:String):Boolean;overload;
begin
  Result:=False;
  if (Edit.ClassName='TDBEdit') then
  begin
    if Edit.Text='' then
    begin
      Application.MessageBox(PChar(sShowText+'信息不能为空!'),PChar(sShowCaption),MB_ICONINFORMATION+MB_OK);
      Result:=True;
      Edit.SetFocus ;
      Exit;
    end;
  end;
end;
我在使用时:
if IsEmptyEdit(DBEdit_Name,'行政区名称不能为空!','注意') then exit;
DBEdit_Name  是TDBEdit类型,这使用是正确的
当使用
if IsEmptyEdit(Edit_UnitName,'单位','提示') then  Exit;
就出错了,Edit_UnitName:Tedit
There is no overloaded version of 'IsEmptyEdit' that can be called with these arguments
这里哪里出错了?求救!!!!

解决方案 »

  1.   

    不明白为什么你要overload,其实可以两函数合并function IsEmptyEdit(Edit:TCustomEdit;sShowText,sShowCaption:String):Boolean;
    begin
      Result:=False;
      if (Edit.ClassName='TEdit') or (Edit.ClassName='TDBEdit') then
      begin
        if Edit.Text='' then
        begin
          Application.MessageBox(PChar(sShowText+'信息不能为空!'),PChar(sShowCaption),MB_ICONINFORMATION+MB_OK);
          Result:=True;
          Edit.SetFocus ;
          Exit;
        end;
      end;
    end;
      

  2.   

    问题解绝了,我在引用单元时,用的是Qstdctrls,正确应该引用stdCtrls