diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/backregunit.pas b/applications/lazstats/source/forms/analysis/multiple_regression/backregunit.pas index 82507f08a..385376032 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/backregunit.pas +++ b/applications/lazstats/source/forms/analysis/multiple_regression/backregunit.pas @@ -67,6 +67,9 @@ var implementation +uses + Utils; + { TBackRegFrm } procedure TBackRegFrm.ResetBtnClick(Sender: TObject); @@ -459,29 +462,14 @@ end; procedure TBackRegFrm.UpdateBtnStates; var - i: Integer; lSelected: Boolean; begin - lSelected := false; - for i := 0 to VarList.Items.Count-1 do - if VarList.Selected[i] then - begin - lSelected := true; - break; - end; + lSelected := AnySelected(VarList); DepInBtn.Enabled := lSelected and (DepVar.Text = ''); InBtn.Enabled := lSelected; DepOutBtn.Enabled := DepVar.Text <> ''; - - lSelected := false; - for i := 0 to SelList.Items.Count-1 do - if SelList.Selected[i] then - begin - lSelected := true; - break; - end; - OutBtn.Enabled := lSelected; + OutBtn.Enabled := AnySelected(SelList); end; diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.pas b/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.pas index 9262b5ce2..eabd04795 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.pas +++ b/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.pas @@ -69,7 +69,8 @@ var implementation uses - Math; + Math, + Utils; { TCoxRegFrm } @@ -625,28 +626,14 @@ end; procedure TCoxRegFrm.UpdateBtnStates; var - i: Integer; lSelected: Boolean; begin - lSelected := false; - for i := 0 to VarList.Items.Count-1 do - if VarList.Selected[i] then - begin - lSelected := true; - break; - end; + lSelected := AnySelected(VarList); InBtn.Enabled := lSelected; DepInBtn.Enabled := lSelected and (DepVar.Text = ''); StatusInBtn.Enabled := lSelected and (StatusEdit.Text = ''); - lSelected := false; - for i := 0 to BlockList.Items.Count-1 do - if BlockList.Selected[i] then - begin - lSelected := true; - break; - end; - OutBtn.Enabled := lSelected; + OutBtn.Enabled := AnySelected(BlockList); DepOutBtn.Enabled := DepVar.Text <> ''; StatusOutBtn.Enabled := StatusEdit.Text <> ''; end; diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/stepfwdmrunit.pas b/applications/lazstats/source/forms/analysis/multiple_regression/stepfwdmrunit.pas index 7a541dc84..cf8705214 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/stepfwdmrunit.pas +++ b/applications/lazstats/source/forms/analysis/multiple_regression/stepfwdmrunit.pas @@ -72,7 +72,8 @@ var implementation uses - Math; + Math, + Utils; { TStepFwdFrm } @@ -578,30 +579,12 @@ begin end; procedure TStepFwdFrm.UpdateBtnStates; -var - lSelected: Boolean; - i: Integer; begin DepInBtn.Enabled := (VarList.ItemIndex > -1) and (DepVar.Text = ''); DepOutBtn.Enabled := (DepVar.Text <> ''); - lSelected := false; - for i:=0 to VarList.Items.Count-1 do - if VarList.Selected[i] then - begin - lSelected := true; - break; - end; - InBtn.Enabled := lSelected; - - lSelected := false; - for i := 0 to SelList.Items.Count-1 do - if SelList.Selected[i] then - begin - lSelected := true; - break; - end; - OutBtn.Enabled := lSelected; + InBtn.Enabled := AnySelected(VarList); + OutBtn.Enabled := AnySelected(SelList); end; diff --git a/applications/lazstats/source/units/utils.pas b/applications/lazstats/source/units/utils.pas new file mode 100644 index 000000000..ee2f55235 --- /dev/null +++ b/applications/lazstats/source/units/utils.pas @@ -0,0 +1,28 @@ +unit Utils; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, StdCtrls; + +function AnySelected(AListbox: TListBox): Boolean; + +implementation + +function AnySelected(AListBox: TListBox): Boolean; +var + i: Integer; +begin + Result := false; + for i := 0 to AListbox.Items.Count-1 do + if AListbox.Selected[i] then + begin + Result := true; + exit; + end; +end; + +end. +