lazstats: Refactor AutoCorUnit and related units. Add autocorr.laz test file (not available in OpenStat).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7429 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-05-04 22:35:23 +00:00
parent abb796c0b2
commit 30b6409bbd
18 changed files with 4721 additions and 1333 deletions

View File

@ -0,0 +1,413 @@
201
1
VAR
VARIABLE 1
5
F
3
99999
L
Case 0
VAR
Case 1
5.310
Case 2
5.267
Case 3
5.936
Case 4
6.032
Case 5
6.048
Case 6
6.188
Case 7
6.038
Case 8
6.344
Case 9
6.176
Case 10
5.780
Case 11
5.678
Case 12
5.843
Case 13
5.342
Case 14
5.373
Case 15
4.798
Case 16
4.622
Case 17
4.634
Case 18
4.267
Case 19
4.504
Case 20
4.424
Case 21
4.452
Case 22
4.597
Case 23
4.353
Case 24
4.671
Case 25
4.908
Case 26
5.095
Case 27
5.257
Case 28
5.558
Case 29
6.128
Case 30
6.144
Case 31
6.409
Case 32
6.453
Case 33
6.309
Case 34
5.981
Case 35
6.042
Case 36
5.932
Case 37
5.751
Case 38
5.196
Case 39
5.145
Case 40
4.971
Case 41
4.605
Case 42
4.381
Case 43
4.451
Case 44
4.055
Case 45
4.309
Case 46
4.369
Case 47
4.504
Case 48
4.506
Case 49
4.559
Case 50
5.049
Case 51
5.398
Case 52
5.608
Case 53
5.800
Case 54
5.969
Case 55
5.867
Case 56
6.154
Case 57
6.482
Case 58
6.322
Case 59
6.040
Case 60
5.911
Case 61
6.066
Case 62
5.908
Case 63
5.582
Case 64
4.985
Case 65
5.156
Case 66
4.549
Case 67
4.322
Case 68
4.140
Case 69
4.434
Case 70
4.338
Case 71
4.221
Case 72
4.578
Case 73
4.251
Case 74
4.788
Case 75
5.083
Case 76
5.303
Case 77
5.276
Case 78
5.581
Case 79
5.848
Case 80
5.998
Case 81
6.140
Case 82
5.992
Case 83
6.409
Case 84
6.418
Case 85
6.141
Case 86
5.908
Case 87
5.765
Case 88
5.354
Case 89
5.033
Case 90
5.083
Case 91
4.878
Case 92
4.467
Case 93
4.612
Case 94
4.471
Case 95
4.242
Case 96
4.446
Case 97
4.431
Case 98
4.566
Case 99
4.520
Case 100
4.705
Case 101
4.914
Case 102
5.541
Case 103
5.745
Case 104
5.667
Case 105
5.834
Case 106
6.185
Case 107
6.406
Case 108
6.450
Case 109
6.122
Case 110
5.892
Case 111
5.977
Case 112
5.928
Case 113
5.383
Case 114
5.450
Case 115
4.973
Case 116
4.682
Case 117
4.536
Case 118
4.454
Case 119
4.121
Case 120
4.398
Case 121
4.503
Case 122
4.348
Case 123
4.337
Case 124
4.801
Case 125
4.817
Case 126
5.178
Case 127
5.490
Case 128
5.407
Case 129
5.738
Case 130
6.070
Case 131
5.940
Case 132
6.188
Case 133
6.025
Case 134
6.315
Case 135
5.917
Case 136
6.080
Case 137
6.022
Case 138
5.508
Case 139
5.186
Case 140
5.293
Case 141
4.847
Case 142
4.838
Case 143
4.535
Case 144
4.166
Case 145
4.372
Case 146
4.137
Case 147
4.353
Case 148
4.280
Case 149
4.777
Case 150
5.013
Case 151
4.952
Case 152
5.371
Case 153
5.794
Case 154
5.607
Case 155
5.792
Case 156
5.889
Case 157
6.159
Case 158
6.239
Case 159
6.460
Case 160
6.363
Case 161
5.937
Case 162
5.828
Case 163
5.520
Case 164
5.447
Case 165
5.154
Case 166
4.690
Case 167
4.484
Case 168
4.556
Case 169
4.183
Case 170
4.373
Case 171
4.363
Case 172
4.084
Case 173
4.563
Case 174
4.707
Case 175
4.892
Case 176
5.194
Case 177
5.477
Case 178
5.350
Case 179
5.683
Case 180
6.034
Case 181
6.036
Case 182
6.386
Case 183
6.436
Case 184
6.004
Case 185
5.921
Case 186
6.016
Case 187
5.762
Case 188
5.481
Case 189
5.496
Case 190
5.102
Case 191
4.648
Case 192
4.600
Case 193
4.444
Case 194
4.411
Case 195
4.097
Case 196
4.492
Case 197
4.300
Case 198
4.326
Case 199
4.400
Case 200
4.879
Case 201
4.868

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
object AutoCorrFrm: TAutoCorrFrm object AutoCorrFrm: TAutoCorrFrm
Left = 456 Left = 456
Height = 459 Height = 459
Top = 163 Top = 145
Width = 684 Width = 684
AutoSize = True AutoSize = True
Caption = 'Autocorrelation' Caption = 'Autocorrelation'
@ -35,8 +35,10 @@ object AutoCorrFrm: TAutoCorrFrm
Width = 99 Width = 99
BorderSpacing.Left = 16 BorderSpacing.Left = 16
Caption = 'A Grid Column' Caption = 'A Grid Column'
Checked = True
OnClick = ColBtnClick OnClick = ColBtnClick
TabOrder = 0 TabOrder = 0
TabStop = True
end end
object RowBtn: TRadioButton object RowBtn: TRadioButton
AnchorSideLeft.Control = ColBtn AnchorSideLeft.Control = ColBtn
@ -138,86 +140,67 @@ object AutoCorrFrm: TAutoCorrFrm
end end
end end
object ResetBtn: TButton object ResetBtn: TButton
AnchorSideRight.Control = CancelBtn AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 387 Left = 475
Height = 25 Height = 25
Top = 426 Top = 426
Width = 54 Width = 54
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 8
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 12 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Reset' Caption = 'Reset'
OnClick = ResetBtnClick OnClick = ResetBtnClick
TabOrder = 5 TabOrder = 5
end end
object CancelBtn: TButton
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 453
Height = 25
Top = 426
Width = 62
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 12
BorderSpacing.Top = 8
BorderSpacing.Right = 12
BorderSpacing.Bottom = 8
Caption = 'Cancel'
ModalResult = 2
TabOrder = 6
end
object ComputeBtn: TButton object ComputeBtn: TButton
AnchorSideRight.Control = ReturnBtn AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 527 Left = 537
Height = 25 Height = 25
Top = 426 Top = 426
Width = 76 Width = 76
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 8
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 12 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Compute' Caption = 'Compute'
ModalResult = 1
OnClick = ComputeBtnClick OnClick = ComputeBtnClick
TabOrder = 7 TabOrder = 6
end end
object ReturnBtn: TButton object CloseBtn: TButton
AnchorSideRight.Control = Owner AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 615 Left = 621
Height = 25 Height = 25
Top = 426 Top = 426
Width = 61 Width = 55
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 8
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 8 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Return' Caption = 'Close'
ModalResult = 1 ModalResult = 11
OnClick = ReturnBtnClick OnClick = CloseBtnClick
TabOrder = 8 TabOrder = 7
end end
object HelpBtn: TButton object HelpBtn: TButton
Tag = 104 Tag = 104
AnchorSideRight.Control = ResetBtn AnchorSideRight.Control = ResetBtn
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 324 Left = 416
Height = 25 Height = 25
Top = 426 Top = 426
Width = 51 Width = 51
@ -225,7 +208,7 @@ object AutoCorrFrm: TAutoCorrFrm
AutoSize = True AutoSize = True
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 12 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Help' Caption = 'Help'
OnClick = HelpBtnClick OnClick = HelpBtnClick
@ -235,7 +218,7 @@ object AutoCorrFrm: TAutoCorrFrm
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideRight.Control = Owner AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ReturnBtn AnchorSideBottom.Control = CloseBtn
Left = 0 Left = 0
Height = 8 Height = 8
Top = 410 Top = 410
@ -383,6 +366,7 @@ object AutoCorrFrm: TAutoCorrFrm
BorderSpacing.Right = 8 BorderSpacing.Right = 8
Constraints.MinHeight = 220 Constraints.MinHeight = 220
ItemHeight = 0 ItemHeight = 0
OnSelectionChange = VarListSelectionChange
TabOrder = 0 TabOrder = 0
end end
object InBtn: TBitBtn object InBtn: TBitBtn
@ -500,6 +484,7 @@ object AutoCorrFrm: TAutoCorrFrm
Anchors = [akLeft, akRight, akBottom] Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Bottom = 12 BorderSpacing.Bottom = 12
ReadOnly = True
TabOrder = 3 TabOrder = 3
Text = 'DepVarEdit' Text = 'DepVarEdit'
end end
@ -659,31 +644,31 @@ object AutoCorrFrm: TAutoCorrFrm
Left = 12 Left = 12
Height = 19 Height = 19
Top = 6 Top = 6
Width = 142 Width = 148
Caption = 'Correlogram' Caption = 'Plot correlogram'
TabOrder = 0 TabOrder = 0
end end
object StatsChk: TCheckBox object StatsChk: TCheckBox
Left = 12 Left = 12
Height = 19 Height = 19
Top = 27 Top = 27
Width = 142 Width = 148
Caption = 'Statistics' Caption = 'Print statistics'
TabOrder = 1 TabOrder = 1
end end
object RMatChk: TCheckBox object RMatChk: TCheckBox
Left = 12 Left = 12
Height = 19 Height = 19
Top = 48 Top = 48
Width = 142 Width = 148
Caption = 'Print correlation Mat.' Caption = 'Print correlation matrix'
TabOrder = 2 TabOrder = 2
end end
object PartialsChk: TCheckBox object PartialsChk: TCheckBox
Left = 12 Left = 12
Height = 19 Height = 19
Top = 69 Top = 69
Width = 142 Width = 148
Caption = 'Partial autocorrelations' Caption = 'Partial autocorrelations'
TabOrder = 3 TabOrder = 3
end end
@ -691,16 +676,16 @@ object AutoCorrFrm: TAutoCorrFrm
Left = 12 Left = 12
Height = 19 Height = 19
Top = 90 Top = 90
Width = 142 Width = 148
Caption = 'Yule-Walker Coef.s' Caption = 'Yule-Walker coefficients'
TabOrder = 4 TabOrder = 4
end end
object ResidChk: TCheckBox object ResidChk: TCheckBox
Left = 12 Left = 12
Height = 19 Height = 19
Top = 111 Top = 111
Width = 142 Width = 148
Caption = 'Residual Plot' Caption = 'Residual plot'
TabOrder = 5 TabOrder = 5
end end
end end

