这个问题已经有人问过,KINGRON回答过的。自己找找

解决方案 »

  1.   

    Tobject太大,没有HEIGHT。用一个小一点的,好象TWINCONTROL
      

  2.   

    TWINCONTROL我也试过,好象也不行
      

  3.   

    主  题:怎样把不同的控件作为同一个参数在函数中调用。
    作  者:yellowbb
    所属论坛:Delphi
    问题点数:20
    回复次数:15
    发表时间:2001-5-7 10:56:00
     
      
          我需要判定dbedit和dbcombobox中的值是否为空,想通过一个函数来实现,如:
    function isempty(edit:tdbedit;temp:string):boolean;但我想该函数对dbedit和dbcombobox都能产生作用,而不用对dbedit和dbcombobox来单独定义,请各位指点。
     
    回复贴子: 
     回复人:gzlad(请不要迷信Delphi) (2001-5-7 11:32:00)  得0分 
    找到它们的共同的父类就可以了。
    function isempty(edit:共同的父类;temp:string):boolean;  
     回复人:xycleo(虚竹(不是和尚)) (2001-5-7 11:37:00)  得0分 
    在bcb中可以用sender  
     回复人:yellowbb(阿黄) (2001-5-7 11:41:00)  得0分 
    我有用twincontrol代替tdbedit,但在函数中用 if edit.text='' 是出现错误。
     
     回复人:laza(秋高蓝) (2001-5-7 12:09:00)  得20分 
    统一对窗体的控件进行判断就行了。代码:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i: Integer;
    begin
      for i := 0 to ComponentCount - 1 do
      begin
        if (Components[i] is TDBEdit) then
        begin
          if TDBEdit(Components[i]).Text = '' then{ if TDBEdit(Components[i]).Field.IsNull then 也行} 
          begin
            showmessage('NUll Value!')
          end;
        end;
        if (Components[i] is TDBComboBox) then
        begin
          if TDBComboBox(Components[i]).Text = '' then
          showmessage('Null Value');
        end;
      end;
    end; 
     回复人:Kingron(WinAPI) (2001-5-7 13:18:00)  得0分 
    function isempty(edit:TObject;temp:string):boolean;
    begin
      if edit is TEdit then
        Result:=(Edit as TEdit).Text='';
      if edit is TCombobox then
        Result:=(Edit As TCombobox).Text='';
    end;  
     回复人:weenyboy(小公子) (2001-5-7 13:45:00)  得0分 
    function TForm1.isempty(component: TComponent): boolean;
    begin
      if Component.ClassName ='TEdit' then
        if TEdit(Component).Text='' then
          Result:=True
        else
          Result:=False
      else if Component.ClassName ='TComboBox' then
        if TComboBox(Component).Text='' then
          Result:=True
        else
          Result:=False;
    end;  
     回复人:yellowbb(阿黄) (2001-5-7 14:04:00)  得0分 
    谢谢各位的帮助,我在试一下。我会给分的。
    不过不多了,见笑。
     
     回复人:nisky(夜天) (2001-5-7 14:39:00)  得0分 
    传进去任何两个控件,判断是否有DATASOURCE属性!  
     回复人:yypp() (2001-5-7 14:46:00)  得0分 
    KINGRON的方法真是好又学到了我靠,VC真不是人学的,一大堆自动生成的代码看得头晕,动不动就是#if !defined(AFX_WINGREETDOC_H__921DB34B_42ED_11D5_82DD_005022300CC1__INCLUDED_)
    #define AFX_WINGREETDOC_H__921DB34B_42ED_11D5_82DD_005022300CC1__INCLUDED_
    这些东西,
    我faint.
    不过还是要继续学  
     回复人:yellowbb(阿黄) (2001-5-7 18:05:00)  得0分 
    有同感  
     回复人:copy_paste(paste) (2001-5-7 18:49:00)  得0分 
    function IsEmpty(Sender: TObject): Boolean;
    begin
      Result := TControl(Sender).Text = '';
    end;  
     回复人:BaldZhang(BaldZhang) (2001-5-7 20:30:00)  得0分 
    TO: copy_paste(paste)  好象TControl的Text属性是看不到的(Protected)啊  
     回复人:copy_paste(paste) (2001-5-7 21:11:00)  得0分 
    呵呵,出丑了。
    反正答案多几个无所谓.可以这样
    procedure Button1.OnClick(Sender: TObject);  function IsEmpty(Handle: THandle): Boolean;
      var
        Buf: array of Char;
      begin
        Result := False;
        if GetWindowText(Handle,@Buf,255) > 0 then
          Result := True;
      end;begin
      if IsEmpty(Edit1.Handle) or 
        IsEmpty(DBCombobox1.Handle) then
        ShowMessage('有东西。');
    end;  
     回复人:BaldZhang(BaldZhang) (2001-5-8 8:39:00)  得0分 
    何必呢,这么麻烦,哈哈哈哈再出个馊主意,
    Type
      TMyControl = class(TControl);function IsEmpty(Sender: TObject): Boolean;
    begin
      Result := TMyControl(Sender).Text = '';
    end; 
     
     回复人:maozefa(之源) (2001-5-8 9:42:00)  得0分 
    laza(秋高蓝)的写法是最通俗和正确的。应该加分。不过,应该把procedure改为function才符合提问者的要求。