ika*_*eat 0 delphi checkbox boolean
我有一个具有一些属性的对象:
Obj.Big
Obj.Rotate
Obj.Paint
Obj.Lines
Run Code Online (Sandbox Code Playgroud)
它们都是布尔类型属性.
在我的主程序中,我调用另一个程序:
procedure TMainForm.Create(Sender:TObject);
begin
SetParameter(BigCheckBox, Obj.Big);
SetParameter(RotateCheckBox, Obj.Rotate);
SetParameter(PaintCheckBox, Obj.Paint);
SetParameter(LinesCheckBox, Obj.Lines);
end;
Run Code Online (Sandbox Code Playgroud)
该SetParameter程序是这样的:
procedure TMainForm.SetParameter(ACheckBox : TCheckBox; ABoolOption : Boolean);
begin
if(ACheckBox.Checked) and (ACheckBox.Enabled) then begin
ABoolOption := true;
end
else if(not ACheckBox.Checked) and (ACheckBox.Enabled) then begin
ABoolOption := false;
end;
end;
Run Code Online (Sandbox Code Playgroud)
它接受checkbox对象和传递对象的布尔属性的属性ABoolOption.我不能简单地做,LinesCheckBox.Checked := Obj.Lines因为当复选框被填充时我需要"无所事事"动作(它们都是三态).当我运行它时,这些对象的参数都没有改变.为什么是这样?
你没有通过财产.你传递了那个属性的价值.IOW,你SetParameter正在接收ACheckBox, True或者ACheckBox, False,因此你无需改变.更好的方法可能是将SetParameter过程更改为函数:
function TMainForm.SetBooleanValue(const ACheckBox: TCheckBox): Boolean;
begin
Result := (ACheckBox.Checked) and (ACheckBox.Enabled);
end;
Run Code Online (Sandbox Code Playgroud)
然后使用它像:
Obj.Big := SetBooleanValue(BigCheckbox);
Obj.Rotate := SetBooleanValue(RotateCheckBox);
Obj.Paint := SetBooleanValue(PaintCheckBox);
Obj.Lines := SetBooleanValue(LinesCheckBox);
Run Code Online (Sandbox Code Playgroud)
如果您需要允许第三个选项,则应在执行以下呼叫之前先检查它SetBooleanValue:
if not ThirdCondition then
Obj.Big := SetBooleanValue(BigCheckBox);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
115 次 |
| 最近记录: |