View File

@ -51,168 +51,168 @@ procedure TAutoPlotFrm.FormShow(Sender: TObject);
begin begin
Image1.Canvas.Brush.Color := clWhite; Image1.Canvas.Brush.Color := clWhite;
Image1.Canvas.FillRect(0, 0, Image1.Width, Image1.Height); Image1.Canvas.FillRect(0, 0, Image1.Width, Image1.Height);
// AutoPlotFrm.Image1.Canvas.Clear;
AutoPlot(self); AutoPlot(self);
end; end;
procedure TAutoPlotFrm.PrintBtnClick(Sender: TObject); procedure TAutoPlotFrm.PrintBtnClick(Sender: TObject);
var r : Trect; var
R: Trect;
begin begin
with Printer do with Printer do
begin begin
Printer.Orientation := poPortrait; Orientation := poPortrait;
r := Rect(20,20,printer.pagewidth-20,printer.pageheight div 2 + 20); R := Rect(20,20, PageWidth-20, PageHeight div 2 + 20);
BeginDoc; BeginDoc;
Canvas.StretchDraw(r,Image1.Picture.BitMap); try
EndDoc; Canvas.StretchDraw(R, Image1.Picture.BitMap);
end; finally
EndDoc;
end;
end;
end; end;
procedure TAutoPlotFrm.AutoPlot(Sender: TObject); procedure TAutoPlotFrm.AutoPlot(Sender: TObject);
var var
topmarg, botmarg, leftmarg, rightmarg, verthi, horizlong : integer; topmarg, botmarg, leftmarg, rightmarg, verthi, horizlong: integer;
i, X, Y, middle, yincrement, xincrement, labelheight : integer; i, X, Y, middle, yincrement, xincrement, labelheight: integer;
labelstring : string; labelstring: string;
labelstr : string; corstep, yprop, scaley: double;
corstep, yprop, scaley : double;
begin begin
height := Image1.Canvas.Height; height := Image1.Canvas.Height;
width := Image1.Canvas.Width; width := Image1.Canvas.Width;
middle := height div 2; middle := height div 2;
topmarg := height div 10; topmarg := height div 10;
verthi := height - (2 * topmarg); verthi := height - 3 * topmarg;
botmarg := topmarg + verthi; botmarg := topmarg + verthi;
leftmarg := width div 10; leftmarg := width div 10;
horizlong := width - 2 * leftmarg; horizlong := width - 2 * leftmarg;
rightmarg := leftmarg + horizlong; rightmarg := leftmarg + horizlong;
yincrement := verthi div 20; yincrement := verthi div 20;
xincrement := horizlong div npoints; xincrement := horizlong div npoints;
// AutoPlotFrm.Show; Image1.Canvas.Pen.Color := clBlack;
Image1.Canvas.Pen.Color := clBlack; Image1.Canvas.Font.Color := clBlack;
// print title at top, centered // print title at top, centered
labelstring := 'Autocorrelations analysis for :'; labelstring := 'Autocorrelations analysis for ' + DepVarEdit;
labelstring := labelstring + DepVarEdit; X := leftmarg + (horizlong - Image1.Canvas.TextWidth(labelstring)) div 2;
X := (leftmarg + horizlong div 2) - (Image1.Canvas.TextWidth(labelstring) div 2); Y := 1;
Y := 1; Image1.Canvas.TextOut(X, Y, labelstring);
Image1.Canvas.TextOut(X,Y,labelstring);
// draw middle (zero correlation) axis // draw middle (zero correlation) axis
Y := middle; Image1.Canvas.Pen.Color := clBlack;
Image1.Canvas.MoveTo(leftmarg,Y); Image1.Canvas.Line(leftmarg, middle, rightmarg, middle);
X := rightmarg;
Image1.Canvas.LineTo(X,Y);
// draw right axis // draw left axis
X := leftmarg; Image1.Canvas.Pen.Color := clBlack;
Image1.Canvas.Line(leftmarg, topmarg, leftmarg, botmarg);
// correlation scale to left of vertical axis
corstep := 1.0;
for i := 0 to 20 do
begin
Y := topmarg + i * yincrement;
labelstring := Format('%4.2f -', [corstep]);
X := leftmarg - Image1.Canvas.TextWidth(labelstring);
Image1.Canvas.TextOut(X, Y, labelstring);
corstep := corstep - 0.1;
end;
// Make legend axis on bottom
Image1.Canvas.Pen.Color := clBlack;
Y := botmarg;
Image1.Canvas.Line(leftmarg, Y, rightmarg, Y);
Y := botmarg;
for i := 0 to npoints do
begin
X := leftmarg + xincrement * i;
labelstring := '|';
Image1.Canvas.TextOut(X, Y, labelstring);
labelstring := IntToStr(i);
Y := Y + 5;
if odd(i) then
Image1.Canvas.TextOut(X, Y, labelstring);
Y := botmarg; Y := botmarg;
Image1.Canvas.MoveTo(X,Y); end;
Y := topmarg;
Image1.Canvas.LineTo(X,Y);
// correlation scale to left of vertical axis labelstring := 'LAG VALUE';
corstep := 1.0; X := leftmarg + (horizlong - Image1.Canvas.TextWidth(labelstring) div 2);
for i := 0 to 20 do Y := botmarg + Image1.Canvas.TextHeight(labelstring) + 10;
begin Image1.Canvas.TextOut(X, Y, labelstring);
Y := topmarg + (i * yincrement);
labelstr := format('%4.2f -',[corstep]);
labelstring := labelstr;
X := leftmarg - Image1.Canvas.TextWidth(labelstring);
Image1.Canvas.TextOut(X,Y,labelstring);
corstep := corstep - 0.1;
end;
// Make legend axis on bottom // Plot lines from correlation to correlation
X := leftmarg; Image1.Canvas.Pen.Color := clRed;
Y := botmarg; for i := 0 to npoints - 1 do
Image1.Canvas.MoveTo(X,Y); begin
X := rightmarg; yprop := (1.0 - correlations[i]) / 2.0;
Image1.Canvas.LineTo(X,Y); scaley := yprop * verthi;
for i := 0 to npoints do X := leftmarg + round(xincrement * i);
begin Y := topmarg + round(scaley);
X := leftmarg + (xincrement * i); if (i = 0)then
labelstring := '|'; Image1.Canvas.MoveTo(X, Y)
Image1.Canvas.TextOut(X,Y,labelstring); else
labelstring := IntToStr(i); Image1.Canvas.LineTo(X, Y);
Y := Y + 5; Image1.Canvas.Ellipse(X-3, Y-3, X+3, Y+3);
if (i mod 2) = 1 then Image1.Canvas.TextOut(X,Y,labelstring); end;
Y := botmarg;
end;
labelstring := 'LAG VALUE';
X := (leftmarg + horizlong div 2) - (Image1.Canvas.TextWidth(labelstring) div 2);
Y := botmarg + Image1.Canvas.TextHeight(labelstring);
Image1.Canvas.TextOut(X,Y,labelstring);
// Plot lines from correlation to correlation // Plot partial correlations
Image1.Canvas.Pen.Color := clRed; if PlotPartCors then
begin
Image1.Canvas.Pen.Color := clBlue;
for i := 0 to npoints - 1 do for i := 0 to npoints - 1 do
begin begin
yprop := (1.0 - correlations[i]) / 2.0; yprop := (1.0 - partcors[i]) / 2.0;
scaley := yprop * verthi; scaley := yprop * verthi;
X := leftmarg + round(xincrement * i); X := leftmarg + round(xincrement * i);
Y := topmarg + round(scaley); Y := topmarg + round(scaley);
if (i = 0)then Image1.Canvas.MoveTo(X,Y) if (i = 0) then
else Canvas.LineTo(X,Y); Image1.Canvas.MoveTo(X,Y)
Image1.Canvas.Ellipse(X-3,Y-3,X+3,Y+3); else
Image1.Canvas.LineTo(X,Y);
Image1.Canvas.Ellipse(X-3, Y-3, X+3, Y+3);
end; end;
end;
// Plot partial correlations // Plot lines for upper and lower 95% confidence levels
if PlotPartCors then if PlotLimits then
begin begin
Image1.Canvas.Pen.Color := clBlue; Image1.Canvas.Pen.Color := clGreen;
for i := 0 to npoints - 1 do yprop := (1.0 - uplimit) / 2.0;
begin scaley := yprop * verthi;
yprop := (1.0 - partcors[i]) / 2.0; Y := topmarg + round(scaley);
scaley := yprop * verthi; Image1.Canvas.MoveTo(leftmarg,Y);
X := leftmarg + round(xincrement * i);
Y := topmarg + round(scaley);
if (i = 0) then Image1.Canvas.MoveTo(X,Y)
else Image1.Canvas.LineTo(X,Y);
Image1.Canvas.Ellipse(X-3,Y-3,X+3,Y+3);
end;
end;
// Plot lines for upper and lower 95% confidence levels
if PlotLimits then
begin
Image1.Canvas.Pen.Color := clGreen;
yprop := (1.0 - uplimit) / 2.0;
scaley := yprop * verthi;
Y := topmarg + round(scaley);
Image1.Canvas.MoveTo(leftmarg,Y);
X := rightmarg;
Image1.Canvas.LineTo(X,Y);
yprop := (1.0 - lowlimit) / 2.0;
scaley := yprop * verthi;
Y := topmarg + round(scaley);
Image1.Canvas.MoveTo(leftmarg,Y);
X := rightmarg;
Image1.Canvas.LineTo(X,Y);
end;
// Show legend at right
X := rightmarg; X := rightmarg;
labelstring := 'Correlations'; Image1.Canvas.LineTo(X, Y);
labelheight := Image1.Canvas.TextHeight(labelstring); yprop := (1.0 - lowlimit) / 2.0;
Y := 5 * labelheight; scaley := yprop * verthi;
Image1.Canvas.Font.Color := clRed; Y := topmarg + round(scaley);
Image1.Canvas.TextOut(X,Y,labelstring); Image1.Canvas.MoveTo(leftmarg, Y);
if PlotPartCors then X := rightmarg;
begin Image1.Canvas.LineTo(X,Y);
labelstring := 'Partials'; end;
Y := 6 * labelheight;
Image1.Canvas.Font.Color := clBlue; // Show legend at right
Image1.Canvas.TextOut(X,Y,labelstring); X := rightmarg;
end; labelstring := 'Correlations';
if PlotLimits then labelheight := Image1.Canvas.TextHeight(labelstring);
begin Y := 5 * labelheight;
Y := 7 * labelheight; Image1.Canvas.Font.Color := clRed;
labelstring := '95% C.I.'; Image1.Canvas.TextOut(X, Y, labelstring);
Image1.Canvas.Font.Color := clGreen; if PlotPartCors then
Image1.Canvas.TextOut(X,Y,labelstring); begin
end; labelstring := 'Partials';
Y := 6 * labelheight;
Image1.Canvas.Font.Color := clBlue;
Image1.Canvas.TextOut(X, Y, labelstring);
end;
if PlotLimits then
begin
Y := 7 * labelheight;
labelstring := '95% C.I.';
Image1.Canvas.Font.Color := clGreen;
Image1.Canvas.TextOut(X, Y, labelstring);
end;
end; end;
procedure TAutoPlotFrm.FormActivate(Sender: TObject); procedure TAutoPlotFrm.FormActivate(Sender: TObject);

View File

@ -2,29 +2,30 @@ object DifferenceFrm: TDifferenceFrm
Left = 611 Left = 611
Height = 115 Height = 115
Top = 292 Top = 292
Width = 318 Width = 308
AutoSize = True AutoSize = True
BorderStyle = bsDialog BorderStyle = bsDialog
Caption = 'Differencing Specification' Caption = 'Differencing Specification'
ClientHeight = 115 ClientHeight = 115
ClientWidth = 318 ClientWidth = 308
OnActivate = FormActivate OnActivate = FormActivate
OnShow = FormShow OnShow = FormShow
Position = poMainFormCenter Position = poMainFormCenter
LCLVersion = '2.1.0.0' LCLVersion = '2.1.0.0'
object CancelBtn: TButton object CancelBtn: TButton
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Bevel1 AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 128 AnchorSideRight.Control = OKBtn
Left = 188
Height = 25 Height = 25
Top = 78 Top = 78
Width = 62 Width = 62
Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 8
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 12 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Cancel' Caption = 'Cancel'
ModalResult = 2 ModalResult = 2
@ -35,16 +36,20 @@ object DifferenceFrm: TDifferenceFrm
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Bevel1 AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 202 AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 258
Height = 25 Height = 25
Top = 78 Top = 78
Width = 42 Width = 42
Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 16 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'OK' Caption = 'OK'
ModalResult = 1 ModalResult = 1
OnClick = OKBtnClick
TabOrder = 3 TabOrder = 3
end end
object HelpBtn: TButton object HelpBtn: TButton
@ -52,13 +57,13 @@ object DifferenceFrm: TDifferenceFrm
AnchorSideTop.Control = Bevel1 AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = CancelBtn AnchorSideRight.Control = CancelBtn
Left = 65 Left = 129
Height = 25 Height = 25
Top = 78 Top = 78
Width = 51 Width = 51
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
BorderSpacing.Left = 16 BorderSpacing.Left = 8
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Help' Caption = 'Help'
@ -69,14 +74,14 @@ object DifferenceFrm: TDifferenceFrm
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Owner AnchorSideTop.Control = Owner
Left = 68 Left = 63
Height = 50 Height = 50
Top = 8 Top = 8
Width = 183 Width = 183
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 24
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 12 BorderSpacing.Right = 24
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 50 ClientHeight = 50
ClientWidth = 183 ClientWidth = 183
@ -118,7 +123,7 @@ object DifferenceFrm: TDifferenceFrm
Alignment = taRightJustify Alignment = taRightJustify
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
TabOrder = 0 TabOrder = 0
Text = '1' Text = 'LagEdit'
end end
object OrderEdit: TEdit object OrderEdit: TEdit
AnchorSideTop.Control = LagEdit AnchorSideTop.Control = LagEdit
@ -133,7 +138,7 @@ object DifferenceFrm: TDifferenceFrm
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
BorderSpacing.Top = 4 BorderSpacing.Top = 4
TabOrder = 1 TabOrder = 1
Text = '1' Text = 'OrderEdit'
end end
end end
object Bevel1: TBevel object Bevel1: TBevel
@ -145,7 +150,7 @@ object DifferenceFrm: TDifferenceFrm
Left = 0 Left = 0
Height = 8 Height = 8
Top = 62 Top = 62
Width = 318 Width = 308
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4 BorderSpacing.Top = 4
Shape = bsBottomLine Shape = bsBottomLine

