diff --git a/applications/lazstats/source/forms/simulations/fprobunit.lfm b/applications/lazstats/source/forms/simulations/fprobunit.lfm index f5b132269..9afce89c5 100644 --- a/applications/lazstats/source/forms/simulations/fprobunit.lfm +++ b/applications/lazstats/source/forms/simulations/fprobunit.lfm @@ -29,7 +29,7 @@ object FForm: TFForm Cancel = True Caption = 'Cancel' ModalResult = 2 - TabOrder = 0 + TabOrder = 1 end object ResetBtn: TButton AnchorSideTop.Control = Bevel1 @@ -45,7 +45,7 @@ object FForm: TFForm BorderSpacing.Right = 12 Caption = 'Reset' OnClick = ResetBtnClick - TabOrder = 1 + TabOrder = 2 end object ComputeBtn: TButton AnchorSideTop.Control = Bevel1 @@ -61,7 +61,7 @@ object FForm: TFForm BorderSpacing.Right = 12 Caption = 'Compute' OnClick = ComputeBtnClick - TabOrder = 2 + TabOrder = 3 end object ReturnBtn: TButton AnchorSideTop.Control = Bevel1 @@ -79,7 +79,7 @@ object FForm: TFForm BorderSpacing.Bottom = 8 Caption = 'Return' ModalResult = 1 - TabOrder = 3 + TabOrder = 4 end object Bevel1: TBevel AnchorSideLeft.Control = Owner @@ -108,18 +108,18 @@ object FForm: TFForm BevelOuter = bvNone ClientHeight = 85 ClientWidth = 412 - TabOrder = 4 + TabOrder = 0 object Label1: TLabel AnchorSideTop.Control = FEdit AnchorSideTop.Side = asrCenter AnchorSideRight.Control = Label4 AnchorSideRight.Side = asrBottom - Left = 88 + Left = 102 Height = 15 Top = 4 - Width = 117 + Width = 103 Anchors = [akTop, akRight] - Caption = 'Given: An F statistic = ' + Caption = 'Given: An F statistic' ParentColor = False end object FEdit: TEdit @@ -141,12 +141,12 @@ object FForm: TFForm AnchorSideTop.Side = asrCenter AnchorSideRight.Control = Label4 AnchorSideRight.Side = asrBottom - Left = 88 + Left = 91 Height = 15 Top = 31 - Width = 117 + Width = 114 Anchors = [akTop, akRight] - Caption = 'with Deg. Freedom of ' + Caption = 'with deg. freedom of ' ParentColor = False end object DF1Edit: TEdit @@ -199,7 +199,7 @@ object FForm: TFForm Height = 15 Top = 66 Width = 205 - Caption = 'then the probability of a larger value = ' + Caption = 'then the probability of a larger value is' ParentColor = False end object ProbEdit: TEdit diff --git a/applications/lazstats/source/forms/simulations/fprobunit.pas b/applications/lazstats/source/forms/simulations/fprobunit.pas index edf8e6fc6..e6e734e8c 100644 --- a/applications/lazstats/source/forms/simulations/fprobunit.pas +++ b/applications/lazstats/source/forms/simulations/fprobunit.pas @@ -41,8 +41,10 @@ var implementation +{$R *.lfm} + uses - Math, MathUnit; + Math, MathUnit, Utils; { TFForm } @@ -55,14 +57,33 @@ begin end; procedure TFForm.ComputeBtnClick(Sender: TObject); -VAR - F, df1, df2, prob : extended; +var + F, prob: Double; + df1, df2: Integer; begin - F := StrToFloat(FEdit.Text); - df1 := StrToFloat(DF1Edit.Text); - df2 := StrToFloat(DF2Edit.Text); - prob := ProbF(F,df1,df2); - ProbEdit.Text := Format('%6.4f',[prob]); + if not MyTryStrToFloat(FEdit.Text, F) then + begin + FEdit.SetFocus; + ErrorMsg('No valid number.'); + exit; + end; + + if not TryStrToInt(DF1Edit.Text, df1) then + begin + DF1Edit.SetFocus; + ErrorMsg('No valid integer (must be positive).'); + exit; + end; + + if not TryStrToInt(DF2Edit.Text, df2) then + begin + DF2Edit.SetFocus; + ErrorMsg('No valid integer (must be positive).'); + exit; + end; + + prob := ProbF(F, df1, df2); + ProbEdit.Text := Format('%6.4f', [prob]); end; procedure TFForm.FormActivate(Sender: TObject); @@ -77,8 +98,5 @@ begin end; -initialization - {$I fprobunit.lrs} - end. diff --git a/applications/lazstats/source/forms/simulations/inversezunit.lfm b/applications/lazstats/source/forms/simulations/inversezunit.lfm index 94829005a..4ff95baea 100644 --- a/applications/lazstats/source/forms/simulations/inversezunit.lfm +++ b/applications/lazstats/source/forms/simulations/inversezunit.lfm @@ -29,7 +29,7 @@ object InversezForm: TInversezForm Cancel = True Caption = 'Cancel' ModalResult = 2 - TabOrder = 0 + TabOrder = 1 end object ResetBtn: TButton AnchorSideTop.Control = Bevel1 @@ -45,7 +45,7 @@ object InversezForm: TInversezForm BorderSpacing.Right = 12 Caption = 'Reset' OnClick = ResetBtnClick - TabOrder = 1 + TabOrder = 2 end object ComputeBtn: TButton AnchorSideTop.Control = Bevel1 @@ -61,7 +61,7 @@ object InversezForm: TInversezForm BorderSpacing.Right = 12 Caption = 'Compute' OnClick = ComputeBtnClick - TabOrder = 2 + TabOrder = 3 end object ReturnBtn: TButton AnchorSideTop.Control = Bevel1 @@ -78,7 +78,7 @@ object InversezForm: TInversezForm BorderSpacing.Right = 16 Caption = 'Return' ModalResult = 1 - TabOrder = 3 + TabOrder = 4 end object Bevel1: TBevel AnchorSideLeft.Control = Owner @@ -97,29 +97,29 @@ object InversezForm: TInversezForm AnchorSideLeft.Control = Owner AnchorSideLeft.Side = asrCenter AnchorSideTop.Control = Owner - Left = 54 + Left = 65 Height = 54 Top = 8 - Width = 239 + Width = 217 AutoSize = True BorderSpacing.Left = 8 BorderSpacing.Top = 8 BorderSpacing.Right = 8 BevelOuter = bvNone ClientHeight = 54 - ClientWidth = 239 - TabOrder = 4 + ClientWidth = 217 + TabOrder = 0 object Label1: TLabel AnchorSideTop.Control = ProbEdit AnchorSideTop.Side = asrCenter AnchorSideRight.Control = Label2 AnchorSideRight.Side = asrBottom - Left = 8 + Left = 0 Height = 15 Top = 4 - Width = 135 + Width = 121 Anchors = [akTop, akRight] - Caption = 'Cumulative Probability = ' + Caption = 'Cumulative Probability' ParentColor = False end object ProbEdit: TEdit @@ -127,7 +127,7 @@ object InversezForm: TInversezForm AnchorSideTop.Control = Panel1 AnchorSideRight.Control = ZEdit AnchorSideRight.Side = asrBottom - Left = 151 + Left = 129 Height = 23 Top = 0 Width = 88 @@ -143,8 +143,8 @@ object InversezForm: TInversezForm Left = 0 Height = 15 Top = 35 - Width = 143 - Caption = 'Corresponds to a z value = ' + Width = 121 + Caption = 'Corresponding z value ' ParentColor = False end object ZEdit: TEdit @@ -152,7 +152,7 @@ object InversezForm: TInversezForm AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = ProbEdit AnchorSideTop.Side = asrBottom - Left = 151 + Left = 129 Height = 23 Top = 31 Width = 88 diff --git a/applications/lazstats/source/forms/simulations/inversezunit.pas b/applications/lazstats/source/forms/simulations/inversezunit.pas index 78fbc11b9..df2ec3848 100644 --- a/applications/lazstats/source/forms/simulations/inversezunit.pas +++ b/applications/lazstats/source/forms/simulations/inversezunit.pas @@ -6,8 +6,7 @@ interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, - StdCtrls, ExtCtrls, - Functionslib; + StdCtrls, ExtCtrls; type @@ -38,8 +37,10 @@ var implementation +{$R *.lfm} + uses - Math; + Math, MathUnit, Utils; { TInversezForm } @@ -50,14 +51,17 @@ begin end; procedure TInversezForm.ComputeBtnClick(Sender: TObject); -VAR - Prob, Zscore : double; - outvalue : string; +var + prob, zScore: double; begin - Prob := StrToFloat(ProbEdit.Text); - Zscore := inversez(Prob); - outvalue := format('%6.4f',[Zscore]); - ZEdit.Text := outvalue; + if not MyTryStrToFloat(ProbEdit.Text, prob) then + begin + ProbEdit.SetFocus; + ErrorMsg('No valid number.'); + exit; + end; + zScore := InverseNormalDist(prob); + ZEdit.Text := Format('%6.4f', [zScore]); end; procedure TInversezForm.FormActivate(Sender: TObject); @@ -71,8 +75,5 @@ begin ReturnBtn.Constraints.MinWidth := w; end; -initialization - {$I inversezunit.lrs} - end. diff --git a/applications/lazstats/source/forms/simulations/probchisqrunit.lfm b/applications/lazstats/source/forms/simulations/probchisqrunit.lfm index 2337d733a..c458e62e7 100644 --- a/applications/lazstats/source/forms/simulations/probchisqrunit.lfm +++ b/applications/lazstats/source/forms/simulations/probchisqrunit.lfm @@ -26,7 +26,7 @@ object ChiSqrProbForm: TChiSqrProbForm Cancel = True Caption = 'Cancel' ModalResult = 2 - TabOrder = 0 + TabOrder = 1 end object ResetBtn: TButton AnchorSideTop.Control = ReturnBtn @@ -40,7 +40,7 @@ object ChiSqrProbForm: TChiSqrProbForm BorderSpacing.Right = 8 Caption = 'Reset' OnClick = ResetBtnClick - TabOrder = 1 + TabOrder = 2 end object ComputeBtn: TButton AnchorSideTop.Control = ReturnBtn @@ -54,7 +54,7 @@ object ChiSqrProbForm: TChiSqrProbForm BorderSpacing.Right = 8 Caption = 'Compute' OnClick = ComputeBtnClick - TabOrder = 2 + TabOrder = 3 end object ReturnBtn: TButton AnchorSideTop.Control = Bevel1 @@ -73,7 +73,7 @@ object ChiSqrProbForm: TChiSqrProbForm BorderSpacing.Bottom = 8 Caption = 'Return' ModalResult = 1 - TabOrder = 3 + TabOrder = 4 end object Bevel1: TBevel AnchorSideLeft.Control = Owner @@ -92,18 +92,18 @@ object ChiSqrProbForm: TChiSqrProbForm AnchorSideLeft.Control = Owner AnchorSideLeft.Side = asrCenter AnchorSideTop.Control = Owner - Left = 86 + Left = 93 Height = 85 Top = 8 - Width = 217 + Width = 203 AutoSize = True BorderSpacing.Left = 8 BorderSpacing.Top = 8 BorderSpacing.Right = 8 BevelOuter = bvNone ClientHeight = 85 - ClientWidth = 217 - TabOrder = 4 + ClientWidth = 203 + TabOrder = 0 object Label1: TLabel AnchorSideTop.Control = ChiSqrEdit AnchorSideTop.Side = asrCenter @@ -112,10 +112,10 @@ object ChiSqrProbForm: TChiSqrProbForm Left = 30 Height = 15 Top = 4 - Width = 105 + Width = 91 Anchors = [akTop, akRight] BorderSpacing.Left = 8 - Caption = 'Chisquared value = ' + Caption = 'Chisquared value' ParentColor = False end object ChiSqrEdit: TEdit @@ -123,7 +123,7 @@ object ChiSqrProbForm: TChiSqrProbForm AnchorSideTop.Control = Panel1 AnchorSideRight.Control = ProbEdit AnchorSideRight.Side = asrBottom - Left = 143 + Left = 129 Height = 23 Top = 0 Width = 74 @@ -140,10 +140,10 @@ object ChiSqrProbForm: TChiSqrProbForm Left = 24 Height = 15 Top = 31 - Width = 111 + Width = 97 Anchors = [akTop, akRight] BorderSpacing.Left = 8 - Caption = 'with deg. freedom = ' + Caption = 'with deg. freedom' ParentColor = False end object DFEdit: TEdit @@ -152,7 +152,7 @@ object ChiSqrProbForm: TChiSqrProbForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ProbEdit AnchorSideRight.Side = asrBottom - Left = 143 + Left = 129 Height = 23 Top = 27 Width = 74 @@ -169,8 +169,8 @@ object ChiSqrProbForm: TChiSqrProbForm Left = 0 Height = 15 Top = 66 - Width = 135 - Caption = 'Probability larger value = ' + Width = 121 + Caption = 'Probability larger value' ParentColor = False end object ProbEdit: TEdit @@ -178,7 +178,7 @@ object ChiSqrProbForm: TChiSqrProbForm AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = DFEdit AnchorSideTop.Side = asrBottom - Left = 143 + Left = 129 Height = 23 Top = 62 Width = 74 diff --git a/applications/lazstats/source/forms/simulations/probchisqrunit.pas b/applications/lazstats/source/forms/simulations/probchisqrunit.pas index 579bde031..83ff41c53 100644 --- a/applications/lazstats/source/forms/simulations/probchisqrunit.pas +++ b/applications/lazstats/source/forms/simulations/probchisqrunit.pas @@ -40,8 +40,10 @@ var implementation +{$R *.lfm} + uses - Math; + Math, MathUnit, Utils; { TChiSqrProbForm } @@ -53,16 +55,25 @@ begin end; procedure TChiSqrProbForm.ComputeBtnClick(Sender: TObject); -VAR - ChiSqr, Prob : double; - DF : integer; - outvalue : string; +var + chiSqr, prob: double; + DF: integer; begin - ChiSqr := StrToFloat(ChiSqrEdit.Text); - DF := StrToInt(DFEdit.Text); - Prob := 1.0 - chisquaredprob(ChiSqr,DF); - outvalue := format('%6.4f',[Prob]); - ProbEdit.Text := outvalue; + if not MyTryStrToFloat(ChiSqrEdit.Text, chiSqr) then + begin + ChiSqrEdit.SetFocus; + ErrorMsg('No valid number.'); + exit; + end; + + if not TryStrToInt(DFEdit.Text, DF) or (DF <= 0) then begin + DFEdit.SetFocus; + ErrorMsg('No a valid integer (must be positive).'); + exit; + end; + + prob := 1.0 - ChiSquaredProb(ChiSqr, DF); + ProbEdit.Text := Format('%6.4f', [prob]); end; procedure TChiSqrProbForm.FormActivate(Sender: TObject); @@ -76,8 +87,5 @@ begin ReturnBtn.Constraints.MinWidth := w; end; -initialization - {$I probchisqrunit.lrs} - end. diff --git a/applications/lazstats/source/forms/simulations/probsmallerzunit.lfm b/applications/lazstats/source/forms/simulations/probsmallerzunit.lfm index 17c13f1a8..95016dbf4 100644 --- a/applications/lazstats/source/forms/simulations/probsmallerzunit.lfm +++ b/applications/lazstats/source/forms/simulations/probsmallerzunit.lfm @@ -29,7 +29,7 @@ object ProbSmallerzForm: TProbSmallerzForm Cancel = True Caption = 'Cancel' ModalResult = 2 - TabOrder = 0 + TabOrder = 1 end object ResetBtn: TButton AnchorSideTop.Control = Bevel1 @@ -45,7 +45,7 @@ object ProbSmallerzForm: TProbSmallerzForm BorderSpacing.Right = 12 Caption = 'Reset' OnClick = ResetBtnClick - TabOrder = 1 + TabOrder = 2 end object ComputeBtn: TButton AnchorSideTop.Control = Bevel1 @@ -61,7 +61,7 @@ object ProbSmallerzForm: TProbSmallerzForm BorderSpacing.Right = 12 Caption = 'Compute' OnClick = ComputeBtnClick - TabOrder = 2 + TabOrder = 3 end object ReturnBtn: TButton AnchorSideTop.Control = Bevel1 @@ -79,38 +79,38 @@ object ProbSmallerzForm: TProbSmallerzForm BorderSpacing.Bottom = 8 Caption = 'Return' ModalResult = 1 - TabOrder = 3 + TabOrder = 4 end object Panel1: TPanel AnchorSideLeft.Control = Owner AnchorSideLeft.Side = asrCenter - Left = 57 + Left = 64 Height = 54 Top = 4 - Width = 194 + Width = 180 AutoSize = True BorderSpacing.Left = 8 BorderSpacing.Top = 8 BorderSpacing.Right = 8 BevelOuter = bvNone ClientHeight = 54 - ClientWidth = 194 - TabOrder = 4 + ClientWidth = 180 + TabOrder = 0 object Label1: TLabel AnchorSideTop.Control = zEdit AnchorSideTop.Side = asrCenter Left = 0 Height = 15 Top = 4 - Width = 103 - Caption = 'Observed z score = ' + Width = 89 + Caption = 'Observed z score' ParentColor = False end object zEdit: TEdit AnchorSideLeft.Control = Label1 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 111 + Left = 97 Height = 23 Top = 0 Width = 83 @@ -127,9 +127,9 @@ object ProbSmallerzForm: TProbSmallerzForm Left = 13 Height = 15 Top = 35 - Width = 90 + Width = 76 Anchors = [akTop, akRight] - Caption = 'Probability < z = ' + Caption = 'Probability < z' ParentColor = False end object ProbzEdit: TEdit @@ -138,7 +138,7 @@ object ProbSmallerzForm: TProbSmallerzForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = zEdit AnchorSideRight.Side = asrBottom - Left = 111 + Left = 97 Height = 23 Top = 31 Width = 83 diff --git a/applications/lazstats/source/forms/simulations/probsmallerzunit.pas b/applications/lazstats/source/forms/simulations/probsmallerzunit.pas index f9563cc5d..6c16267fd 100644 --- a/applications/lazstats/source/forms/simulations/probsmallerzunit.pas +++ b/applications/lazstats/source/forms/simulations/probsmallerzunit.pas @@ -6,8 +6,7 @@ interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, - StdCtrls, ExtCtrls, - Functionslib; + StdCtrls, ExtCtrls; type @@ -38,26 +37,31 @@ var implementation +{$R *.lfm} + uses - Math; + Math, MathUnit, Utils; { TProbSmallerzForm } procedure TProbSmallerzForm.ResetBtnClick(Sender: TObject); begin - zEdit.Text := ''; - ProbzEdit.Text := ''; + zEdit.Text := ''; + ProbzEdit.Text := ''; end; procedure TProbSmallerzForm.ComputeBtnClick(Sender: TObject); -VAR - zprob, z : double; - outvalue : string; +var + zprob, z: double; begin - z := StrToFloat(zEdit.Text); - zprob := probz(z); - outvalue := format('%6.4f',[zprob]); - ProbzEdit.Text := outvalue; + if not MyTryStrToFloat(zEdit.Text, z) then + begin + zEdit.SetFocus; + ErrorMsg('No valid number.'); + exit; + end; + zProb := NormalDist(z); + ProbzEdit.Text := Format('%6.4f', [zProb]); end; procedure TProbSmallerzForm.FormActivate(Sender: TObject); @@ -71,8 +75,5 @@ begin ReturnBtn.Constraints.MinWidth := w; end; -initialization - {$I probsmallerzunit.lrs} - end. diff --git a/applications/lazstats/source/forms/simulations/probzunit.lfm b/applications/lazstats/source/forms/simulations/probzunit.lfm index 07dd9e9ac..4d053baa0 100644 --- a/applications/lazstats/source/forms/simulations/probzunit.lfm +++ b/applications/lazstats/source/forms/simulations/probzunit.lfm @@ -29,7 +29,7 @@ object ProbzForm: TProbzForm Cancel = True Caption = 'Cancel' ModalResult = 2 - TabOrder = 0 + TabOrder = 1 end object ResetBtn: TButton AnchorSideTop.Control = Bevel1 @@ -45,7 +45,7 @@ object ProbzForm: TProbzForm BorderSpacing.Right = 12 Caption = 'Reset' OnClick = ResetBtnClick - TabOrder = 1 + TabOrder = 2 end object ComputeBtn: TButton AnchorSideTop.Control = Bevel1 @@ -61,7 +61,7 @@ object ProbzForm: TProbzForm BorderSpacing.Right = 12 Caption = 'Compute' OnClick = ComputeBtnClick - TabOrder = 2 + TabOrder = 3 end object ReturnBtn: TButton AnchorSideTop.Control = Bevel1 @@ -79,7 +79,7 @@ object ProbzForm: TProbzForm BorderSpacing.Bottom = 8 Caption = 'Return' ModalResult = 1 - TabOrder = 3 + TabOrder = 4 end object Bevel1: TBevel AnchorSideLeft.Control = Owner @@ -98,18 +98,18 @@ object ProbzForm: TProbzForm AnchorSideLeft.Control = Owner AnchorSideLeft.Side = asrCenter AnchorSideTop.Control = Owner - Left = 58 + Left = 65 Height = 55 Top = 8 - Width = 194 + Width = 180 AutoSize = True BorderSpacing.Left = 8 BorderSpacing.Top = 8 BorderSpacing.Right = 8 BevelOuter = bvNone ClientHeight = 55 - ClientWidth = 194 - TabOrder = 4 + ClientWidth = 180 + TabOrder = 0 object Label1: TLabel AnchorSideLeft.Control = Panel1 AnchorSideTop.Control = zEdit @@ -117,14 +117,14 @@ object ProbzForm: TProbzForm Left = 0 Height = 15 Top = 4 - Width = 103 - Caption = 'Observed z score = ' + Width = 89 + Caption = 'Observed z score' ParentColor = False end object zEdit: TEdit AnchorSideLeft.Control = Label1 AnchorSideLeft.Side = asrBottom - Left = 111 + Left = 97 Height = 23 Top = 0 Width = 83 @@ -141,16 +141,16 @@ object ProbzForm: TProbzForm Left = 13 Height = 15 Top = 36 - Width = 90 + Width = 76 Anchors = [akTop, akRight] - Caption = 'Probability > z = ' + Caption = 'Probability > z' ParentColor = False end object ProbzEdit: TEdit AnchorSideLeft.Control = zEdit AnchorSideRight.Control = zEdit AnchorSideRight.Side = asrBottom - Left = 111 + Left = 97 Height = 23 Top = 32 Width = 83 diff --git a/applications/lazstats/source/forms/simulations/probzunit.pas b/applications/lazstats/source/forms/simulations/probzunit.pas index c30c2c0d8..a56130a73 100644 --- a/applications/lazstats/source/forms/simulations/probzunit.pas +++ b/applications/lazstats/source/forms/simulations/probzunit.pas @@ -6,8 +6,7 @@ interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, - StdCtrls, ExtCtrls, - FunctionsLib; + StdCtrls, ExtCtrls; type @@ -38,8 +37,10 @@ var implementation +{$R *.lfm} + uses - Math; + Math, MathUnit, Utils; { TProbzForm } @@ -50,14 +51,17 @@ begin end; procedure TProbzForm.ComputeBtnClick(Sender: TObject); -VAR - zprob, z : double; - outvalue : string; +var + zprob, z: double; begin - z := StrToFloat(zEdit.Text); - zprob := 1.0 - probz(z); - outvalue := format('%6.4f',[zprob]); - ProbzEdit.Text := outvalue; + if not MyTryStrToFloat(zEdit.Text, z) then + begin + zEdit.SetFocus; + ErrorMsg('No valid number.'); + exit; + end; + zProb := 1.0 - NormalDist(z); + ProbzEdit.Text := Format('%6.4f', [zProb]); end; procedure TProbzForm.FormActivate(Sender: TObject); @@ -71,8 +75,5 @@ begin ReturnBtn.Constraints.MinWidth := w; end; -initialization - {$I probzunit.lrs} - end. diff --git a/applications/lazstats/source/forms/simulations/tprobunit.lfm b/applications/lazstats/source/forms/simulations/tprobunit.lfm index f30404f21..ad0480321 100644 --- a/applications/lazstats/source/forms/simulations/tprobunit.lfm +++ b/applications/lazstats/source/forms/simulations/tprobunit.lfm @@ -29,7 +29,7 @@ object TProbForm: TTProbForm Cancel = True Caption = 'Cancel' ModalResult = 2 - TabOrder = 0 + TabOrder = 1 end object ResetBtn: TButton AnchorSideTop.Control = Bevel1 @@ -45,7 +45,7 @@ object TProbForm: TTProbForm BorderSpacing.Right = 12 Caption = 'Reset' OnClick = ResetBtnClick - TabOrder = 1 + TabOrder = 2 end object ComputeBtn: TButton AnchorSideTop.Control = Bevel1 @@ -61,7 +61,7 @@ object TProbForm: TTProbForm BorderSpacing.Right = 12 Caption = 'Compute' OnClick = ComputeBtnClick - TabOrder = 2 + TabOrder = 3 end object ReturnBtn: TButton AnchorSideTop.Control = Bevel1 @@ -79,7 +79,7 @@ object TProbForm: TTProbForm BorderSpacing.Bottom = 8 Caption = 'Return' ModalResult = 1 - TabOrder = 3 + TabOrder = 4 end object Bevel1: TBevel AnchorSideLeft.Control = Owner @@ -98,18 +98,18 @@ object TProbForm: TTProbForm AnchorSideLeft.Control = Owner AnchorSideLeft.Side = asrCenter AnchorSideTop.Control = Owner - Left = 87 + Left = 94 Height = 85 Top = 8 - Width = 217 + Width = 203 AutoSize = True BorderSpacing.Left = 8 BorderSpacing.Top = 8 BorderSpacing.Right = 8 BevelOuter = bvNone ClientHeight = 85 - ClientWidth = 217 - TabOrder = 4 + ClientWidth = 203 + TabOrder = 0 object Label1: TLabel AnchorSideTop.Control = tValueEdit AnchorSideTop.Side = asrCenter @@ -118,9 +118,9 @@ object TProbForm: TTProbForm Left = 42 Height = 15 Top = 4 - Width = 93 + Width = 79 Anchors = [akTop, akRight] - Caption = 'Student t value = ' + Caption = 'Student t value' ParentColor = False end object tValueEdit: TEdit @@ -128,7 +128,7 @@ object TProbForm: TTProbForm AnchorSideTop.Control = Panel1 AnchorSideRight.Control = ProbEdit AnchorSideRight.Side = asrBottom - Left = 143 + Left = 129 Height = 23 Top = 0 Width = 74 @@ -145,9 +145,9 @@ object TProbForm: TTProbForm Left = 24 Height = 15 Top = 31 - Width = 111 + Width = 97 Anchors = [akTop, akRight] - Caption = 'with deg. freedom = ' + Caption = 'with deg. freedom' ParentColor = False end object DFEdit: TEdit @@ -156,7 +156,7 @@ object TProbForm: TTProbForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ProbEdit AnchorSideRight.Side = asrBottom - Left = 143 + Left = 129 Height = 23 Top = 27 Width = 74 @@ -173,8 +173,8 @@ object TProbForm: TTProbForm Left = 0 Height = 15 Top = 66 - Width = 135 - Caption = 'Probability larger value = ' + Width = 121 + Caption = 'Probability larger value' ParentColor = False end object ProbEdit: TEdit @@ -182,7 +182,7 @@ object TProbForm: TTProbForm AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = DFEdit AnchorSideTop.Side = asrBottom - Left = 143 + Left = 129 Height = 23 Top = 62 Width = 74 diff --git a/applications/lazstats/source/forms/simulations/tprobunit.pas b/applications/lazstats/source/forms/simulations/tprobunit.pas index c91c679aa..7f2f97451 100644 --- a/applications/lazstats/source/forms/simulations/tprobunit.pas +++ b/applications/lazstats/source/forms/simulations/tprobunit.pas @@ -42,7 +42,7 @@ implementation {$R *.lfm} uses - Math, MathUnit; + Math, MathUnit, Utils; { TTProbForm } @@ -54,18 +54,32 @@ begin end; procedure TTProbForm.ComputeBtnClick(Sender: TObject); -VAR - tvalue, dfvalue, prob : double; - outvalue : string; +var + tvalue, prob: double; + dfValue: Integer; begin - tvalue := StrToFloat(tValueEdit.Text); - dfvalue := StrToFloat(DFEdit.Text); - if tvalue >= 0.0 then prob := 0.5 * ProbT(tvalue,dfvalue); - if tvalue < 0.0 then prob := 1.0 - ProbT(tvalue,dfvalue) + - (0.5 * probt(tvalue,dfvalue)) ; - if tvalue = 0.0 then prob := 0.50; - outvalue := format('%6.4f',[prob]); - ProbEdit.Text := outvalue; + if not MyTryStrToFloat(tValueEdit.Text, tvalue) then + begin + tValueEdit.SetFocus; + ErrorMsg('No valid number.'); + exit; + end; + + if not TryStrToInt(DFEdit.Text, dfValue) then + begin + dfEdit.SetFocus; + ErrorMsg('Not a valid integer (must be positive).'); + exit; + end; + + if tvalue >= 0.0 then + prob := 0.5 * ProbT(tvalue, dfvalue) + else if tvalue < 0.0 then + prob := 1.0 - ProbT(tvalue, dfvalue) + (0.5 *ProbT(tvalue, dfvalue)) + else + prob := 0.50; + + ProbEdit.Text := Format('%6.4f', [prob]); end; procedure TTProbForm.FormActivate(Sender: TObject); diff --git a/applications/lazstats/source/forms/simulations/twozprobunit.lfm b/applications/lazstats/source/forms/simulations/twozprobunit.lfm index e694e6cb4..7aadd1c3b 100644 --- a/applications/lazstats/source/forms/simulations/twozprobunit.lfm +++ b/applications/lazstats/source/forms/simulations/twozprobunit.lfm @@ -8,6 +8,7 @@ object TwozProbForm: TTwozProbForm Caption = 'Probability between two z scores' ClientHeight = 147 ClientWidth = 378 + OnActivate = FormActivate OnShow = ResetBtnClick Position = poMainFormCenter LCLVersion = '2.1.0.0' @@ -15,25 +16,25 @@ object TwozProbForm: TTwozProbForm AnchorSideTop.Control = Bevel1 AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ResetBtn - Left = 57 + Left = 81 Height = 25 Top = 109 Width = 62 Anchors = [akTop, akRight] AutoSize = True - BorderSpacing.Left = 32 + BorderSpacing.Left = 8 BorderSpacing.Top = 8 BorderSpacing.Right = 12 Cancel = True Caption = 'Cancel' ModalResult = 2 - TabOrder = 0 + TabOrder = 1 end object ResetBtn: TButton AnchorSideTop.Control = Bevel1 AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ComputeBtn - Left = 131 + Left = 155 Height = 25 Top = 109 Width = 54 @@ -43,13 +44,13 @@ object TwozProbForm: TTwozProbForm BorderSpacing.Right = 12 Caption = 'Reset' OnClick = ResetBtnClick - TabOrder = 1 + TabOrder = 2 end object ComputeBtn: TButton AnchorSideTop.Control = Bevel1 AnchorSideTop.Side = asrBottom AnchorSideRight.Control = ReturnBtn - Left = 197 + Left = 221 Height = 25 Top = 109 Width = 76 @@ -59,25 +60,25 @@ object TwozProbForm: TTwozProbForm BorderSpacing.Right = 12 Caption = 'Compute' OnClick = ComputeBtnClick - TabOrder = 2 + TabOrder = 3 end object ReturnBtn: TButton AnchorSideTop.Control = Bevel1 AnchorSideTop.Side = asrBottom AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom - Left = 285 + Left = 309 Height = 25 Top = 109 Width = 61 Anchors = [akTop, akRight] AutoSize = True BorderSpacing.Top = 8 - BorderSpacing.Right = 32 + BorderSpacing.Right = 8 BorderSpacing.Bottom = 8 Caption = 'Return' ModalResult = 1 - TabOrder = 3 + TabOrder = 4 end object Bevel1: TBevel AnchorSideLeft.Control = Owner @@ -96,18 +97,18 @@ object TwozProbForm: TTwozProbForm AnchorSideLeft.Control = Owner AnchorSideLeft.Side = asrCenter AnchorSideTop.Control = Owner - Left = 74 + Left = 81 Height = 85 Top = 8 - Width = 231 + Width = 217 AutoSize = True BorderSpacing.Left = 8 BorderSpacing.Top = 8 BorderSpacing.Right = 8 BevelOuter = bvNone ClientHeight = 85 - ClientWidth = 231 - TabOrder = 4 + ClientWidth = 217 + TabOrder = 0 object Label1: TLabel AnchorSideLeft.Control = Panel1 AnchorSideTop.Control = Z1Edit @@ -115,15 +116,15 @@ object TwozProbForm: TTwozProbForm Left = 0 Height = 15 Top = 4 - Width = 155 - Caption = 'The probability between z1 = ' + Width = 141 + Caption = 'The probability between z1' ParentColor = False end object Z1Edit: TEdit AnchorSideLeft.Control = Label1 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 163 + Left = 149 Height = 23 Top = 0 Width = 68 @@ -137,12 +138,12 @@ object TwozProbForm: TTwozProbForm AnchorSideTop.Side = asrCenter AnchorSideRight.Control = Label1 AnchorSideRight.Side = asrBottom - Left = 107 + Left = 104 Height = 15 Top = 31 - Width = 48 + Width = 37 Anchors = [akTop, akRight] - Caption = 'and z2 = ' + Caption = 'and z2 ' ParentColor = False end object Z2Edit: TEdit @@ -151,7 +152,7 @@ object TwozProbForm: TTwozProbForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = Z1Edit AnchorSideRight.Side = asrBottom - Left = 163 + Left = 149 Height = 23 Top = 27 Width = 68 @@ -169,9 +170,9 @@ object TwozProbForm: TTwozProbForm Left = 84 Height = 15 Top = 66 - Width = 71 + Width = 57 Anchors = [akTop, akRight] - Caption = 'Probability = ' + Caption = 'Probability' ParentColor = False end object ProbEdit: TEdit @@ -180,7 +181,7 @@ object TwozProbForm: TTwozProbForm AnchorSideTop.Side = asrBottom AnchorSideRight.Control = Z1Edit AnchorSideRight.Side = asrBottom - Left = 163 + Left = 149 Height = 23 Top = 62 Width = 68 diff --git a/applications/lazstats/source/forms/simulations/twozprobunit.pas b/applications/lazstats/source/forms/simulations/twozprobunit.pas index e15d281a3..a82af24a2 100644 --- a/applications/lazstats/source/forms/simulations/twozprobunit.pas +++ b/applications/lazstats/source/forms/simulations/twozprobunit.pas @@ -6,8 +6,7 @@ interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, - StdCtrls, ExtCtrls, - FunctionsLib; + StdCtrls, ExtCtrls; type @@ -27,6 +26,7 @@ type Z1Edit: TEdit; Label1: TLabel; procedure ComputeBtnClick(Sender: TObject); + procedure FormActivate(Sender: TObject); procedure ResetBtnClick(Sender: TObject); private { private declarations } @@ -39,6 +39,11 @@ var implementation +{$R *.lfm} + +uses + Math, MathUnit, Utils; + { TTwozProbForm } procedure TTwozProbForm.ResetBtnClick(Sender: TObject); @@ -49,26 +54,37 @@ begin end; procedure TTwozProbForm.ComputeBtnClick(Sender: TObject); -VAR +var z1, z2, prob : double; - outvalue : string; begin - z1 := StrToFloat(Z1Edit.Text); - z2 := StrToFloat(Z2Edit.Text); - if z1 < z2 then - begin - prob := probz(z2) - probz(z1); - end; - if z1 > z2 then - begin - prob := probz(z1) - probz(z2); - end; - outvalue := format('%6.4f',[prob]); - ProbEdit.Text := outvalue; + if not MyTryStrToFloat(Z1Edit.Text, z1) then + begin + Z1Edit.SetFocus; + ErrorMsg('No valid number.'); + exit; + end; + + if not MyTryStrToFloat(Z2Edit.Text, z2) then + begin + Z2Edit.SetFocus; + ErrorMsg('No valid number.'); + exit; + end; + + prob := abs(NormalDist(z2) - NormalDist(z1)); + ProbEdit.Text := Format('%6.4f', [prob]); end; -initialization - {$I twozprobunit.lrs} +procedure TTwozProbForm.FormActivate(Sender: TObject); +var + w: Integer; +begin + w := MaxValue([CancelBtn.Width, ResetBtn.Width, ComputeBtn.Width, ReturnBtn.Width]); + CancelBtn.Constraints.MinWidth := w; + ResetBtn.Constraints.MinWidth := w; + ComputeBtn.Constraints.MinWidth := w; + ReturnBtn.Constraints.MinWidth := w; +end; end. diff --git a/applications/lazstats/source/units/mathunit.pas b/applications/lazstats/source/units/mathunit.pas index 6abdc1a60..25ef944a1 100644 --- a/applications/lazstats/source/units/mathunit.pas +++ b/applications/lazstats/source/units/mathunit.pas @@ -46,6 +46,7 @@ function FactorialLn(n: Integer): Double; function PoissonPDF(n: integer; a: double): Double; function PoissonCDF(n: Integer; a: double): Double; +function MyTryStrToFloat(S: String; out AValue: Double): Boolean; implementation @@ -569,6 +570,20 @@ begin end; +{ Converts a string to a floating point value. Checks for comma or point as + decimal separator } +function MyTryStrToFloat(S: String; out AValue: Double): Boolean; +var + fs: TFormatSettings; +begin + Result := TryStrToFloat(S, AValue); + if not Result then + begin + fs := FormatSettings; + if fs.DecimalSeparator = '.' then fs.DecimalSeparator := ',' else fs.DecimalSeparator := '.'; + Result := TryStrToFloat(S, AValue, fs); + end; +end; initialization InitFactLn(); diff --git a/applications/lazstats/source/units/utils.pas b/applications/lazstats/source/units/utils.pas index 7023d20d9..2380cb049 100644 --- a/applications/lazstats/source/units/utils.pas +++ b/applications/lazstats/source/units/utils.pas @@ -194,4 +194,3 @@ end; end. -