LazStats: Refactor GenSeqUnit. Add pdf to chm file.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7438 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-05-08 12:13:59 +00:00
parent d7dcf034cf
commit d7abee5099
4 changed files with 191 additions and 178 deletions

Binary file not shown.

View File

@@ -1,23 +1,27 @@
object GenSeqFrm: TGenSeqFrm object GenSeqFrm: TGenSeqFrm
Left = 390 Left = 390
Height = 192 Height = 231
Top = 114 Top = 114
Width = 367 Width = 367
AutoSize = True AutoSize = True
BorderStyle = bsDialog
Caption = 'Generation of Sequential Values' Caption = 'Generation of Sequential Values'
ClientHeight = 192 ClientHeight = 231
ClientWidth = 367 ClientWidth = 367
OnActivate = FormActivate
OnCreate = FormCreate OnCreate = FormCreate
OnShow = FormShow OnShow = FormShow
Position = poMainFormCenter Position = poMainFormCenter
LCLVersion = '2.1.0.0' LCLVersion = '2.1.0.0'
object Label1: TLabel object Label1: TLabel
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = StartAtEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2 AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 47 Left = 99
Height = 15 Height = 15
Top = 96 Top = 94
Width = 99 Width = 99
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
BorderSpacing.Left = 12 BorderSpacing.Left = 12
@@ -26,10 +30,12 @@ object GenSeqFrm: TGenSeqFrm
end end
object Label2: TLabel object Label2: TLabel
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = IncrEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = IncrEdit AnchorSideRight.Control = IncrEdit
Left = 34 Left = 86
Height = 15 Height = 15
Top = 127 Top = 125
Width = 112 Width = 112
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
BorderSpacing.Left = 12 BorderSpacing.Left = 12
@@ -39,11 +45,13 @@ object GenSeqFrm: TGenSeqFrm
end end
object Label3: TLabel object Label3: TLabel
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = LabelEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2 AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 41 Left = 93
Height = 15 Height = 15
Top = 160 Top = 156
Width = 105 Width = 105
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
BorderSpacing.Left = 12 BorderSpacing.Left = 12
@@ -52,11 +60,12 @@ object GenSeqFrm: TGenSeqFrm
end end
object RadioGroup1: TRadioGroup object RadioGroup1: TRadioGroup
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Owner AnchorSideTop.Control = Owner
Left = 8 Left = 71
Height = 74 Height = 74
Top = 8 Top = 8
Width = 236 Width = 225
AutoFill = False AutoFill = False
AutoSize = True AutoSize = True
BorderSpacing.Left = 8 BorderSpacing.Left = 8
@@ -69,30 +78,29 @@ object GenSeqFrm: TGenSeqFrm
ChildSizing.Layout = cclTopToBottomThenLeftToRight ChildSizing.Layout = cclTopToBottomThenLeftToRight
ChildSizing.ControlsPerLine = 2 ChildSizing.ControlsPerLine = 2
ClientHeight = 54 ClientHeight = 54
ClientWidth = 232 ClientWidth = 221
Items.Strings = ( Items.Strings = (
'All Current Cases' 'All Current Cases'
'Number of Cases = ' 'Number of Cases:'
) )
OnClick = RadioGroup1Click OnClick = RadioGroup1Click
TabOrder = 0 TabOrder = 0
object StaticText1: TStaticText object StaticText1: TStaticText
Left = 140 Left = 129
Height = 19 Height = 19
Top = 6 Top = 6
Width = 80 Width = 80
Caption = ' ' Caption = ' '
TabOrder = 2 TabOrder = 1
end end
object NoCasesEdit: TEdit object NoCasesEdit: TEdit
Left = 140 Left = 129
Height = 23 Height = 23
Top = 25 Top = 25
Width = 80 Width = 80
Alignment = taRightJustify Alignment = taRightJustify
BorderSpacing.Left = 3 BorderSpacing.Left = 3
OnExit = NoCasesEditExit TabOrder = 0
TabOrder = 3
Text = 'NoCasesEdit' Text = 'NoCasesEdit'
end end
end end
@@ -100,7 +108,7 @@ object GenSeqFrm: TGenSeqFrm
AnchorSideLeft.Control = LabelEdit AnchorSideLeft.Control = LabelEdit
AnchorSideTop.Control = RadioGroup1 AnchorSideTop.Control = RadioGroup1
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 154 Left = 206
Height = 23 Height = 23
Top = 90 Top = 90
Width = 78 Width = 78
@@ -113,7 +121,7 @@ object GenSeqFrm: TGenSeqFrm
AnchorSideLeft.Control = LabelEdit AnchorSideLeft.Control = LabelEdit
AnchorSideTop.Control = StartAtEdit AnchorSideTop.Control = StartAtEdit
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 154 Left = 206
Height = 23 Height = 23
Top = 121 Top = 121
Width = 78 Width = 78
@@ -127,100 +135,75 @@ object GenSeqFrm: TGenSeqFrm
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = RadioGroup1 AnchorSideRight.Control = RadioGroup1
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 154 Left = 206
Height = 23 Height = 23
Top = 152 Top = 152
Width = 78 Width = 78
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 12 BorderSpacing.Right = 12
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 4
TabOrder = 3 TabOrder = 3
Text = 'LabelEdit' Text = 'LabelEdit'
end end
object Panel1: TPanel object CloseBtn: TButton
AnchorSideLeft.Control = RadioGroup1 AnchorSideTop.Control = Bevel1
AnchorSideLeft.Side = asrBottom
AnchorSideBottom.Control = LabelEdit
AnchorSideBottom.Side = asrBottom
Left = 260
Height = 136
Top = 39
Width = 76
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Left = 16
BorderSpacing.Right = 8
BevelOuter = bvNone
ChildSizing.VerticalSpacing = 12
ClientHeight = 136
ClientWidth = 76
TabOrder = 4
object ResetBtn: TButton
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Panel1
AnchorSideRight.Control = Panel1
AnchorSideRight.Side = asrBottom
Left = 0
Height = 25
Top = 0
Width = 76
Anchors = [akTop, akLeft, akRight]
AutoSize = True
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 0
end
object CancelBtn: TButton
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = ResetBtn
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Panel1 AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 0 Left = 304
Height = 25 Height = 25
Top = 37 Top = 195
Width = 76 Width = 55
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
BorderSpacing.Top = 8 BorderSpacing.Top = 8
Caption = 'Cancel' BorderSpacing.Right = 8
ModalResult = 2 BorderSpacing.Bottom = 8
TabOrder = 1 Caption = 'Close'
ModalResult = 11
TabOrder = 4
end end
object ComputeBtn: TButton object ComputeBtn: TButton
AnchorSideLeft.Control = Panel1 AnchorSideTop.Control = CloseBtn
AnchorSideTop.Control = CancelBtn AnchorSideRight.Control = CloseBtn
AnchorSideTop.Side = asrBottom Left = 220
AnchorSideRight.Control = Panel1
AnchorSideRight.Side = asrBottom
Left = 0
Height = 25 Height = 25
Top = 74 Top = 195
Width = 76 Width = 76
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
BorderSpacing.Top = 8 BorderSpacing.Right = 8
Caption = 'Compute' Caption = 'Compute'
OnClick = ComputeBtnClick OnClick = ComputeBtnClick
TabOrder = 2 TabOrder = 5
end end
object ReturnBtn: TButton object ResetBtn: TButton
AnchorSideLeft.Control = Panel1 AnchorSideTop.Control = CloseBtn
AnchorSideTop.Control = ComputeBtn AnchorSideRight.Control = ComputeBtn
Left = 158
Height = 25
Top = 195
Width = 54
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Right = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 6
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = LabelEdit
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Panel1 AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 0 Left = 0
Height = 25 Height = 8
Top = 111 Top = 179
Width = 76 Width = 367
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
AutoSize = True Shape = bsBottomLine
BorderSpacing.Top = 8
Caption = 'Return'
ModalResult = 1
TabOrder = 3
end
end end
end end

View File

@@ -15,12 +15,11 @@ type
{ TGenSeqFrm } { TGenSeqFrm }
TGenSeqFrm = class(TForm) TGenSeqFrm = class(TForm)
Bevel1: TBevel;
NoCasesEdit: TEdit; NoCasesEdit: TEdit;
Panel1: TPanel;
ResetBtn: TButton; ResetBtn: TButton;
CancelBtn: TButton;
ComputeBtn: TButton; ComputeBtn: TButton;
ReturnBtn: TButton; CloseBtn: TButton;
LabelEdit: TEdit; LabelEdit: TEdit;
Label3: TLabel; Label3: TLabel;
StartAtEdit: TEdit; StartAtEdit: TEdit;
@@ -30,9 +29,9 @@ type
RadioGroup1: TRadioGroup; RadioGroup1: TRadioGroup;
StaticText1: TStaticText; StaticText1: TStaticText;
procedure ComputeBtnClick(Sender: TObject); procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
procedure NoCasesEditExit(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject); procedure RadioGroup1Click(Sender: TObject);
procedure ResetBtnClick(Sender: TObject); procedure ResetBtnClick(Sender: TObject);
private private
@@ -47,6 +46,9 @@ var
implementation implementation
uses
Math;
{ TGenSeqFrm } { TGenSeqFrm }
procedure TGenSeqFrm.ResetBtnClick(Sender: TObject); procedure TGenSeqFrm.ResetBtnClick(Sender: TObject);
@@ -68,27 +70,56 @@ var
i, col: integer; i, col: integer;
First, Increment: double; First, Increment: double;
begin begin
if StartAtEdit.Text = '' then if RadioGroup1.ItemIndex = 1 then begin
if NoCasesEdit.Text = '' then
begin begin
ShowMessage('Error! No starting value provided.'); NoCasesEdit.Setfocus;
MessageDlg('Number of cases to generate not specified.', mtError, [mbOK], 0);
exit; exit;
end; end;
if IncrEdit.Text = '' then if not TryStrToInt(NoCasesEdit.Text, NCases) or (NCases <= 0) then
begin begin
ShowMessage('Error! No increment value provided.'); NoCasesEdit.SetFocus;
MessageDlg('Number of cases must be a valid, positive integer.', mtError, [mbOK], 0);
exit; exit;
end; end;
end else
NCases := NoCases;
if (StartAtEdit.Text = '') or not TryStrToFloat(StartAtEdit.Text, First) then
begin
StartAtEdit.Setfocus;
MessageDlg('No starting value provided.', mtError, [mbOK], 0);
exit;
end;
if (IncrEdit.Text = '') then
begin
IncrEdit.SetFocus;
MessageDlg('No increment value provided.', mtError, [mbOK], 0);
exit;
end;
if not TryStrToFloat(IncrEdit.Text, Increment) or (Increment <= 0) then
begin
IncrEdit.SetFocus;
MessageDlg('No valid increment value provided.', mtError, [mbOK], 0);
exit;
end;
if LabelEdit.Text = '' then if LabelEdit.Text = '' then
begin begin
ShowMessage('Error! No variable label provided.'); LabelEdit.SetFocus;
MessageDlg('No variable label provided.', mtError, [mbOK], 0);
exit; exit;
end; end;
if NoCases < Ncases then if NoCases < Ncases then
begin begin
OS3MainFrm.DataGrid.RowCount := NCases + 1; OS3MainFrm.DataGrid.RowCount := NCases + 1;
OS3MainFrm.NoCasesEdit.Text := IntToStr(NCases); OS3MainFrm.NoCasesEdit.Text := IntToStr(NCases);
NoCases := Ncases; NoCases := Ncases;
end; end;
if NoVariables <= 0 then // a new data file if NoVariables <= 0 then // a new data file
begin begin
OS3MainFrm.DataGrid.ColCount := 2; OS3MainFrm.DataGrid.ColCount := 2;
@@ -103,7 +134,6 @@ begin
OS3MainFrm.DataGrid.Cells[1,0] := LabelEdit.Text; OS3MainFrm.DataGrid.Cells[1,0] := LabelEdit.Text;
DictionaryFrm.DictGrid.RowCount := 2; DictionaryFrm.DictGrid.RowCount := 2;
NoVariables := 1; NoVariables := 1;
end end
else // existing data file else // existing data file
begin begin
@@ -116,12 +146,22 @@ begin
Increment := StrToFloat(IncrEdit.Text); Increment := StrToFloat(IncrEdit.Text);
for i := 1 to Ncases do for i := 1 to Ncases do
begin begin
OS3MainFrm.DataGrid.Cells[col,i] := format('%8.3f',[First]); OS3MainFrm.DataGrid.Cells[col,i] := Format('%.3f', [First]);
First := First + Increment; First := First + Increment;
end; end;
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables); OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
end; end;
procedure TGenSeqFrm.FormActivate(Sender: TObject);
var
w: Integer;
begin
w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
ResetBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w;
end;
procedure TGenSeqFrm.FormCreate(Sender: TObject); procedure TGenSeqFrm.FormCreate(Sender: TObject);
begin begin
Assert(OS3MainFrm <> nil); Assert(OS3MainFrm <> nil);
@@ -129,28 +169,18 @@ begin
Application.CreateForm(TDictionaryFrm, DictionaryFrm); Application.CreateForm(TDictionaryFrm, DictionaryFrm);
end; end;
procedure TGenSeqFrm.NoCasesEditExit(Sender: TObject);
begin
if RadioGroup1.ItemIndex = 1 then Ncases := StrToInt(NoCasesEdit.Text);
if (Ncases <= 0) and (RadioGroup1.ItemIndex = 1) then
begin
ShowMessage('Error! No. of cases to generate not specified.');
exit;
end;
end;
procedure TGenSeqFrm.RadioGroup1Click(Sender: TObject); procedure TGenSeqFrm.RadioGroup1Click(Sender: TObject);
begin begin
if RadioGroup1.ItemIndex = 0 then if RadioGroup1.ItemIndex = 0 then
begin begin
if NoCases <= 0 then if NoCases <= 0 then
begin begin
ShowMessage('Error! There are currently no cases!'); MessageDlg('There are currently no cases.', mtError, [mbOK], 0);
exit; exit;
end end else
else Ncases := NoCases; Ncases := NoCases;
end end else
else NoCasesEdit.SetFocus; NoCasesEdit.SetFocus;
end; end;
initialization initialization