View File

@ -25,8 +25,10 @@ type
procedure FormActivate(Sender: TObject); procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
procedure HelpBtnClick(Sender: TObject); procedure HelpBtnClick(Sender: TObject);
procedure OKBtnClick(Sender: TObject);
private private
{ private declarations } { private declarations }
function Validate(out AMsg: String; out AControl: TWinControl): boolean;
public public
{ public declarations } { public declarations }
end; end;
@ -53,8 +55,8 @@ end;
procedure TDifferenceFrm.FormShow(Sender: TObject); procedure TDifferenceFrm.FormShow(Sender: TObject);
begin begin
LagEdit.Text := '1'; LagEdit.Text := '1';
OrderEdit.Text := '1'; OrderEdit.Text := '1';
end; end;
procedure TDifferenceFrm.HelpBtnClick(Sender: TObject); procedure TDifferenceFrm.HelpBtnClick(Sender: TObject);
@ -64,6 +66,54 @@ begin
ContextHelpForm.HelpMessage((Sender as TButton).tag); ContextHelpForm.HelpMessage((Sender as TButton).tag);
end; end;
procedure TDifferenceFrm.OKBtnClick(Sender: TObject);
var
msg: String;
C: TWinControl;
begin
if not Validate(msg, C) then
begin
C.SetFocus;
MessageDlg(msg, mtError, [mbOK], 0);
ModalResult := mrNone;
end;
end;
function TDifferenceFrm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
var
n: Integer;
begin
Result := false;
if LagEdit.Text = '' then
begin
AMsg := 'Input required.';
AControl := LagEdit;
exit;
end;
if not TryStrToInt(LagEdit.Text, n) or (n < 0) then
begin
AMsg := 'Non-negative integer value required.';
AControl := LagEdit;
exit;
end;
if OrderEdit.Text = '' then
begin
AMsg := 'Input required.';
AControl := OrderEdit;
exit;
end;
if not TryStrToInt(OrderEdit.Text, n) or (n < 0) then
begin
AMsg := 'Non-negative integer value required.';
AControl := OrderEdit;
exit;
end;
Result := true;
end;
initialization initialization
{$I differenceunit.lrs} {$I differenceunit.lrs}

