下面代码用字符串实现了对控件的操作,其中所有控件都在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;