J
Jar
Unregistered / Unconfirmed
GUEST, unregistred user!
本人工作程序一部分,有删除,仅仅一个思路而已。
private
{ Private declarations }
Namelbl:array[0..30] of Tlabel;
Allow:array[0..30] of TCheckBox;
EditBox:array[0..30] of TEdit;
UnitLbl:Array[0..30]of TLabel;
……
function CreateForm(DataSourceNo,TypeId:Byte):Boolean;
var
i,j:Byte
begin
result:=True;
try
begin
for i:=0 to FTotalPCount-1 do
begin
if FParam.UseFlag=0 then
begin
j:=j+1;
end
else
begin
Namelbl:=CreateName(FParam.Name,i,(i-j));
Allow:=CreateAllow(i,(i-j));
EditBox:=CreateEditBox(i,i-j);
UnitLbl:=CreateUnit(FParam.DataUnit,i,(i-j));
end;
end
else
begin
ShowMessage('输入界面生成出错');
Result:=False;
exit;
end;
end;
except
result:=False;
exit;
end;
end;
function CreateEditBox(i,j:Byte): TEdit;
//功能:生成数字量输入的edit
var
EdtParam:TEdit;
begin
try
begin
EdtParam:= TEdit.Create(GRMainFrm);
EdtParam.Name:='Edt'+IntToStr(i);
EdtParam.text:='';
EdtParam.Left:= PnlInput.Left;
EdtParam.top:= PnlInput.Top+(j+1)*(PnlInput.Height+2)+5;
EdtParam.height:=PnlInput.Height;
EdtParam.width:=PnlInput.Width;
Edtparam.Enabled:=False;
EdtParam.OnExit:=EditBoxExit;
EdtParam.OnKeyPress:=EditBoxKeyPress;
EdtParam.OnClick:=EditBoxClick;
EdtParam.Tag:=i;
EdtParam.Parent:=ScrollBox1;
Result:= Edtparam;
end;
except
Result:=Nil;
end;
end;
Procedure EditBoxClick(Sender:TObject);
var
I:Byte;
begin
i:=(Sender as Tcontrol).Tag;
if Sender=EditBox then
begin
if FParam.ParamType<=100 then
begin
if EditBox.Text='' then
begin
EditBox.Text:='On';
exit;
end;
if EditBox.Text='On' then
begin
EditBox.Text:='Off';
exit;
end;
if EditBox.Text='Off' then
begin
EditBox.Text:='On';
exit;
end;
end;
end;
end;
Procedure EditBoxExit(Sender:TObject);
var
i:Byte;
begin
i:=(Sender as Tcontrol).Tag
//访问标识
if Sender=EditBox then
begin
if Allow.Checked then
begin
if FParam.ParamType > 150 then
begin
if EditBox.Text<>'' then
begin
if ((StrToFloat(EditBox.Text)> FParam.Valmax) or (StrToFloat(EditBox.Text)<FParam.ValMin)) then
begin
ShowMessage('输入值必须在'+IntToStr(FParam.ValMin)+'-'+IntToStr(FParam.ValMax)+'之间!');
EditBox.Text:='';
EditBox.SetFocus;
end;
end;
end;
end;
end;
end;
private
{ Private declarations }
Namelbl:array[0..30] of Tlabel;
Allow:array[0..30] of TCheckBox;
EditBox:array[0..30] of TEdit;
UnitLbl:Array[0..30]of TLabel;
……
function CreateForm(DataSourceNo,TypeId:Byte):Boolean;
var
i,j:Byte
begin
result:=True;
try
begin
for i:=0 to FTotalPCount-1 do
begin
if FParam.UseFlag=0 then
begin
j:=j+1;
end
else
begin
Namelbl:=CreateName(FParam.Name,i,(i-j));
Allow:=CreateAllow(i,(i-j));
EditBox:=CreateEditBox(i,i-j);
UnitLbl:=CreateUnit(FParam.DataUnit,i,(i-j));
end;
end
else
begin
ShowMessage('输入界面生成出错');
Result:=False;
exit;
end;
end;
except
result:=False;
exit;
end;
end;
function CreateEditBox(i,j:Byte): TEdit;
//功能:生成数字量输入的edit
var
EdtParam:TEdit;
begin
try
begin
EdtParam:= TEdit.Create(GRMainFrm);
EdtParam.Name:='Edt'+IntToStr(i);
EdtParam.text:='';
EdtParam.Left:= PnlInput.Left;
EdtParam.top:= PnlInput.Top+(j+1)*(PnlInput.Height+2)+5;
EdtParam.height:=PnlInput.Height;
EdtParam.width:=PnlInput.Width;
Edtparam.Enabled:=False;
EdtParam.OnExit:=EditBoxExit;
EdtParam.OnKeyPress:=EditBoxKeyPress;
EdtParam.OnClick:=EditBoxClick;
EdtParam.Tag:=i;
EdtParam.Parent:=ScrollBox1;
Result:= Edtparam;
end;
except
Result:=Nil;
end;
end;
Procedure EditBoxClick(Sender:TObject);
var
I:Byte;
begin
i:=(Sender as Tcontrol).Tag;
if Sender=EditBox then
begin
if FParam.ParamType<=100 then
begin
if EditBox.Text='' then
begin
EditBox.Text:='On';
exit;
end;
if EditBox.Text='On' then
begin
EditBox.Text:='Off';
exit;
end;
if EditBox.Text='Off' then
begin
EditBox.Text:='On';
exit;
end;
end;
end;
end;
Procedure EditBoxExit(Sender:TObject);
var
i:Byte;
begin
i:=(Sender as Tcontrol).Tag
//访问标识
if Sender=EditBox then
begin
if Allow.Checked then
begin
if FParam.ParamType > 150 then
begin
if EditBox.Text<>'' then
begin
if ((StrToFloat(EditBox.Text)> FParam.Valmax) or (StrToFloat(EditBox.Text)<FParam.ValMin)) then
begin
ShowMessage('输入值必须在'+IntToStr(FParam.ValMin)+'-'+IntToStr(FParam.ValMax)+'之间!');
EditBox.Text:='';
EditBox.SetFocus;
end;
end;
end;
end;
end;
end;