View File

@ -9,27 +9,27 @@ object ExpSmoothFrm: TExpSmoothFrm
ClientHeight = 131 ClientHeight = 131
ClientWidth = 352 ClientWidth = 352
OnActivate = FormActivate OnActivate = FormActivate
OnShow = FormShow
Position = poMainFormCenter Position = poMainFormCenter
LCLVersion = '2.1.0.0' LCLVersion = '2.1.0.0'
object Label1: TLabel object Label1: TLabel
AnchorSideTop.Control = AlphaEdit AnchorSideTop.Control = AlphaEdit
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = AlphaEdit AnchorSideRight.Control = AlphaEdit
Left = 101 Left = 115
Height = 15 Height = 15
Top = 12 Top = 12
Width = 45 Width = 31
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
BorderSpacing.Left = 16
BorderSpacing.Right = 8 BorderSpacing.Right = 8
Caption = 'Alpha = ' Caption = 'Alpha'
ParentColor = False ParentColor = False
end end
object Label2: TLabel object Label2: TLabel
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = AlphaScroll
AnchorSideTop.Control = AlphaScroll AnchorSideTop.Control = AlphaScroll
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 8 Left = 24
Height = 15 Height = 15
Top = 66 Top = 66
Width = 15 Width = 15
@ -41,9 +41,9 @@ object ExpSmoothFrm: TExpSmoothFrm
object Label3: TLabel object Label3: TLabel
AnchorSideTop.Control = AlphaScroll AnchorSideTop.Control = AlphaScroll
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner AnchorSideRight.Control = AlphaScroll
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 329 Left = 313
Height = 15 Height = 15
Top = 66 Top = 66
Width = 15 Width = 15
@ -63,6 +63,7 @@ object ExpSmoothFrm: TExpSmoothFrm
Width = 44 Width = 44
Alignment = taRightJustify Alignment = taRightJustify
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 16
TabOrder = 0 TabOrder = 0
Text = '0.99' Text = '0.99'
end end
@ -72,17 +73,18 @@ object ExpSmoothFrm: TExpSmoothFrm
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 8 Left = 16
Height = 23 Height = 23
Top = 39 Top = 39
Width = 336 Width = 320
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 8 BorderSpacing.Left = 16
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 8 BorderSpacing.Right = 16
Max = 1 Max = 99
Min = 1
PageSize = 0 PageSize = 0
Position = 1 Position = 99
TabOrder = 1 TabOrder = 1
OnChange = AlphaScrollChange OnChange = AlphaScrollChange
end end
@ -90,12 +92,13 @@ object ExpSmoothFrm: TExpSmoothFrm
AnchorSideTop.Control = Bevel1 AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = OKBtn AnchorSideRight.Control = OKBtn
Left = 228 Left = 220
Height = 25 Height = 25
Top = 97 Top = 97
Width = 62 Width = 62
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
BorderSpacing.Left = 16
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 12 BorderSpacing.Right = 12
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
@ -108,17 +111,18 @@ object ExpSmoothFrm: TExpSmoothFrm
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 302 Left = 294
Height = 25 Height = 25
Top = 97 Top = 97
Width = 42 Width = 42
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
AutoSize = True AutoSize = True
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 8 BorderSpacing.Right = 16
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'OK' Caption = 'OK'
ModalResult = 1 ModalResult = 1
OnClick = OKBtnClick
TabOrder = 3 TabOrder = 3
end end
object Bevel1: TBevel object Bevel1: TBevel

View File

@ -23,12 +23,14 @@ type
AlphaScroll: TScrollBar; AlphaScroll: TScrollBar;
procedure AlphaScrollChange(Sender: TObject); procedure AlphaScrollChange(Sender: TObject);
procedure FormActivate(Sender: TObject); procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject); procedure OKBtnClick(Sender: TObject);
private private
{ private declarations } { private declarations }
FAlpha: Double;
procedure SetAlpha(AValue: Double);
public public
{ public declarations } { public declarations }
alpha : double; property Alpha: Double read FAlpha write SetAlpha;
end; end;
var var
@ -47,17 +49,34 @@ begin
CancelBtn.Constraints.MinWidth := OKBtn.Constraints.MinWidth; CancelBtn.Constraints.MinWidth := OKBtn.Constraints.MinWidth;
end; end;
procedure TExpSmoothFrm.FormShow(Sender: TObject); procedure TExpSmoothFrm.OKBtnClick(Sender: TObject);
begin begin
AlphaEdit.Text := '0.99'; if AlphaEdit.Text = '' then
AlphaScroll.Position := 99; begin
alpha := 0.99; AlphaEdit.SetFocus;
MessageDlg('Alpha cannot be empty.', mtError, [mbOK], 0);
ModalResult := mrNone;
end else
if not TryStrToFloat(AlphaEdit.Text, FAlpha) or (FAlpha < 0.0) or (FAlpha > 1.0) then
begin
AlphaEdit.SetFocus;
MessageDlg('Alpha must be > 0 and < 1', mtError, [mbOK], 0);
ModalResult := mrNone;
end;
end;
procedure TExpSmoothFrm.SetAlpha(AValue: Double);
begin
if (AValue = FAlpha) then exit;
FAlpha := AValue;
AlphaScroll.Position := Round(100 * FAlpha);
AlphaEdit.Text := FormatFloat('0.00', FAlpha);
end; end;
procedure TExpSmoothFrm.AlphaScrollChange(Sender: TObject); procedure TExpSmoothFrm.AlphaScrollChange(Sender: TObject);
begin begin
AlphaEdit.Text := FloatToStr(AlphaScroll.Position / 100.0); FAlpha := AlphaScroll.Position / 100.0;
alpha := AlphaScroll.Position / 100.0; AlphaEdit.Text := FormatFloat('0.00', FAlpha);
end; end;

View File

@ -2,11 +2,11 @@ object FFTFrm: TFFTFrm
Left = 648 Left = 648
Height = 127 Height = 127
Top = 346 Top = 346
Width = 305 Width = 224
BorderStyle = bsDialog BorderStyle = bsDialog
Caption = 'Fourier Transform Form' Caption = 'Fourier Transform Form'
ClientHeight = 127 ClientHeight = 127
ClientWidth = 305 ClientWidth = 224
OnActivate = FormActivate OnActivate = FormActivate
Position = poMainFormCenter Position = poMainFormCenter
LCLVersion = '2.1.0.0' LCLVersion = '2.1.0.0'
@ -14,7 +14,7 @@ object FFTFrm: TFFTFrm
AnchorSideTop.Control = Bevel1 AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = OKBtn AnchorSideRight.Control = OKBtn
Left = 177 Left = 96
Height = 25 Height = 25
Top = 93 Top = 93
Width = 62 Width = 62
@ -32,7 +32,7 @@ object FFTFrm: TFFTFrm
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 251 Left = 170
Height = 25 Height = 25
Top = 93 Top = 93
Width = 42 Width = 42
@ -43,6 +43,7 @@ object FFTFrm: TFFTFrm
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'OK' Caption = 'OK'
ModalResult = 1 ModalResult = 1
OnClick = OKBtnClick
TabOrder = 2 TabOrder = 2
end end
object Memo1: TLabel object Memo1: TLabel
@ -53,7 +54,7 @@ object FFTFrm: TFFTFrm
Left = 8 Left = 8
Height = 30 Height = 30
Top = 8 Top = 8
Width = 289 Width = 208
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Top = 8 BorderSpacing.Top = 8
@ -64,17 +65,16 @@ object FFTFrm: TFFTFrm
end end
object Panel1: TPanel object Panel1: TPanel
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Memo1 AnchorSideTop.Control = Memo1
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 66 Left = 24
Height = 23 Height = 23
Top = 50 Top = 50
Width = 172 Width = 172
AutoSize = True AutoSize = True
BorderSpacing.Left = 64 BorderSpacing.Left = 24
BorderSpacing.Top = 12 BorderSpacing.Top = 12
BorderSpacing.Right = 64 BorderSpacing.Right = 24
BorderSpacing.Bottom = 4 BorderSpacing.Bottom = 4
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 23 ClientHeight = 23
@ -115,7 +115,7 @@ object FFTFrm: TFFTFrm
Left = 0 Left = 0
Height = 8 Height = 8
Top = 77 Top = 77
Width = 305 Width = 224
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
Shape = bsBottomLine Shape = bsBottomLine
end end

View File

@ -21,6 +21,7 @@ type
Label1: TLabel; Label1: TLabel;
Panel1: TPanel; Panel1: TPanel;
procedure FormActivate(Sender: TObject); procedure FormActivate(Sender: TObject);
procedure OKBtnClick(Sender: TObject);
private private
{ private declarations } { private declarations }
public public
@ -46,6 +47,24 @@ begin
OKBtn.Constraints.MinWidth := w; OKBtn.Constraints.MinWidth := w;
end; end;
procedure TFFTFrm.OKBtnClick(Sender: TObject);
var
n: Integer;
begin
if NptsEdit.Text = '' then
begin
NptsEdit.SetFocus;
MessageDlg('Number of points not specified.', mtError, [mbOK], 0);
ModalResult := mrNone;
end else
if not TryStrToInt(NptsEdit.Text, n) or (n <= 0) then
begin
NptsEdit.SetFocus;
MessageDlg('Number of points must be a valid and positive integer.', mtError, [mbOK], 0);
ModalResult := mrNone;
end;
end;
initialization initialization
{$I fftunit.lrs} {$I fftunit.lrs}

View File

@ -1,11 +1,12 @@
object MoveAvgFrm: TMoveAvgFrm object MoveAvgFrm: TMoveAvgFrm
Left = 434 Left = 434
Height = 307 Height = 292
Top = 163 Top = 163
Width = 372 Width = 372
Caption = 'Moving Average Specification Form' Caption = 'Moving Average Specification Form'
ClientHeight = 307 ClientHeight = 292
ClientWidth = 372 ClientWidth = 372
OnActivate = FormActivate
OnShow = FormShow OnShow = FormShow
Position = poMainFormCenter Position = poMainFormCenter
LCLVersion = '2.1.0.0' LCLVersion = '2.1.0.0'
@ -43,7 +44,7 @@ object MoveAvgFrm: TMoveAvgFrm
Top = 13 Top = 13
Width = 118 Width = 118
Alignment = taRightJustify Alignment = taRightJustify
OnKeyPress = OrderEditKeyPress OnEditingDone = OrderEditEditingDone
TabOrder = 0 TabOrder = 0
Text = 'OrderEdit' Text = 'OrderEdit'
end end
@ -58,19 +59,18 @@ object MoveAvgFrm: TMoveAvgFrm
Width = 118 Width = 118
Alignment = taRightJustify Alignment = taRightJustify
BorderSpacing.Left = 8 BorderSpacing.Left = 8
OnKeyPress = ThetaEditKeyPress
TabOrder = 1 TabOrder = 1
Text = 'ThetaEdit' Text = 'ThetaEdit'
end end
object ThetaList: TListBox object ThetaList: TListBox
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideRight.Control = Panel1 AnchorSideRight.Control = Owner
AnchorSideBottom.Control = Owner AnchorSideRight.Side = asrBottom
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Control = OKBtn
Left = 8 Left = 8
Height = 219 Height = 171
Top = 80 Top = 80
Width = 286 Width = 356
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Right = 8 BorderSpacing.Right = 8
@ -79,76 +79,79 @@ object MoveAvgFrm: TMoveAvgFrm
OnClick = ThetaListClick OnClick = ThetaListClick
TabOrder = 2 TabOrder = 2
end end
object Panel1: TPanel object OKBtn: TButton
AnchorSideRight.Control = Owner AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 302 Left = 322
Height = 157 Height = 25
Top = 142 Top = 259
Width = 62 Width = 42
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Top = 8
BorderSpacing.Right = 8 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
BevelOuter = bvNone Caption = 'OK'
ChildSizing.VerticalSpacing = 8 ModalResult = 1
ChildSizing.Layout = cclLeftToRightThenTopToBottom OnClick = OKBtnClick
ClientHeight = 157
ClientWidth = 62
TabOrder = 3 TabOrder = 3
object HelpBtn: TButton end
Tag = 132 object CancelBtn: TButton
Left = 0 AnchorSideTop.Control = OKBtn
Height = 25 AnchorSideRight.Control = OKBtn
Top = 0 Left = 252
Width = 62 Height = 25
AutoSize = True Top = 259
Caption = 'Help' Width = 62
OnClick = HelpBtnClick Anchors = [akTop, akRight]
TabOrder = 0 AutoSize = True
end BorderSpacing.Right = 8
object ResetBtn: TButton Caption = 'Cancel'
Left = 0 ModalResult = 2
Height = 25 TabOrder = 4
Top = 33 end
Width = 62 object ApplyBtn: TButton
AutoSize = True AnchorSideTop.Control = OKBtn
Caption = 'Reset' AnchorSideRight.Control = CancelBtn
OnClick = ResetBtnClick Left = 187
TabOrder = 1 Height = 25
end Top = 259
object CancelBtn: TButton Width = 57
Left = 0 Anchors = [akTop, akRight]
Height = 25 AutoSize = True
Top = 66 BorderSpacing.Right = 8
Width = 62 Caption = 'Apply'
AutoSize = True OnClick = ApplyBtnClick
Caption = 'Cancel' TabOrder = 5
ModalResult = 2 end
TabOrder = 2 object ResetBtn: TButton
end AnchorSideTop.Control = OKBtn
object ApplyBtn: TButton AnchorSideRight.Control = ApplyBtn
Left = 0 Left = 125
Height = 25 Height = 25
Top = 99 Top = 259
Width = 62 Width = 54
AutoSize = True Anchors = [akTop, akRight]
Caption = 'Apply' AutoSize = True
OnClick = ApplyBtnClick BorderSpacing.Right = 8
TabOrder = 3 Caption = 'Reset'
end OnClick = ResetBtnClick
object OKBtn: TButton TabOrder = 6
Left = 0 end
Height = 25 object HelpBtn: TButton
Top = 132 Tag = 132
Width = 62 AnchorSideTop.Control = OKBtn
AutoSize = True AnchorSideRight.Control = ResetBtn
Caption = 'OK' Left = 66
ModalResult = 1 Height = 25
TabOrder = 4 Top = 259
end Width = 51
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Right = 8
Caption = 'Help'
OnClick = HelpBtnClick
TabOrder = 7
end end
end end

