LazStats: Refactor GenRndValsUnit. Add its pdf to chm file.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7439 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-05-08 17:11:02 +00:00
parent d7abee5099
commit ea3f5e5f56
5 changed files with 467 additions and 249 deletions

Binary file not shown.

View File

@ -4,7 +4,7 @@ object GenRndValsFrm: TGenRndValsFrm
Top = 203
Width = 429
AutoSize = True
BorderStyle = bsSingle
BorderStyle = bsDialog
Caption = 'Generate Random Values'
ClientHeight = 349
ClientWidth = 429
@ -108,7 +108,8 @@ object GenRndValsFrm: TGenRndValsFrm
ClientHeight = 145
ClientWidth = 400
TabOrder = 2
object Label2: TLabel
object LowIntLabel: TLabel
Tag = 1
AnchorSideLeft.Control = rbFDistributionValues
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = rbFlatInteger
@ -121,10 +122,11 @@ object GenRndValsFrm: TGenRndValsFrm
Caption = 'Between '
ParentColor = False
end
object Label3: TLabel
AnchorSideLeft.Control = Label10
object AndIntLabel: TLabel
Tag = 1
AnchorSideLeft.Control = FDF2Label
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Label2
AnchorSideTop.Control = LowIntLabel
Left = 297
Height = 15
Top = 6
@ -135,9 +137,10 @@ object GenRndValsFrm: TGenRndValsFrm
ParentColor = False
end
object LowIntEdit: TEdit
AnchorSideLeft.Control = Label2
Tag = 1
AnchorSideLeft.Control = LowIntLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label2
AnchorSideTop.Control = LowIntLabel
AnchorSideTop.Side = asrCenter
Left = 228
Height = 23
@ -150,8 +153,9 @@ object GenRndValsFrm: TGenRndValsFrm
Text = 'LowIntEdit'
end
object HiIntEdit: TEdit
Tag = 1
AnchorSideLeft.Control = FDF2Edit
AnchorSideTop.Control = Label2
AnchorSideTop.Control = LowIntLabel
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = FDF2Edit
AnchorSideRight.Side = asrBottom
@ -178,19 +182,24 @@ object GenRndValsFrm: TGenRndValsFrm
OnChange = DistTypeChange
TabOrder = 0
end
object Label4: TLabel
AnchorSideLeft.Control = Label2
object LowRealLabel: TLabel
Tag = 2
AnchorSideLeft.Control = LowIntLabel
AnchorSideTop.Control = rbFlatFloatingPoint
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = LowRealEdit
Left = 168
Height = 15
Top = 33
Width = 48
Anchors = [akTop, akRight]
BorderSpacing.Right = 12
Caption = 'Between '
ParentColor = False
end
object Label5: TLabel
AnchorSideLeft.Control = Label10
object AndRealLabel: TLabel
Tag = 2
AnchorSideLeft.Control = FDF2Label
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = LowRealEdit
AnchorSideTop.Side = asrCenter
@ -202,8 +211,9 @@ object GenRndValsFrm: TGenRndValsFrm
ParentColor = False
end
object LowRealEdit: TEdit
Tag = 2
AnchorSideLeft.Control = LowIntEdit
AnchorSideTop.Control = Label4
AnchorSideTop.Control = LowRealLabel
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = LowIntEdit
AnchorSideRight.Side = asrBottom
@ -218,8 +228,9 @@ object GenRndValsFrm: TGenRndValsFrm
Text = 'LowRealEdit'
end
object HiRealEdit: TEdit
Tag = 2
AnchorSideLeft.Control = FDF2Edit
AnchorSideTop.Control = Label5
AnchorSideTop.Control = AndRealLabel
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = FDF2Edit
AnchorSideRight.Side = asrBottom
@ -260,31 +271,37 @@ object GenRndValsFrm: TGenRndValsFrm
OnChange = DistTypeChange
TabOrder = 6
end
object Label6: TLabel
AnchorSideLeft.Control = Label4
object MeanLabel: TLabel
Tag = 3
AnchorSideLeft.Control = LowRealLabel
AnchorSideTop.Control = rbNormalZValues
AnchorSideTop.Side = asrCenter
Left = 168
AnchorSideRight.Control = zMeanEdit
Left = 183
Height = 15
Top = 60
Width = 44
Caption = 'Mean = '
Width = 33
Anchors = [akTop, akRight]
BorderSpacing.Right = 12
Caption = 'Mean:'
ParentColor = False
end
object Label7: TLabel
AnchorSideLeft.Control = Label10
object SDLabel: TLabel
Tag = 3
AnchorSideLeft.Control = FDF2Label
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = rbNormalZValues
AnchorSideTop.Side = asrCenter
Left = 291
Left = 297
Height = 15
Top = 60
Width = 34
Width = 23
BorderSpacing.Left = 7
Caption = 'S.D. = '
Caption = 'S.D.:'
ParentColor = False
end
object zMeanEdit: TEdit
Tag = 3
AnchorSideLeft.Control = LowRealEdit
AnchorSideTop.Control = rbNormalZValues
AnchorSideTop.Side = asrCenter
@ -301,6 +318,7 @@ object GenRndValsFrm: TGenRndValsFrm
Text = 'zMeanEdit'
end
object zSDEdit: TEdit
Tag = 3
AnchorSideLeft.Control = FDF2Edit
AnchorSideTop.Control = rbNormalZValues
AnchorSideTop.Side = asrCenter
@ -329,18 +347,23 @@ object GenRndValsFrm: TGenRndValsFrm
OnChange = DistTypeChange
TabOrder = 9
end
object Label8: TLabel
AnchorSideLeft.Control = Label4
object ChiSqDFLabel: TLabel
Tag = 4
AnchorSideLeft.Control = LowRealLabel
AnchorSideTop.Control = rbChiSquaredValues
AnchorSideTop.Side = asrCenter
Left = 168
AnchorSideRight.Control = ChiDFEdit
Left = 190
Height = 15
Top = 87
Width = 40
Caption = 'D.F. 1 ='
Width = 26
Anchors = [akTop, akRight]
BorderSpacing.Right = 12
Caption = 'D.F. :'
ParentColor = False
end
object ChiDFEdit: TEdit
Tag = 4
AnchorSideLeft.Control = zMeanEdit
AnchorSideTop.Control = rbChiSquaredValues
AnchorSideTop.Side = asrCenter
@ -369,31 +392,37 @@ object GenRndValsFrm: TGenRndValsFrm
OnChange = DistTypeChange
TabOrder = 11
end
object Label9: TLabel
AnchorSideLeft.Control = Label8
object FDF1Label: TLabel
Tag = 5
AnchorSideLeft.Control = ChiSqDFLabel
AnchorSideTop.Control = rbFDistributionValues
AnchorSideTop.Side = asrCenter
Left = 168
AnchorSideRight.Control = FDF1Edit
Left = 184
Height = 15
Top = 114
Width = 40
Caption = 'D.F. 1 ='
Width = 32
Anchors = [akTop, akRight]
BorderSpacing.Right = 12
Caption = 'D.F. 1:'
ParentColor = False
end
object Label10: TLabel
object FDF2Label: TLabel
Tag = 5
AnchorSideLeft.Control = FDF1Edit
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = rbFDistributionValues
AnchorSideTop.Side = asrCenter
Left = 288
Left = 292
Height = 15
Top = 114
Width = 40
BorderSpacing.Left = 8
Caption = 'D.F. 2 ='
Width = 32
BorderSpacing.Left = 12
Caption = 'D.F. 2:'
ParentColor = False
end
object FDF1Edit: TEdit
Tag = 5
AnchorSideLeft.Control = ChiDFEdit
AnchorSideTop.Control = rbFDistributionValues
AnchorSideTop.Side = asrCenter
@ -410,7 +439,8 @@ object GenRndValsFrm: TGenRndValsFrm
Text = 'FDF1Edit'
end
object FDF2Edit: TEdit
AnchorSideLeft.Control = Label10
Tag = 5
AnchorSideLeft.Control = FDF2Label
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = rbFDistributionValues
AnchorSideTop.Side = asrCenter
@ -420,7 +450,7 @@ object GenRndValsFrm: TGenRndValsFrm
Top = 110
Width = 52
Alignment = taRightJustify
BorderSpacing.Left = 8
BorderSpacing.Left = 12
BorderSpacing.Right = 12
BorderSpacing.Bottom = 12
TabOrder = 13
@ -448,8 +478,8 @@ object GenRndValsFrm: TGenRndValsFrm
object ResetBtn: TButton
AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = CancelBtn
Left = 136
AnchorSideRight.Control = ComputeBtn
Left = 208
Height = 25
Top = 1
Width = 54
@ -460,27 +490,11 @@ object GenRndValsFrm: TGenRndValsFrm
OnClick = ResetBtnClick
TabOrder = 0
end
object CancelBtn: TButton
AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = ComputeBtn
Left = 198
Height = 25
Top = 1
Width = 62
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Right = 8
Cancel = True
Caption = 'Cancel'
ModalResult = 2
TabOrder = 1
end
object ComputeBtn: TButton
AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = ReturnBtn
Left = 268
AnchorSideRight.Control = CloseBtn
Left = 270
Height = 25
Top = 1
Width = 76
@ -489,22 +503,23 @@ object GenRndValsFrm: TGenRndValsFrm
BorderSpacing.Right = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 2
TabOrder = 1
end
object ReturnBtn: TButton
object CloseBtn: TButton
AnchorSideTop.Control = Panel1
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Panel1
AnchorSideRight.Side = asrBottom
Left = 352
Left = 354
Height = 25
Top = 1
Width = 61
Width = 55
Anchors = [akTop, akRight]
AutoSize = True
Caption = 'Return'
ModalResult = 1
TabOrder = 3
BorderSpacing.Right = 4
Caption = 'Close'
ModalResult = 11
TabOrder = 2
end
end
object Bevel1: TBevel

