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 AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = LabelEdit AnchorSideRight.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 260 Left = 304
Height = 136 Height = 25
Top = 39 Top = 195
Width = 76 Width = 55
Anchors = [akLeft, akBottom] Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
BorderSpacing.Left = 16 BorderSpacing.Top = 8
BorderSpacing.Right = 8 BorderSpacing.Right = 8
BevelOuter = bvNone BorderSpacing.Bottom = 8
ChildSizing.VerticalSpacing = 12 Caption = 'Close'
ClientHeight = 136 ModalResult = 11
ClientWidth = 76
TabOrder = 4 TabOrder = 4
object ResetBtn: TButton end
AnchorSideLeft.Control = Panel1 object ComputeBtn: TButton
AnchorSideTop.Control = Panel1 AnchorSideTop.Control = CloseBtn
AnchorSideRight.Control = Panel1 AnchorSideRight.Control = CloseBtn
AnchorSideRight.Side = asrBottom Left = 220
Left = 0 Height = 25
Height = 25 Top = 195
Top = 0 Width = 76
Width = 76 Anchors = [akTop, akRight]
Anchors = [akTop, akLeft, akRight] AutoSize = True
AutoSize = True BorderSpacing.Right = 8
Caption = 'Reset' Caption = 'Compute'
OnClick = ResetBtnClick OnClick = ComputeBtnClick
TabOrder = 0 TabOrder = 5
end end
object CancelBtn: TButton object ResetBtn: TButton
AnchorSideLeft.Control = Panel1 AnchorSideTop.Control = CloseBtn
AnchorSideTop.Control = ResetBtn AnchorSideRight.Control = ComputeBtn
AnchorSideTop.Side = asrBottom Left = 158
AnchorSideRight.Control = Panel1 Height = 25
AnchorSideRight.Side = asrBottom Top = 195
Left = 0 Width = 54
Height = 25 Anchors = [akTop, akRight]
Top = 37 AutoSize = True
Width = 76 BorderSpacing.Left = 8
Anchors = [akTop, akLeft, akRight] BorderSpacing.Right = 8
AutoSize = True Caption = 'Reset'
BorderSpacing.Top = 8 OnClick = ResetBtnClick
Caption = 'Cancel' TabOrder = 6
ModalResult = 2 end
TabOrder = 1 object Bevel1: TBevel
end AnchorSideLeft.Control = Owner
object ComputeBtn: TButton AnchorSideTop.Control = LabelEdit
AnchorSideLeft.Control = Panel1 AnchorSideTop.Side = asrBottom
AnchorSideTop.Control = CancelBtn AnchorSideRight.Control = Owner
AnchorSideTop.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideRight.Control = Panel1 Left = 0
AnchorSideRight.Side = asrBottom Height = 8
Left = 0 Top = 179
Height = 25 Width = 367
Top = 74 Anchors = [akTop, akLeft, akRight]
Width = 76 Shape = bsBottomLine
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Top = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 2
end
object ReturnBtn: TButton
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = ComputeBtn
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Panel1
AnchorSideRight.Side = asrBottom
Left = 0
Height = 25
Top = 111
Width = 76
Anchors = [akTop, akLeft, akRight]
AutoSize = True
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,79 +46,120 @@ var
implementation implementation
uses
Math;
{ TGenSeqFrm } { TGenSeqFrm }
procedure TGenSeqFrm.ResetBtnClick(Sender: TObject); procedure TGenSeqFrm.ResetBtnClick(Sender: TObject);
begin begin
RadioGroup1.ItemIndex := 1; RadioGroup1.ItemIndex := 1;
NoCasesEdit.Text := ''; NoCasesEdit.Text := '';
StartAtEdit.Text := ''; StartAtEdit.Text := '';
IncrEdit.Text := ''; IncrEdit.Text := '';
LabelEdit.Text := ''; LabelEdit.Text := '';
end; end;
procedure TGenSeqFrm.FormShow(Sender: TObject); procedure TGenSeqFrm.FormShow(Sender: TObject);
begin begin
ResetBtnClick(self); ResetBtnClick(self);
end; end;
procedure TGenSeqFrm.ComputeBtnClick(Sender: TObject); procedure TGenSeqFrm.ComputeBtnClick(Sender: TObject);
var 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;
exit; MessageDlg('Number of cases to generate not specified.', mtError, [mbOK], 0);
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;
exit; MessageDlg('Number of cases must be a valid, positive integer.', mtError, [mbOK], 0);
exit;
end; end;
if LabelEdit.Text = '' then end else
begin NCases := NoCases;
ShowMessage('Error! No variable label provided.');
exit;
end;
if NoCases < Ncases then
begin
OS3MainFrm.DataGrid.RowCount := NCases + 1;
OS3MainFrm.NoCasesEdit.Text := IntToStr(NCases);
NoCases := Ncases;
end;
if NoVariables <= 0 then // a new data file
begin
OS3MainFrm.DataGrid.ColCount := 2;
OS3MainFrm.DataGrid.RowCount := Ncases + 1;
for i := 1 to Ncases do
OS3MainFrm.DataGrid.Cells[0,i] := format('Case %d',[i]);
col := 1;
DictionaryFrm.DictGrid.RowCount := 1;
DictionaryFrm.DictGrid.ColCount := 8;
DictionaryFrm.NewVar(col);
DictionaryFrm.DictGrid.Cells[1,col] := LabelEdit.Text;
OS3MainFrm.DataGrid.Cells[1,0] := LabelEdit.Text;
DictionaryFrm.DictGrid.RowCount := 2;
NoVariables := 1;
end if (StartAtEdit.Text = '') or not TryStrToFloat(StartAtEdit.Text, First) then
else // existing data file begin
begin StartAtEdit.Setfocus;
col := NoVariables + 1; MessageDlg('No starting value provided.', mtError, [mbOK], 0);
DictionaryFrm.NewVar(col); exit;
DictionaryFrm.DictGrid.Cells[1,col] := LabelEdit.Text; end;
end;
First := StrToFloat(StartAtEdit.Text); if (IncrEdit.Text = '') then
Increment := StrToFloat(IncrEdit.Text); 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
begin
LabelEdit.SetFocus;
MessageDlg('No variable label provided.', mtError, [mbOK], 0);
exit;
end;
if NoCases < Ncases then
begin
OS3MainFrm.DataGrid.RowCount := NCases + 1;
OS3MainFrm.NoCasesEdit.Text := IntToStr(NCases);
NoCases := Ncases;
end;
if NoVariables <= 0 then // a new data file
begin
OS3MainFrm.DataGrid.ColCount := 2;
OS3MainFrm.DataGrid.RowCount := Ncases + 1;
for i := 1 to Ncases do for i := 1 to Ncases do
begin OS3MainFrm.DataGrid.Cells[0,i] := format('Case %d',[i]);
OS3MainFrm.DataGrid.Cells[col,i] := format('%8.3f',[First]); col := 1;
First := First + Increment; DictionaryFrm.DictGrid.RowCount := 1;
end; DictionaryFrm.DictGrid.ColCount := 8;
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables); DictionaryFrm.NewVar(col);
DictionaryFrm.DictGrid.Cells[1,col] := LabelEdit.Text;
OS3MainFrm.DataGrid.Cells[1,0] := LabelEdit.Text;
DictionaryFrm.DictGrid.RowCount := 2;
NoVariables := 1;
end
else // existing data file
begin
col := NoVariables + 1;
DictionaryFrm.NewVar(col);
DictionaryFrm.DictGrid.Cells[1,col] := LabelEdit.Text;
end;
First := StrToFloat(StartAtEdit.Text);
Increment := StrToFloat(IncrEdit.Text);
for i := 1 to Ncases do
begin
OS3MainFrm.DataGrid.Cells[col,i] := Format('%.3f', [First]);
First := First + Increment;
end;
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
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; end;
procedure TGenSeqFrm.FormCreate(Sender: TObject); procedure TGenSeqFrm.FormCreate(Sender: TObject);
@@ -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
if NoCases <= 0 then
begin begin
if NoCases <= 0 then MessageDlg('There are currently no cases.', mtError, [mbOK], 0);
begin exit;
ShowMessage('Error! There are currently no cases!'); end else
exit; Ncases := NoCases;
end end else
else Ncases := NoCases; NoCasesEdit.SetFocus;
end
else NoCasesEdit.SetFocus;
end; end;
initialization initialization