我想实现这样一个公共函数,在各个不同的窗体内调用:
输入:(本窗体实例,窗体类名,组件名)
如果 本窗体实例的该组件 存在,则判断组件类型,
如果是tedit,则返回text值,如果是tlabel,则返回Caption值谢谢

解决方案 »

  1.   

    function GetChildWindowText(Form : Twincontrol;ControlName :string) : string;
    var
    i,j:integer;
    wincontrol : twincontrol;
    begin
      for i:=0 to Form.controlcount - 1 do
      begin
       if (form.controls[i] is twincontrol) then
       begin
         result := GetChildWindowText(twincontrol(form.controls[i]),controlname);
         if (form.controls[i] is tedit) and (form.controls[i].Name = controlname) then
         begin
           result := tedit(form.controls[i]).text;
         end;
       end else begin
          if (form.controls[i] is tlabel) and (form.controls[i].Name = controlname) then
           result := tlabel(form.controls[i]).caption;
         end;
       end;
      end;
      

  2.   

    用findcomponent行吗,不过好像在unit1引用unit2的form,用findcomponent可以tedit组件找到,但读text的时候发现是空的,不知道为什么