View File

@ -11,6 +11,8 @@ uses
type
TDistType = (dtUnknown, dtFlatInt, dtFlatReal, dtNormal, dtChiSq, dtF);
{ TGenRndValsFrm }
TGenRndValsFrm = class(TForm)
@ -25,27 +27,26 @@ type
rbFlatInteger: TRadioButton;
rbFlatFloatingPoint: TRadioButton;
ResetBtn: TButton;
CancelBtn: TButton;
ComputeBtn: TButton;
ReturnBtn: TButton;
CloseBtn: TButton;
ChiDFEdit: TEdit;
FDF2Edit: TEdit;
FDF1Edit: TEdit;
Label10: TLabel;
Label8: TLabel;
Label9: TLabel;
FDF2Label: TLabel;
ChiSqDFLabel: TLabel;
FDF1Label: TLabel;
zSDEdit: TEdit;
zMeanEdit: TEdit;
HiRealEdit: TEdit;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
AndRealLabel: TLabel;
MeanLabel: TLabel;
SDLabel: TLabel;
LowRealEdit: TEdit;
Label4: TLabel;
LowRealLabel: TLabel;
LowIntEdit: TEdit;
HiIntEdit: TEdit;
Label2: TLabel;
Label3: TLabel;
LowIntLabel: TLabel;
AndIntLabel: TLabel;
LabelEdit: TEdit;
Label1: TLabel;
RadioGroup1: TRadioGroup;
@ -62,8 +63,9 @@ type
procedure zMeanEditKeyPress(Sender: TObject; var Key: char);
private
{ private declarations }
Ncases : integer;
DistType : integer;
Ncases: integer;
DistType: TDistType;
function Validate(out AMsg: String; out AControl: TWinControl): boolean;
public
{ public declarations }
end;
@ -80,26 +82,29 @@ uses
procedure TGenRndValsFrm.RadioGroup1Click(Sender: TObject);
begin
if RadioGroup1.ItemIndex = 1 then
(*
if RadioGroup1.ItemIndex = 1 then
begin
if NoCases <= 0 then
begin
if NoCases <= 0 then
begin
ShowMessage('Error! There are currently no cases!');
exit;
end
else Ncases := NoCases
MessageDlg('There are currently no cases!', mtError, [mbOK], 0);
exit;
end
else NoCasesEdit.SetFocus;
else
Ncases := NoCases
end else
NoCasesEdit.SetFocus;
*)
end;
procedure TGenRndValsFrm.LowIntEditKeyPress(Sender: TObject; var Key: char);
begin
if Ord(Key) = 13 then HiIntEdit.SetFocus;
if Key = #13 then HiIntEdit.SetFocus;
end;
procedure TGenRndValsFrm.FDF1EditKeyPress(Sender: TObject; var Key: char);
begin
if Ord(Key) = 13 then FDF2Edit.SetFocus;
if Key = #13 then FDF2Edit.SetFocus;
end;
procedure TGenRndValsFrm.FormCreate(Sender: TObject);
@ -111,200 +116,398 @@ end;
procedure TGenRndValsFrm.ComputeBtnClick(Sender: TObject);
var
i, j : integer;
col : integer;
RndNo : integer;
RealRnd : double;
Range : integer;
MinReal, MaxReal : double;
Mean, StdDev : double;
SumX1, SumX2 : double;
df1, df2 : integer;
i, j : integer;
col : integer;
RndNo : integer;
RealRnd : double;
Range : integer;
MinReal, MaxReal : double;
Mean, StdDev : double;
SumX1, SumX2 : double;
df1, df2 : integer;
C: TWinControl;
msg: String;
begin
if LabelEdit.Text = '' then
begin
ShowMessage('Error. Enter a label for the variable.');
exit;
end;
if DistType <= 0 then
begin
ShowMessage('First, select a distribution type.');
exit;
end;
if RadioGroup1.ItemIndex < 0 then
begin
ShowMessage('Select an option for the number of values to generate.');
exit;
end;
if (RadioGroup1.ItemIndex = 1) and (NoCasesEdit.Text = '') then
begin
ShowMessage('Error! Number of cases not specified.');
exit;
end
else Ncases := StrToInt(NoCasesEdit.Text);
if not Validate(msg, C) then begin
C.SetFocus;
MessageDlg(msg, mtError, [mbOK], 0);
exit;
end;
if (RadioGroup1.ItemIndex = 1) then
if NoCases < Ncases then
begin
OS3MainFrm.DataGrid.RowCount := NCases + 1;
OS3MainFrm.NoCasesEdit.Text := IntToStr(NCases);
NoCases := Ncases;
OS3MainFrm.DataGrid.RowCount := NCases + 1;
OS3MainFrm.NoCasesEdit.Text := IntToStr(NCases);
NoCases := Ncases;
end;
DictionaryFrm.DictGrid.ColCount := 8;
if NoVariables <= 0 then // a new data file
begin
OS3MainFrm.DataGrid.ColCount := 2;
if NoCases <= 0 then
begin
MessageDlg('There are currently no cases.', mtError, [mbOK], 0);
exit;
end;
DictionaryFrm.DictGrid.ColCount := 8;
if NoVariables <= 0 then // a new data file
begin
OS3MainFrm.DataGrid.ColCount := 2;
for i := 1 to Ncases do
OS3MainFrm.DataGrid.Cells[0,i] := Format('Case %d',[i]);
col := 1;
DictionaryFrm.DictGrid.RowCount := 1;
DictionaryFrm.NewVar(col);
DictionaryFrm.DictGrid.Cells[1,col] := LabelEdit.Text;
OS3MainFrm.DataGrid.Cells[col,0] := LabelEdit.Text;
end
else // existing data file
begin
col := NoVariables + 1;
DictionaryFrm.NewVar(col);
DictionaryFrm.DictGrid.Cells[1,col] := LabelEdit.Text;
OS3MainFrm.DataGrid.Cells[col,0] := LabelEdit.Text;
end;
Randomize;
case DistType of
dtFlatInt:
begin // range of integers
Range := StrToInt(HiIntEdit.Text) - StrToInt(LowIntEdit.Text);
for i := 1 to Ncases do
OS3MainFrm.DataGrid.Cells[0,i] := format('Case %d',[i]);
col := 1;
DictionaryFrm.DictGrid.RowCount := 1;
DictionaryFrm.NewVar(col);
DictionaryFrm.DictGrid.Cells[1,col] := LabelEdit.Text;
OS3MainFrm.DataGrid.Cells[col,0] := LabelEdit.Text;
end
else // existing data file
begin
col := NoVariables + 1;
DictionaryFrm.NewVar(col);
DictionaryFrm.DictGrid.Cells[1,col] := LabelEdit.Text;
OS3MainFrm.DataGrid.Cells[col,0] := LabelEdit.Text;
end;
randomize;
case DistType of
1 : begin // range of integers
Range := StrToInt(HiIntEdit.Text) - StrToInt(LowIntEdit.Text);
for i := 1 to Ncases do
begin
RndNo := random(Range);
RndNo := RndNo + StrToInt(LowIntEdit.Text);
OS3MainFrm.DataGrid.Cells[col,i] := IntToStr(RndNo);
end;
begin
RndNo := random(Range);
RndNo := RndNo + StrToInt(LowIntEdit.Text);
OS3MainFrm.DataGrid.Cells[col,i] := IntToStr(RndNo);
end;
2 : begin // range of real random numbers
MinReal := StrToFloat(LowRealEdit.Text);
MaxReal := StrToFloat(HiRealEdit.Text);
Range := round(MaxReal - MinReal);
for i := 1 to Ncases do
begin
RealRnd := random;
RndNo := random(Range);
RealRnd := RndNo + RealRnd + MinReal;
OS3MainFrm.DataGrid.Cells[col,i] := format('%8.3f',[RealRnd]);
end;
end;
dtFlatReal:
begin // range of real random numbers
MinReal := StrToFloat(LowRealEdit.Text);
MaxReal := StrToFloat(HiRealEdit.Text);
Range := round(MaxReal - MinReal);
for i := 1 to Ncases do
begin
RealRnd := random;
RndNo := random(Range);
RealRnd := RndNo + RealRnd + MinReal;
OS3MainFrm.DataGrid.Cells[col,i] := format('%.3f',[RealRnd]);
end;
3 : begin // normally distributed z score
Mean := StrToFloat(zMeanEdit.Text);
StdDev := StrToFloat(zSDEdit.Text);
for i := 1 to Ncases do
begin
RealRnd := RandG(Mean,StdDev);
OS3MainFrm.DataGrid.Cells[col,i] := format('%8.3f',[RealRnd]);
end;
end;
dtNormal:
begin // normally distributed z score
Mean := StrToFloat(zMeanEdit.Text);
StdDev := StrToFloat(zSDEdit.Text);
for i := 1 to Ncases do
begin
RealRnd := RandG(Mean, StdDev);
OS3MainFrm.DataGrid.Cells[col,i] := format('%.3f',[RealRnd]);
end;
4 : begin // Chi square is a sum of df squared normally distributed z scores
df1 := StrToInt(ChiDFEdit.Text);
for i := 1 to Ncases do
begin
SumX1 := 0.0;
for j := 1 to df1 do
begin
RealRnd := RandG(0.0,1.0);
SumX1 := SumX1 + (RealRnd * RealRnd);
end;
OS3MainFrm.DataGrid.Cells[col,i] := format('%8.3f',[SumX1]);
end;
end;
dtChiSq:
begin // Chi square is a sum of df squared normally distributed z scores
df1 := StrToInt(ChiDFEdit.Text);
for i := 1 to Ncases do
begin
SumX1 := 0.0;
for j := 1 to df1 do
begin
RealRnd := RandG(0.0, 1.0);
SumX1 := SumX1 + sqr(RealRnd);
end;
OS3MainFrm.DataGrid.Cells[col,i] := format('%.3f', [SumX1]);
end;
5 : begin // F ratio is a ratio of two independent chi-squares
df1 := StrToInt(FDF1Edit.Text);
df2 := StrToInt(FDF2Edit.Text);
for i := 1 to Ncases do
begin
SumX1 := 0.0;
SumX2 := 0.0;
for j := 1 to df1 do
begin
RealRnd := RandG(0.0,1.0);
SumX1 := SumX1 + (RealRnd * RealRnd);
end;
for j := 1 to df2 do
begin
RealRnd := RandG(0.0,1.0);
SumX2 := SumX2 + (RealRnd * RealRnd);
end;
RealRnd := SumX1 / SumX2;
OS3MainFrm.DataGrid.Cells[col,i] := format('%8.3f',[RealRnd]);
end;
end;
dtF:
begin // F ratio is a ratio of two independent chi-squares
df1 := StrToInt(FDF1Edit.Text);
df2 := StrToInt(FDF2Edit.Text);
for i := 1 to Ncases do
begin
SumX1 := 0.0;
SumX2 := 0.0;
for j := 1 to df1 do
begin
RealRnd := RandG(0.0, 1.0);
SumX1 := SumX1 + sqr(RealRnd);
end;
for j := 1 to df2 do
begin
RealRnd := RandG(0.0, 1.0);
SumX2 := SumX2 + sqr(RealRnd);
end;
RealRnd := SumX1 / SumX2;
OS3MainFrm.DataGrid.Cells[col,i] := format('%.3f',[RealRnd]);
end;
end;
NoVariables := col;
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
OS3MainFrm.NoCasesEdit.Text := IntToStr(NoCases);
end;
end;
NoVariables := col;
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
OS3MainFrm.NoCasesEdit.Text := IntToStr(NoCases);
MessageDlg(Format('%d random cases added to grid.', [NCases]), mtInformation, [mbOK], 0);
end;
procedure TGenRndValsFrm.FormShow(Sender: TObject);
var
w: Integer;
w: Integer;
begin
w := MaxValue([ResetBtn.Width, CancelBtn.Width, ComputeBtn.Width, ReturnBtn.Width]);
ResetBtn.Constraints.MinWidth := w;
CancelBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
ReturnBtn.Constraints.MinWidth := w;
w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
ResetBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w;
ResetBtnClick(self);
ResetBtnClick(self);
end;
procedure TGenRndValsFrm.LowRealEditKeyPress(Sender: TObject; var Key: char);
begin
if Ord(Key) = 13 then HiRealEdit.SetFocus;
if Key = #13 then HiRealEdit.SetFocus;
end;
procedure TGenRndValsFrm.NoCasesEditExit(Sender: TObject);
begin
if RadioGroup1.ItemIndex = 1 then Ncases := StrToInt(NoCasesEdit.Text);
if RadioGroup1.ItemIndex = 1 then Ncases := StrToInt(NoCasesEdit.Text);
end;
procedure TGenRndValsFrm.DistTypeChange(Sender: TObject);
var
i: Integer;
selTag: Integer;
begin
DistType := (Sender as TRadioButton).Tag;
if (Sender = nil) then
begin
DistType := dtUnknown;
selTag := -1;
end else
begin
DistType := TDistType((Sender as TRadioButton).Tag);
selTag := (Sender as TRadioButton).Tag;
end;
for i := 0 to GroupBox1.ControlCount-1 do
if not (GroupBox1.Controls[i] is TRadioButton) then
GroupBox1.Controls[i].Enabled := GroupBox1.Controls[i].Tag = selTag;
case DistType of
1 : LowIntEdit.SetFocus;
2 : LowRealEdit.SetFocus;
3 : zMeanEdit.SetFocus;
4 : ChiDFEdit.SetFocus;
5 : FDF1Edit.SetFocus;
else
dtFlatInt:
LowIntEdit.SetFocus;
dtFlatReal:
LowRealEdit.SetFocus;
dtNormal:
zMeanEdit.SetFocus;
dtChiSq:
ChiDFEdit.SetFocus;
dtF:
FDF1Edit.SetFocus;
dtUnknown:
;
{
begin
ShowMessage('Please select a distribution type before pressing Compute.');
exit;
MessageDlg('Please select a distribution type before pressing Compute.', mtError, [mbOK], 0);
exit;
end;
}
else
raise Exception.Create('Unsupported distribution type.');
end;
end;
procedure TGenRndValsFrm.ResetBtnClick(Sender: TObject);
begin
NoCasesEdit.Text := '';
RadioGroup1.ItemIndex := -1;
rbFlatInteger.Checked := false;
rbFlatFloatingPoint.Checked := false;
rbNormalZValues.Checked := false;
rbChiSquaredValues.Checked := false;
rbFDistributionValues.Checked := false;
// RadioGroup2.ItemIndex := -1;
LabelEdit.Text := '';
LowIntEdit.Text := '';
HiIntEdit.Text := '';
LowRealEdit.Text := '';
HiRealEdit.Text := '';
zMeanEdit.Text := '';
zSDEdit.Text := '';
ChiDFEdit.Text := '';
FDF1Edit.Text := '';
FDF2Edit.Text := '';
DistType := 0;
NoCasesEdit.Text := '';
RadioGroup1.ItemIndex := -1;
rbFlatInteger.Checked := false;
rbFlatFloatingPoint.Checked := false;
rbNormalZValues.Checked := false;
rbChiSquaredValues.Checked := false;
rbFDistributionValues.Checked := false;
LabelEdit.Text := '';
LowIntEdit.Text := '';
HiIntEdit.Text := '';
LowRealEdit.Text := '';
HiRealEdit.Text := '';
zMeanEdit.Text := '';
zSDEdit.Text := '';
ChiDFEdit.Text := '';
FDF1Edit.Text := '';
FDF2Edit.Text := '';
DistType := dtUnknown;
DistTypeChange(nil);
end;
procedure TGenRndValsFrm.zMeanEditKeyPress(Sender: TObject; var Key: char);
begin
if Ord(Key) = 13 then zSDEdit.SetFocus;
if Key = #13 then zSDEdit.SetFocus;
end;
function TGenRndvalsFrm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
var
x: Double;
n: Integer;
begin
Result := false;
if LabelEdit.Text = '' then
begin
AControl := LabelEdit;
AMsg := 'Enter a label for the variable.';
exit;
end;
if RadioGroup1.ItemIndex < 0 then
begin
AControl := RadioGroup1;
AMsg := 'Select an option for the number of values to generate.';
exit;
end;
if (RadioGroup1.ItemIndex = 1) then
begin
if (NoCasesEdit.Text = '') then
begin
AControl := NoCasesEdit;
AMsg := 'Number of cases not specified.';
exit;
end;
if not TryStrToInt(NoCasesEdit.Text, NCases) or (NCases <= 0) then
begin
AControl := NoCasesEdit;
AMsg := 'Valid positive number required.';
exit;
end;
end;
case DistType of
dtUnknown:
begin
AControl := GroupBox1;
AMsg := 'Select a distribution type.';
exit;
end;
dtFlatInt:
begin
if (LowIntEdit.Text = '') or (HiIntEdit.Text = '') then
begin
if LowIntEdit.Text = '' then
AControl := LowIntEdit
else
AControl := HiIntEdit;
AMsg := 'Value required.';
exit;
end;
if not TryStrToInt(LowIntEdit.Text, n) then
begin
AControl := LowIntEdit;
AMsg := 'Valid integer number required.';
exit;
end;
if not TryStrToInt(HiIntEdit.Text, n) then
begin
AControl := HiIntEdit;
AMsg := 'Valid integer number required.';
exit;
end;
end;
dtFlatReal:
begin
if (LowRealEdit.Text = '') or (HiRealEdit.Text = '') then
begin
if LowRealEdit.Text = '' then
AControl := LowRealEdit
else
AControl := HiRealEdit;
AMsg := 'Value required.';
exit;
end;
if not TryStrToFloat(LowRealEdit.Text, x) then
begin
AControl := LowRealEdit;
AMsg := 'Valid number required.';
exit;
end;
if not TryStrToFloat(HiRealEdit.Text, x) then
begin
AControl := HiRealEdit;
AMsg := 'Valid number required.';
exit;
end;
end;
dtNormal:
begin
if (zMeanEdit.Text = '') or (zSDEdit.Text = '') then
begin
if zMeanEdit.Text = '' then
AControl := zMeanEdit
else
AControl := zSDEdit;
AMsg := 'Value required.';
exit;
end;
if not TryStrToFloat(zMeanEdit.Text, x) then
begin
AControl := zMeanEdit;
AMsg := 'Valid number required.';
exit;
end;
if not TryStrToFloat(zSDEdit.Text, x) or (x <= 0) then
begin
AControl := zSDEdit;
AMsg := 'Valid positive number required.';
exit;
end;
end;
dtChiSq:
begin
if (ChiDFEdit.Text = '') then
begin
AControl := ChiDFEdit;
AMsg := 'Value required.';
exit;
end;
if not TryStrToInt(ChiDFEdit.Text, n) or (n <= 0)then
begin
AControl := ChiDFEdit;
AMsg := 'Valid positive number required.';
exit;
end;
end;
dtF:
begin
if (FDF1Edit.Text = '') or (FDF2Edit.Text = '') then
begin
if (FDF1Edit.Text = '') then
AControl := FDF1Edit
else
AControl := FDF2Edit;
AMsg := 'Value required.';
exit;
end;
if not TryStrToInt(FDF1Edit.Text, n) or (n <= 0)then
begin
AControl := FDF1Edit;
AMsg := 'Valid positive number required.';
exit;
end;
if not TryStrToInt(FDF2Edit.Text, n) or (n <= 0)then
begin
AControl := FDF2Edit;
AMsg := 'Valid positive number required.';
exit;
end;
end;
end;
Result := true;
end;
initialization

View File

@ -91,7 +91,7 @@ object GenSeqFrm: TGenSeqFrm
Top = 6
Width = 80
Caption = ' '
TabOrder = 1
TabOrder = 0
end
object NoCasesEdit: TEdit
Left = 129
@ -100,7 +100,7 @@ object GenSeqFrm: TGenSeqFrm
Width = 80
Alignment = taRightJustify
BorderSpacing.Left = 3
TabOrder = 0
TabOrder = 1
Text = 'NoCasesEdit'
end
end
@ -162,7 +162,7 @@ object GenSeqFrm: TGenSeqFrm
BorderSpacing.Bottom = 8
Caption = 'Close'
ModalResult = 11
TabOrder = 4
TabOrder = 6
end
object ComputeBtn: TButton
AnchorSideTop.Control = CloseBtn
@ -191,7 +191,7 @@ object GenSeqFrm: TGenSeqFrm
BorderSpacing.Right = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 6
TabOrder = 4
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner