公共函数
我想实现这样一个公共函数,在各个不同的窗体内调用:
输入:(本窗体实例,窗体类名,组件名)
如果 本窗体实例的该组件 存在,则判断组件类型,
如果是tedit,则返回text值,如果是tlabel,则返回Caption值
谢谢
问题点数:20、回复次数:4Top
1 楼wfhlxl(光明正大地偷......学)回复于 2005-05-05 07:07:42 得分 20
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;Top
2 楼carion(carion)回复于 2005-05-05 12:20:55 得分 0
有更简单的吗,不用循环查找吧Top
3 楼carion(carion)回复于 2005-05-05 16:59:42 得分 0
用findcomponent行吗,不过好像在unit1引用unit2的form,用findcomponent可以tedit组件找到,但读text的时候发现是空的,不知道为什么Top
4 楼carion(carion)回复于 2005-05-06 01:29:09 得分 0
自己顶一下
Top




