您的位置:首页 > 编程语言 > Delphi

delphi中实现用字符串表示并操作控件的方法。

2006-05-13 17:39 706 查看
下面代码用字符串实现了对控件的操作,其中所有控件都在panel1内,

StrEdtProNum代表Tedit控件EdtProNum,其它同。

procedure TPM_FrmCFProPlan_Mon.CbUseMatUnit_1Change(Sender: TObject);
var
StrEdtProNum:String;
StrEdtClassNum:String;
StrEdtMatNum:String;
StrCbUseMat:String;
begin
try

StrEdtProNum:='';
StrEdtClassNum:='';
StrEdtMatNum:='';
StrCbUseMat:='';
i:=1;
for i:=1 to 15 do
begin
StrCbUseMat:='CbUseMatUnit_'+InttoStr(i)+'';
StrEdtProNum:='EdtProNum_'+InttoStr(i)+'';
StrEdtClassNum:='EdtClassNum_'+InttoStr(i)+'';
StrEdtMatNum:='EdtMatNum_'+InttoStr(i)+'';
//Compute Values of ProNum1 ClassNum1 and MatNum1
if TComboBox(Panel1.FindChildControl(StrCbUseMat)).Text='公司' then
begin
EdtProNum1.Text:=InttoStr(Round(Strtofloat(TEdit(Panel1.FindChildControl(StrEdtProNum)).Text)+Strtofloat(EdtProNum1.Text)));
EdtClassNum1.Text:=InttoStr(Round(Strtofloat(TEdit(Panel1.FindChildControl(StrEdtClassNum)).Text)+Strtofloat(EdtClassNum1.Text)));
EdtMatNum1.Text:=InttoStr(Round(Strtofloat(TEdit(Panel1.FindChildControl(StrEdtMatNum)).Text)+Strtofloat(EdtMatNum1.Text)));
end;
//Compute Values of ProNum2 ClassNum2 and MatNum2
if TComboBox(Panel1.FindChildControl(StrCbUseMat)).Text='住金公司' then
begin
EdtProNum2.Text:=InttoStr(Round(Strtofloat(TEdit(Panel1.FindChildControl(StrEdtProNum)).Text)+Strtofloat(EdtProNum2.Text)));
EdtClassNum2.Text:=InttoStr(Round(Strtofloat(TEdit(Panel1.FindChildControl(StrEdtClassNum)).Text)+Strtofloat(EdtClassNum2.Text)));
EdtMatNum2.Text:=InttoStr(Round(Strtofloat(TEdit(Panel1.FindChildControl(StrEdtMatNum)).Text)+Strtofloat(EdtMatNum2.Text)));
end;
end;
except
ShowMessage('输入数据格式不正确 ,请重新输入!')
end;
end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