View File

@ -15,7 +15,6 @@ type
TMoveAvgFrm = class(TForm) TMoveAvgFrm = class(TForm)
HelpBtn: TButton; HelpBtn: TButton;
Panel1: TPanel;
ResetBtn: TButton; ResetBtn: TButton;
CancelBtn: TButton; CancelBtn: TButton;
ApplyBtn: TButton; ApplyBtn: TButton;
@ -26,17 +25,20 @@ type
OrderEdit: TEdit; OrderEdit: TEdit;
Label1: TLabel; Label1: TLabel;
procedure ApplyBtnClick(Sender: TObject); procedure ApplyBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
procedure HelpBtnClick(Sender: TObject); procedure HelpBtnClick(Sender: TObject);
procedure OrderEditKeyPress(Sender: TObject; var Key: char); procedure OKBtnClick(Sender: TObject);
procedure OrderEditEditingDone(Sender: TObject);
procedure ResetBtnClick(Sender: TObject); procedure ResetBtnClick(Sender: TObject);
procedure ThetaEditKeyPress(Sender: TObject; var Key: char); procedure ThetaEditEditingDone(Sender: TObject);
procedure ThetaListClick(Sender: TObject); procedure ThetaListClick(Sender: TObject);
private private
{ private declarations } { private declarations }
function Validate(out AMsg: String; out AControl: TWinControl): Boolean;
public public
{ public declarations } { public declarations }
W : array[0..20] of double; W: array[0..20] of double;
order : integer; order : integer;
currentindex : integer; currentindex : integer;
@ -47,42 +49,59 @@ var
implementation implementation
uses
Math;
{ TMoveAvgFrm } { TMoveAvgFrm }
procedure TMoveAvgFrm.ResetBtnClick(Sender: TObject); procedure TMoveAvgFrm.ResetBtnClick(Sender: TObject);
VAR i : integer; var
i: integer;
begin begin
OrderEdit.Text := ''; OrderEdit.Text := '';
ThetaEdit.Text := ''; ThetaEdit.Text := '';
ThetaList.Clear; ThetaList.Clear;
currentindex := 0; CurrentIndex := 0;
for i := 0 to 20 do W[i] := 1.0; for i := 0 to 20 do W[i] := 1.0;
end; end;
procedure TMoveAvgFrm.ThetaEditEditingDone(Sender: TObject);
var
cellString: String;
begin
if CurrentIndex < 1 then
exit;
cellString := Format('Theta(%d) = %s', [currentIndex + 1, ThetaEdit.Text]);
ThetaList.Items[CurrentIndex] := cellString;
W[currentIndex + 1] := StrToFloat(ThetaEdit.Text);
end;
(*
procedure TMoveAvgFrm.ThetaEditKeyPress(Sender: TObject; var Key: char); procedure TMoveAvgFrm.ThetaEditKeyPress(Sender: TObject; var Key: char);
var cellstring : string; var
cellstring: string;
begin begin
if currentindex < 1 then exit; if currentindex < 1 then exit;
if ord(Key) <> 13 then exit; if ord(Key) <> 13 then exit;
cellstring := 'Theta(' + IntToStr(currentindex + 1) + ') = '; cellstring := 'Theta(' + IntToStr(currentindex + 1) + ') = ' + ThetaEdit.Text;
cellstring := cellstring + ThetaEdit.Text; W[currentindex + 1] := StrToFloat(ThetaEdit.Text);
W[currentindex + 1] := StrToFloat(ThetaEdit.Text); end; *)
end;
procedure TMoveAvgFrm.ThetaListClick(Sender: TObject); procedure TMoveAvgFrm.ThetaListClick(Sender: TObject);
VAR index : integer; var
index: integer;
begin begin
index := ThetaList.ItemIndex; index := ThetaList.ItemIndex;
if index < 0 then exit; if index >= 0 then
begin
currentindex := index; currentindex := index;
ThetaEdit.Text := '1.0'; ThetaEdit.Text := '1.0';
ThetaEdit.SetFocus; ThetaEdit.SetFocus;
end;
end; end;
procedure TMoveAvgFrm.FormShow(Sender: TObject); procedure TMoveAvgFrm.FormShow(Sender: TObject);
begin begin
ResetBtnClick(self); ResetBtnClick(self);
end; end;
procedure TMoveAvgFrm.HelpBtnClick(Sender: TObject); procedure TMoveAvgFrm.HelpBtnClick(Sender: TObject);
@ -92,38 +111,108 @@ begin
ContextHelpForm.HelpMessage((Sender as TButton).tag); ContextHelpForm.HelpMessage((Sender as TButton).tag);
end; end;
procedure TMoveAvgFrm.ApplyBtnClick(Sender: TObject); procedure TMoveAvgFrm.OKBtnClick(Sender: TObject);
var var
sum : double; msg: String;
i : integer; C: TWinControl;
cellstring : string;
begin begin
ThetaList.Clear; if not Validate(msg, C) then
sum := W[0]; begin
for i := 1 to order do sum := sum + (2.0 * W[i]); C.SetFocus;
for i := 0 to order do MessageDlg(msg, mtError, [mbOK], 0);
begin ModalResult := mrNone;
W[i] := W[i] / sum; end;
cellstring := 'Theta(' + IntToStr(i+1) + ') = ';
cellstring := cellstring + FloatToStr(W[i]);
ThetaList.Items.Add(cellstring);
end;
end; end;
procedure TMoveAvgFrm.OrderEditKeyPress(Sender: TObject; var Key: char); procedure TMoveAvgFrm.ApplyBtnClick(Sender: TObject);
VAR cellstring : string; var
i : integer; sum: double;
i: integer;
cellstring: string;
begin begin
if ord(Key) <> 13 then exit; ThetaList.Clear;
sum := W[0];
for i := 1 to order do
sum := sum + 2.0 * W[i];
for i := 0 to order do
begin
W[i] := W[i] / sum;
cellstring := 'Theta(' + IntToStr(i+1) + ') = ' + FloatToStr(W[i]);
ThetaList.Items.Add(cellstring);
end;
end;
procedure TMoveAvgFrm.FormActivate(Sender: TObject);
var
wid: Integer;
begin
wid := MaxValue([HelpBtn.Width, ResetBtn.Width, ApplyBtn.Width, CancelBtn.Width, OKBtn.Width]);
HelpBtn.Constraints.MinWidth := wid;
ResetBtn.Constraints.MinWidth := wid;
ApplyBtn.Constraints.MinWidth := wid;
CancelBtn.Constraints.MinWidth := wid;
OKBtn.Constraints.MinWidth := wid;
end;
procedure TMoveAvgFrm.OrderEditEditingDone(Sender: TObject);
var
i: Integer;
begin
ThetaList.Items.BeginUpdate;
try
ThetaList.Clear; ThetaList.Clear;
order := StrToInt(OrderEdit.Text); Order := StrToInt(orderEdit.Text);
for i := 1 to order do for i := 1 to Order do
begin ThetaList.Items.Add('Theta(' + IntToStr(i) + ')');
cellstring := 'Theta(' + IntToStr(i) + ')'; finally
ThetaList.Items.Add(cellstring); ThetaList.Items.EndUpdate;
end; end;
end;
(*
procedure TMoveAvgFrm.OrderEditKeyPress(Sender: TObject; var Key: char);
var
cellstring: string;
i: integer;
begin
if ord(Key) <> 13 then exit;
ThetaList.Clear;
order := StrToInt(OrderEdit.Text);
for i := 1 to order do
begin
cellstring := 'Theta(' + IntToStr(i) + ')';
ThetaList.Items.Add(cellstring);
end;
end;
*)
function TMoveAvgFrm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
var
n: Integer;
begin
Result := false;
if OrderEdit.Text = '' then
begin
AControl := OrderEdit;
AMsg := 'Input required.';
exit;
end;
if not TryStrToInt(OrderEdit.Text, n) or (n < 0) then
begin
AControl := OrderEdit;
AMsg := 'Non-negative integer value required.';
exit;
end;
if ThetaEdit.Text <> '' then
begin
AControl := ThetaEdit;
AMsg := 'Please press ENTER to add this input.';
exit;
end;
Result := true;
end; end;
initialization initialization

View File

@ -45,6 +45,7 @@ object PolynomialFrm: TPolynomialFrm
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'OK' Caption = 'OK'
ModalResult = 1 ModalResult = 1
OnClick = OKBtnClick
TabOrder = 3 TabOrder = 3
end end
object HelpBtn: TButton object HelpBtn: TButton

View File

@ -24,6 +24,7 @@ type
procedure FormActivate(Sender: TObject); procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
procedure HelpBtnClick(Sender: TObject); procedure HelpBtnClick(Sender: TObject);
procedure OKBtnClick(Sender: TObject);
private private
{ private declarations } { private declarations }
public public
@ -62,6 +63,24 @@ begin
ContextHelpForm.HelpMessage((Sender as TButton).tag); ContextHelpForm.HelpMessage((Sender as TButton).tag);
end; end;
procedure TPolynomialFrm.OKBtnClick(Sender: TObject);
var
n: Integer;
begin
if PolyEdit.Text = '' then
begin
PolyEdit.SetFocus;
MessageDlg('Polynomial order not specified.', mtError, [mbOK], 0);
ModalResult := mrNone;
end else
if not TryStrToInt(PolyEdit.Text, n) or (n < 0) then
begin
PolyEdit.SetFocus;
MessageDlg('Polynomial order must be a valid integer > 0', mtError, [mbOK], 0);
ModalResult := mrNone;
end;
end;
initialization initialization
{$I polynomialunit.lrs} {$I polynomialunit.lrs}

View File

@ -63,12 +63,15 @@ const
procedure DisplayReport(AReport: TStrings); procedure DisplayReport(AReport: TStrings);
begin begin
if OutputFrm = nil then if AReport.Count > 0 then
OutputFrm := TOutputFrm.Create(Application) begin
else if OutputFrm = nil then
OutputFrm.Clear; OutputFrm := TOutputFrm.Create(Application)
OutputFrm.AddLines(AReport); else
OutputFrm.ShowModal; OutputFrm.Clear;
OutputFrm.AddLines(AReport);
OutputFrm.ShowModal;
end;
end; end;

View File

@ -89,11 +89,14 @@ const
); );
DIVIDER = '==========================================================================='; DIVIDER = '===========================================================================';
DIVIDER_SMALL = '---------------------------------------------------------------------------';
GRAPH_BACK_COLOR = clCream; GRAPH_BACK_COLOR = clCream;
GRAPH_WALL_COLOR = clGray; GRAPH_WALL_COLOR = clGray;
GRAPH_FLOOR_COLOR = clLtGray; GRAPH_FLOOR_COLOR = clLtGray;
TWO_PI = 2.0 * PI;
implementation implementation
end. end.