LazStats: Inherit form in LifeTableUnit from BasicStatsParamsForm.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8017 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2021-05-09 18:05:59 +00:00
parent 7daa8215e6
commit 03efb4e2b9
5 changed files with 393 additions and 456 deletions

View File

@ -1,51 +1,45 @@
object LifeTableForm: TLifeTableForm
inherited LifeTableForm: TLifeTableForm
Left = 496
Height = 590
Height = 528
Top = 122
Width = 818
Width = 784
HelpType = htKeyword
HelpKeyword = 'html/LifeTable.htm'
AutoSize = True
Caption = 'Life Table'
ClientHeight = 590
ClientWidth = 818
OnActivate = FormActivate
ClientHeight = 528
ClientWidth = 784
OnCreate = FormCreate
OnShow = FormShow
Position = poMainFormCenter
LCLVersion = '2.1.0.0'
object Grid: TStringGrid
Left = 379
Height = 420
Top = 121
Width = 500
Align = alClient
BorderSpacing.Left = 2
BorderSpacing.Top = 8
BorderSpacing.Right = 8
ColCount = 13
Constraints.MinWidth = 500
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goThumbTracking, goSmoothScroll]
RowCount = 2
TabOrder = 2
end
object Panel1: TPanel
Left = 8
Height = 420
Top = 121
Width = 363
Align = alLeft
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 2
BevelOuter = bvNone
ClientHeight = 420
ClientWidth = 363
Constraints.MinWidth = 300
inherited ParamsPanel: TPanel
Height = 512
Width = 260
AutoSize = True
ClientHeight = 512
ClientWidth = 260
TabOrder = 1
object Label1: TLabel
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Panel1
inherited CloseBtn: TButton
Left = 205
Top = 487
end
inherited ComputeBtn: TButton
Left = 121
Top = 487
end
inherited ResetBtn: TButton
Left = 59
Top = 487
end
inherited HelpBtn: TButton
Left = 0
Top = 487
Visible = False
end
inherited ButtonBevel: TBevel
Top = 471
Width = 260
end
object Label1: TLabel[5]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = ParamsPanel
Left = 0
Height = 15
Top = 0
@ -53,29 +47,29 @@ object LifeTableForm: TLifeTableForm
Caption = 'Variables:'
ParentColor = False
end
object VarList: TListBox
AnchorSideLeft.Control = Panel1
object VarList: TListBox[6]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ObsStartInBtn
AnchorSideBottom.Control = Panel1
AnchorSideBottom.Side = asrBottom
Left = 0
Height = 403
Height = 454
Top = 17
Width = 159
Width = 110
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 2
BorderSpacing.Right = 8
BorderSpacing.Right = 6
ItemHeight = 0
OnDblClick = VarListDblClick
OnSelectionChange = VarListSelectionChange
TabOrder = 0
TabOrder = 4
end
object ObsStartInBtn: TBitBtn
AnchorSideLeft.Control = Panel1
object ObsStartInBtn: TBitBtn[7]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = VarList
Left = 167
Left = 116
Height = 28
Top = 19
Width = 28
@ -84,14 +78,14 @@ object LifeTableForm: TLifeTableForm
ImageIndex = 1
OnClick = ObsStartInBtnClick
Spacing = 0
TabOrder = 1
TabOrder = 5
end
object ObsStartOutBtn: TBitBtn
AnchorSideLeft.Control = Panel1
object ObsStartOutBtn: TBitBtn[8]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = ObsStartInBtn
AnchorSideTop.Side = asrBottom
Left = 167
Left = 116
Height = 28
Top = 51
Width = 28
@ -100,47 +94,44 @@ object LifeTableForm: TLifeTableForm
ImageIndex = 0
OnClick = ObsStartOutBtnClick
Spacing = 0
TabOrder = 2
TabOrder = 6
end
object Label2: TLabel
AnchorSideLeft.Control = ObsStartInBtn
AnchorSideLeft.Side = asrBottom
object Label2: TLabel[9]
AnchorSideLeft.Control = ObsStartEdit
AnchorSideBottom.Control = ObsStartEdit
Left = 203
Left = 150
Height = 15
Top = 27
Width = 91
Anchors = [akLeft, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Bottom = 2
Caption = 'Observation Start'
ParentColor = False
end
object ObsStartEdit: TEdit
object ObsStartEdit: TEdit[10]
AnchorSideLeft.Control = ObsStartInBtn
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label2
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Panel1
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ObsStartOutBtn
AnchorSideBottom.Side = asrBottom
Left = 203
Left = 150
Height = 23
Top = 44
Width = 160
Width = 110
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Left = 6
BorderSpacing.Bottom = 12
Constraints.MinWidth = 150
ReadOnly = True
TabOrder = 3
TabOrder = 7
Text = 'ObsStartEdit'
end
object Label3: TLabel
object Label3: TLabel[11]
AnchorSideLeft.Control = ObsEndEdit
AnchorSideBottom.Control = ObsEndEdit
Left = 203
Left = 152
Height = 15
Top = 111
Width = 90
@ -149,30 +140,30 @@ object LifeTableForm: TLifeTableForm
Caption = 'Observation End:'
ParentColor = False
end
object ObsEndEdit: TEdit
object ObsEndEdit: TEdit[12]
AnchorSideLeft.Control = ObsEndInBtn
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = Panel1
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ObsEndOutBtn
AnchorSideBottom.Side = asrBottom
Left = 203
Left = 152
Height = 23
Top = 128
Width = 160
Width = 108
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Bottom = 12
ReadOnly = True
TabOrder = 6
TabOrder = 8
Text = 'ObsEndEdit'
end
object ObsEndInBtn: TBitBtn
AnchorSideLeft.Control = Panel1
object ObsEndInBtn: TBitBtn[13]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = ObsStartOutBtn
AnchorSideTop.Side = asrBottom
Left = 167
Left = 116
Height = 28
Top = 103
Width = 28
@ -181,14 +172,14 @@ object LifeTableForm: TLifeTableForm
ImageIndex = 1
OnClick = ObsEndInBtnClick
Spacing = 0
TabOrder = 4
TabOrder = 9
end
object ObsEndOutBtn: TBitBtn
AnchorSideLeft.Control = Panel1
object ObsEndOutBtn: TBitBtn[14]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = ObsEndInBtn
AnchorSideTop.Side = asrBottom
Left = 167
Left = 116
Height = 28
Top = 135
Width = 28
@ -197,12 +188,12 @@ object LifeTableForm: TLifeTableForm
ImageIndex = 0
OnClick = ObsEndOutBtnClick
Spacing = 0
TabOrder = 5
TabOrder = 10
end
object Label4: TLabel
object Label4: TLabel[15]
AnchorSideLeft.Control = NoAliveEdit
AnchorSideBottom.Control = NoAliveEdit
Left = 203
Left = 152
Height = 15
Top = 195
Width = 76
@ -211,30 +202,30 @@ object LifeTableForm: TLifeTableForm
Caption = 'Number Alive:'
ParentColor = False
end
object NoAliveEdit: TEdit
AnchorSideLeft.Control = AliveInBtn
object NoAliveEdit: TEdit[16]
AnchorSideLeft.Control = ObsEndInBtn
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = Panel1
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = AliveOutBtn
AnchorSideBottom.Side = asrBottom
Left = 203
Left = 152
Height = 23
Top = 212
Width = 160
Width = 108
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Bottom = 12
ReadOnly = True
TabOrder = 9
TabOrder = 11
Text = 'NoAliveEdit'
end
object AliveInBtn: TBitBtn
AnchorSideLeft.Control = Panel1
object AliveInBtn: TBitBtn[17]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = ObsEndOutBtn
AnchorSideTop.Side = asrBottom
Left = 167
Left = 116
Height = 28
Top = 187
Width = 28
@ -243,14 +234,14 @@ object LifeTableForm: TLifeTableForm
ImageIndex = 1
OnClick = AliveInBtnClick
Spacing = 0
TabOrder = 7
TabOrder = 12
end
object AliveOutBtn: TBitBtn
AnchorSideLeft.Control = Panel1
object AliveOutBtn: TBitBtn[18]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = AliveInBtn
AnchorSideTop.Side = asrBottom
Left = 167
Left = 116
Height = 28
Top = 219
Width = 28
@ -259,12 +250,12 @@ object LifeTableForm: TLifeTableForm
ImageIndex = 0
OnClick = AliveOutBtnClick
Spacing = 0
TabOrder = 8
TabOrder = 13
end
object Label5: TLabel
object Label5: TLabel[19]
AnchorSideLeft.Control = NoDiedEdit
AnchorSideBottom.Control = NoDiedEdit
Left = 203
Left = 152
Height = 15
Top = 279
Width = 74
@ -273,30 +264,30 @@ object LifeTableForm: TLifeTableForm
Caption = 'Number Died:'
ParentColor = False
end
object NoDiedEdit: TEdit
AnchorSideLeft.Control = NoDiedOutBtn
object NoDiedEdit: TEdit[20]
AnchorSideLeft.Control = ObsEndInBtn
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = Panel1
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = NoDiedOutBtn
AnchorSideBottom.Side = asrBottom
Left = 203
Left = 152
Height = 23
Top = 296
Width = 160
Width = 108
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Bottom = 12
ReadOnly = True
TabOrder = 12
TabOrder = 14
Text = 'NoDiedEdit'
end
object NoDiedInBtn: TBitBtn
AnchorSideLeft.Control = Panel1
object NoDiedInBtn: TBitBtn[21]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = AliveOutBtn
AnchorSideTop.Side = asrBottom
Left = 167
Left = 116
Height = 28
Top = 271
Width = 28
@ -305,14 +296,14 @@ object LifeTableForm: TLifeTableForm
ImageIndex = 1
OnClick = NoDiedInBtnClick
Spacing = 0
TabOrder = 10
TabOrder = 15
end
object NoDiedOutBtn: TBitBtn
AnchorSideLeft.Control = Panel1
object NoDiedOutBtn: TBitBtn[22]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = NoDiedInBtn
AnchorSideTop.Side = asrBottom
Left = 167
Left = 116
Height = 28
Top = 303
Width = 28
@ -321,12 +312,12 @@ object LifeTableForm: TLifeTableForm
ImageIndex = 0
OnClick = NoDiedOutBtnClick
Spacing = 0
TabOrder = 11
TabOrder = 16
end
object Label6: TLabel
object Label6: TLabel[23]
AnchorSideLeft.Control = NoCensoredEdit
AnchorSideBottom.Control = NoCensoredEdit
Left = 203
Left = 152
Height = 15
Top = 363
Width = 100
@ -335,30 +326,30 @@ object LifeTableForm: TLifeTableForm
Caption = 'Number Censored:'
ParentColor = False
end
object NoCensoredEdit: TEdit
AnchorSideLeft.Control = NoCensoredOutBtn
object NoCensoredEdit: TEdit[24]
AnchorSideLeft.Control = ObsEndInBtn
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = Panel1
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = NoCensoredOutBtn
AnchorSideBottom.Side = asrBottom
Left = 203
Left = 152
Height = 23
Top = 380
Width = 160
Width = 108
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Bottom = 12
ReadOnly = True
TabOrder = 15
TabOrder = 17
Text = 'NoCensoredEdit'
end
object NoCensoredInBtn: TBitBtn
AnchorSideLeft.Control = Panel1
object NoCensoredInBtn: TBitBtn[25]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = NoDiedOutBtn
AnchorSideTop.Side = asrBottom
Left = 167
Left = 116
Height = 28
Top = 355
Width = 28
@ -367,14 +358,14 @@ object LifeTableForm: TLifeTableForm
ImageIndex = 1
OnClick = NoCensoredInBtnClick
Spacing = 0
TabOrder = 13
TabOrder = 18
end
object NoCensoredOutBtn: TBitBtn
AnchorSideLeft.Control = Panel1
object NoCensoredOutBtn: TBitBtn[26]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = NoCensoredInBtn
AnchorSideTop.Side = asrBottom
Left = 167
Left = 116
Height = 28
Hint = '0'
Top = 387
@ -384,159 +375,58 @@ object LifeTableForm: TLifeTableForm
ImageIndex = 0
OnClick = NoCensoredOutBtnClick
Spacing = 0
TabOrder = 14
TabOrder = 19
end
end
object Panel2: TPanel
Left = 0
Height = 41
Top = 549
Width = 818
Align = alBottom
AutoSize = True
BevelOuter = bvNone
ClientHeight = 41
ClientWidth = 818
TabOrder = 3
object ResetBtn: TButton
AnchorSideTop.Control = Panel2
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Side = asrCenter
Left = 609
Height = 25
Top = 8
Width = 54
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 1
end
object ComputeBtn: TButton
AnchorSideTop.Control = Panel2
AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Side = asrCenter
Left = 671
Height = 25
Top = 8
Width = 76
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 2
end
object CloseBtn: TButton
AnchorSideTop.Control = Panel2
AnchorSideRight.Control = Panel2
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Side = asrCenter
Left = 755
Height = 25
Top = 8
Width = 55
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Close'
ModalResult = 11
TabOrder = 3
end
object HelpBtn: TButton
AnchorSideTop.Control = Panel2
AnchorSideRight.Control = ResetBtn
Left = 550
Height = 25
Top = 8
Width = 51
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Help'
OnClick = HelpBtnClick
TabOrder = 0
end
end
object Panel3: TPanel
Left = 0
Height = 113
Top = 0
Width = 818
Align = alTop
AutoSize = True
BevelOuter = bvNone
ClientHeight = 113
ClientWidth = 818
TabOrder = 0
object Memo1: TLabel
AnchorSideLeft.Control = Panel3
AnchorSideTop.Control = Panel3
AnchorSideRight.Side = asrBottom
Left = 8
Height = 105
Top = 8
Width = 427
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'Directions: Your input grid data should consist of five integer column vaiables:'#13#10'1. The beginning of each observation period (typically 0 for the first observation.'#13#10'2. The ending of each observation period.'#13#10'3. The number alive in the observation period.'#13#10'4. The number that died during the observation period.'#13#10'5. The number last seen alive during the period that are lost (censored)'#13#10'See the example file "lifetable.laz".'
ParentColor = False
WordWrap = True
end
object Label7: TLabel
object Label7: TLabel[27]
AnchorSideTop.Control = CIEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = CIEdit
Left = 576
Height = 15
Top = 94
Width = 188
Left = 115
Height = 30
Top = 435
Width = 94
Anchors = [akTop, akRight]
BorderSpacing.Right = 8
Caption = 'Confidence Level for Number Alive:'
Caption = 'Confidence Level'#13#10'for Number Alive:'
ParentColor = False
end
object CIEdit: TEdit
AnchorSideRight.Control = Panel3
object CIEdit: TEdit[28]
AnchorSideTop.Control = NoCensoredOutBtn
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Memo1
AnchorSideBottom.Side = asrBottom
Left = 772
Left = 217
Height = 23
Top = 90
Width = 38
Anchors = [akRight, akBottom]
BorderSpacing.Right = 8
TabOrder = 0
Top = 439
Width = 43
Alignment = taRightJustify
Anchors = [akTop, akRight]
BorderSpacing.Top = 24
BorderSpacing.Bottom = 8
TabOrder = 20
Text = '0.95'
end
end
object Splitter1: TSplitter
Left = 373
Height = 428
Top = 113
Width = 4
inherited ParamsSplitter: TSplitter
Left = 272
Height = 528
end
object Bevel1: TBevel
Left = 0
Height = 8
Top = 541
Width = 818
Align = alBottom
Shape = bsBottomLine
object Grid: TStringGrid[2]
Left = 281
Height = 512
Top = 8
Width = 495
Align = alClient
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 4
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
ColCount = 13
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goThumbTracking, goSmoothScroll]
RowCount = 2
TabOrder = 0
OnPrepareCanvas = GridPrepareCanvas
end
end

View File

@ -7,19 +7,16 @@ interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls, Grids,
MainUnit, Globals, FunctionsLib, OutputUnit,
GraphLib, ContextHelpUnit;
MainUnit, Globals, FunctionsLib, GraphLib, BasicStatsParamsFormUnit;
type
{ TLifeTableForm }
TLifeTableForm = class(TForm)
TLifeTableForm = class(TBasicStatsParamsForm)
Bevel1: TBevel;
HelpBtn: TButton;
CIEdit: TEdit;
Label7: TLabel;
Memo1: TLabel;
NoCensoredEdit: TEdit;
Label6: TLabel;
NoDiedEdit: TEdit;
@ -40,23 +37,16 @@ type
AliveOutBtn: TBitBtn;
NoDiedOutBtn: TBitBtn;
NoCensoredOutBtn: TBitBtn;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
ResetBtn: TButton;
ComputeBtn: TButton;
CloseBtn: TButton;
Label1: TLabel;
Grid: TStringGrid;
Splitter1: TSplitter;
VarList: TListBox;
procedure AliveInBtnClick(Sender: TObject);
procedure AliveOutBtnClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure HelpBtnClick(Sender: TObject);
procedure GridPrepareCanvas(Sender: TObject; ACol, aRow: Integer;
AState: TGridDrawState);
procedure NoCensoredInBtnClick(Sender: TObject);
procedure NoCensoredOutBtnClick(Sender: TObject);
procedure NoDiedInBtnClick(Sender: TObject);
@ -65,15 +55,17 @@ type
procedure ObsEndOutBtnClick(Sender: TObject);
procedure ObsStartInBtnClick(Sender: TObject);
procedure ObsStartOutBtnClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; User: boolean);
private
{ private declarations }
FAutoSized: Boolean;
procedure UpdateBtnStates;
protected
procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
function Validate(out AMsg: String; out AControl: TWinControl): Boolean; override;
public
{ public declarations }
procedure Reset; override;
end;
var
@ -81,93 +73,33 @@ var
implementation
{$R *.lfm}
uses
Math;
Math,
GridProcs;
{ TLifeTableForm }
procedure TLifeTableForm.FormActivate(Sender: TObject);
var
w: Integer;
procedure TLifeTableForm.AdjustConstraints;
begin
if FAutoSized then
exit;
ParamsPanel.Constraints.MinWidth :=
MaxValue([
Label2.Canvas.TextWidth(Label2.Caption),
Label3.Canvas.TextWidth(Label3.Caption),
Label4.Canvas.TextWidth(Label4.Caption),
Label5.Canvas.TextWidth(Label5.Caption),
Label6.Canvas.Textwidth(Label6.Caption),
Label7.canvas.TextWidth('Confidence Level') + Label7.BorderSpacing.Right + CIEdit.Width]) * 2 +
ObsStartInBtn.Width + VarList.BorderSpacing.Right * 2;
w := MaxValue([HelpBtn.Width, ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
HelpBtn.Constraints.MinWidth := w;
ResetBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w;
Constraints.MinWidth := Width;
Constraints.MinHeight := Height;
FAutoSized := True;
ParamsPanel.Constraints.MinHeight :=
CIEdit.Top + CIEdit.Height + CIEdit.BorderSpacing.Bottom +
ButtonBevel.Height +
CloseBtn.BorderSpacing.Top + CloseBtn.Height;
end;
procedure TLifeTableForm.FormCreate(Sender: TObject);
begin
Assert(OS3MainFrm <> nil);
CIEdit.Text := FormatFloat('0.00', DEFAULT_CONFIDENCE_LEVEL_PERCENT * 0.01);
end;
procedure TLifeTableForm.FormShow(Sender: TObject);
begin
ResetBtnClick(self);
end;
procedure TLifeTableForm.HelpBtnClick(Sender: TObject);
begin
if ContextHelpForm = nil then
Application.CreateForm(TContextHelpForm, ContextHelpForm);
ContextHelpForm.HelpMessage((Sender as TButton).tag);
end;
procedure TLifeTableForm.NoCensoredInBtnClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (NoCensoredEdit.Text = '') then
begin
NoCensoredEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
procedure TLifeTableForm.NoCensoredOutBtnClick(Sender: TObject);
begin
if NoCensoredEdit.Text <> '' then
begin
VarList.Items.Add(NoCensoredEdit.Text);
NoCensoredEdit.Text := '';
end;
UpdateBtnStates;
end;
procedure TLifeTableForm.NoDiedInBtnClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (NoDiedEdit.Text = '') then
begin
NoDiedEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
procedure TLifeTableForm.NoDiedOutBtnClick(Sender: TObject);
begin
if NoDiedEdit.Text <> '' then
begin
VarList.Items.Add(NoDiedEdit.Text);
NoDiedEdit.Text := '';
end;
UpdateBtnStates;
end;
procedure TLifeTableForm.AliveInBtnClick(Sender: TObject);
var
@ -182,6 +114,7 @@ begin
UpdateBtnStates;
end;
procedure TLifeTableForm.AliveOutBtnClick(Sender: TObject);
begin
if NoAliveEdit.Text <> '' then
@ -192,72 +125,46 @@ begin
UpdateBtnStates;
end;
procedure TLifeTableForm.ComputeBtnClick(Sender: TObject);
procedure TLifeTableForm.Compute;
var
i : integer;
varcols : IntDyneVec;
AtRisk, ProbDie, CumProbLive, StdErr, Up95, Low95 : double;
N, P, Q, mu, CI, z : double;
varcols: IntDyneVec = nil;
i: integer;
AtRisk, ProbDie, CumProbLive, StdErr, Up95, Low95: double;
N, P, Q, mu, CI, z: double;
begin
if ObsStartEdit.Text = '' then
begin
MessageDlg('Observation Start not specified.', mtError, [mbOK], 0);
exit;
end;
if ObsEndEdit.Text = '' then
begin
MessageDlg('Observation End not specified.', mtError, [mbOK], 0);
exit;
end;
if NoAliveEdit.Text = '' then
begin
MessageDlg('Number Alive not specified.', mtError, [mbOK], 0);
exit;
end;
if NoDiedEdit.Text = '' then
begin
MessageDlg('Number Died not specified.', mtError, [mbOK], 0);
exit;
end;
if NoCensoredEdit.Text = '' then
begin
MessageDlg('Number Censored not specified.', mtError, [mbOK], 0);
exit;
end;
CI := StrToFloat(CIEdit.Text);
z := InverseZ(CI);
SetLength(varcols, 5);
for i := 1 to 5 do
begin
if (OS3MainFrm.DataGrid.Cells[i,0] = ObsStartEdit.Text) then varcols[0] := i;
if (OS3MainFrm.DataGrid.Cells[i,0] = ObsEndEdit.Text) then varcols[1] := i;
if (OS3MainFrm.DataGrid.Cells[i,0] = NoAliveEdit.Text) then varcols[2] := i;
if (OS3MainFrm.DataGrid.Cells[i,0] = NoDiedEdit.Text) then varcols[3] := i;
if (OS3MainFrm.DataGrid.Cells[i,0] = NoCensoredEdit.Text) then varcols[4] := i;
if (OS3MainFrm.DataGrid.Cells[i,0] = ObsStartEdit.Text) then varcols[0] := i;
if (OS3MainFrm.DataGrid.Cells[i,0] = ObsEndEdit.Text) then varcols[1] := i;
if (OS3MainFrm.DataGrid.Cells[i,0] = NoAliveEdit.Text) then varcols[2] := i;
if (OS3MainFrm.DataGrid.Cells[i,0] = NoDiedEdit.Text) then varcols[3] := i;
if (OS3MainFrm.DataGrid.Cells[i,0] = NoCensoredEdit.Text) then varcols[4] := i;
end;
Grid.RowCount := NoCases + Grid.FixedRows;
for i := 1 to NoCases do
begin
Grid.Cells[0,i] := 'CASE ' + IntToStr(i);
Grid.Cells[1,i] := Trim(OS3MainFrm.DataGrid.Cells[varcols[0],i]);
Grid.Cells[2,i] := Trim(OS3MainFrm.DataGrid.Cells[varcols[1],i]);
Grid.Cells[3,i] := Trim(OS3MainFrm.DataGrid.Cells[varcols[2],i]);
Grid.Cells[4,i] := Trim(OS3MainFrm.DataGrid.Cells[varcols[3],i]);
Grid.Cells[5,i] := Trim(OS3MainFrm.DataGrid.Cells[varcols[4],i]);
end;
for i := 1 to NoCases do
begin
Grid.Cells[0,i] := 'CASE ' + IntToStr(i);
Grid.Cells[1,i] := Trim(OS3MainFrm.DataGrid.Cells[varcols[0],i]);
Grid.Cells[2,i] := Trim(OS3MainFrm.DataGrid.Cells[varcols[1],i]);
Grid.Cells[3,i] := Trim(OS3MainFrm.DataGrid.Cells[varcols[2],i]);
Grid.Cells[4,i] := Trim(OS3MainFrm.DataGrid.Cells[varcols[3],i]);
Grid.Cells[5,i] := Trim(OS3MainFrm.DataGrid.Cells[varcols[4],i]);
end;
for i := 1 to NoCases do
begin
AtRisk := StrToFloat(Grid.Cells[3,i]);
AtRisk := AtRisk - (StrToFloat(Grid.Cells[5,i]) / 2.0);
Grid.Cells[6,i] := Format('%.4f', [AtRisk]);
ProbDie := StrToFloat(Grid.Cells[4,i]) / AtRisk;
Grid.Cells[7,i] := Format('%.4f', [ProbDie]);
Grid.Cells[8,i] := Format('%.4f', [1.0-ProbDie]);
AtRisk := StrToFloat(Grid.Cells[3,i]);
AtRisk := AtRisk - (StrToFloat(Grid.Cells[5,i]) / 2.0);
Grid.Cells[6,i] := Format('%.4f', [AtRisk]);
ProbDie := StrToFloat(Grid.Cells[4,i]) / AtRisk;
Grid.Cells[7,i] := Format('%.4f', [ProbDie]);
Grid.Cells[8,i] := Format('%.4f', [1.0-ProbDie]);
end;
N := StrToFloat(Grid.Cells[3,1]);
@ -266,7 +173,7 @@ begin
P := StrToFloat(Grid.Cells[9,1]);
Q := 1.0 - P;
StdErr := sqrt(N * P * Q);
Grid.Cells[10,1] := format('%.4f', [StdErr]);
Grid.Cells[10,1] := Format('%.4f', [StdErr]);
mu := N * P;
Grid.Cells[10,1] := Format('%.4f', [StdErr]);
@ -278,21 +185,91 @@ begin
for i := 2 to NoCases do
begin
CumProbLive := StrToFloat(Grid.Cells[9,i-1]) * StrToFloat(Grid.Cells[8,i]);
Grid.Cells[9,i] := Format('%.4f', [CumProbLive]);
P := CumProbLive;
Q := 1.0 - P;
StdErr := sqrt(N * P * Q);
mu := N * P;
Grid.Cells[10,i] := Format('%.4f', [StdErr]);
Up95 := mu + z * StdErr;
Low95 := mu - z * StdErr;
Grid.Cells[11,i] := Format('%.4f', [Low95]);
Grid.Cells[12,i] := Format('%.4f', [Up95]);
CumProbLive := StrToFloat(Grid.Cells[9,i-1]) * StrToFloat(Grid.Cells[8,i]);
Grid.Cells[9,i] := Format('%.4f', [CumProbLive]);
P := CumProbLive;
Q := 1.0 - P;
StdErr := sqrt(N * P * Q);
mu := N * P;
Grid.Cells[10,i] := Format('%.4f', [StdErr]);
Up95 := mu + z * StdErr;
Low95 := mu - z * StdErr;
Grid.Cells[11,i] := Format('%.4f', [Low95]);
Grid.Cells[12,i] := Format('%.4f', [Up95]);
end;
varcols := nil;
end;
procedure TLifeTableForm.FormCreate(Sender: TObject);
begin
Assert(OS3MainFrm <> nil);
CIEdit.Text := FormatFloat('0.00', DEFAULT_CONFIDENCE_LEVEL_PERCENT * 0.01);
end;
procedure TLifeTableForm.GridPrepareCanvas(sender: TObject; aCol,
aRow: Integer; aState: TGridDrawState);
var
ts: TTextStyle;
begin
if aRow > 0 then begin
ts := Grid.Canvas.TextStyle;
ts.Alignment := taRightJustify;
Grid.Canvas.TextStyle := ts;
end;
end;
procedure TLifeTableForm.NoCensoredInBtnClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (NoCensoredEdit.Text = '') then
begin
NoCensoredEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
procedure TLifeTableForm.NoCensoredOutBtnClick(Sender: TObject);
begin
if NoCensoredEdit.Text <> '' then
begin
VarList.Items.Add(NoCensoredEdit.Text);
NoCensoredEdit.Text := '';
end;
UpdateBtnStates;
end;
procedure TLifeTableForm.NoDiedInBtnClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (NoDiedEdit.Text = '') then
begin
NoDiedEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
procedure TLifeTableForm.NoDiedOutBtnClick(Sender: TObject);
begin
if NoDiedEdit.Text <> '' then
begin
VarList.Items.Add(NoDiedEdit.Text);
NoDiedEdit.Text := '';
end;
UpdateBtnStates;
end;
procedure TLifeTableForm.ObsEndInBtnClick(Sender: TObject);
var
index: integer;
@ -339,22 +316,17 @@ begin
UpdateBtnStates;
end;
procedure TLifeTableForm.ResetBtnClick(Sender: TObject);
VAR i : integer;
j : integer;
procedure TLifeTableForm.Reset;
var
i, j: integer;
begin
// outline := format('NoCases = %d',[NoCases]);
// ShowMessage(outline);
// outline := format('No.Variables = %d',[NoVariables]);
// ShowMessage(outline);
VarList.Clear;
ObsStartEdit.Text := '';
ObsEndEdit.Text := '';
NoAliveEdit.Text := '';
NoDiedEdit.Text := '';
NoCensoredEdit.Text := '';
Grid.RowCount := NoCases+1;
Grid.RowCount := 2; //NoCases + Grid.FixedRows;
Grid.ColCount := 13;
Grid.Cells[1,0] := 'Obs.Start';
Grid.Cells[2,0] := 'Obs.End';
@ -368,17 +340,14 @@ begin
Grid.Cells[10,0] := 'S.E. Alive';
Grid.Cells[11,0] := 'Low 95%';
Grid.Cells[12,0] := 'Hi 95%';
for i := 0 to 12 do
for j := 1 to NoCases do Grid.Cells[i,j] := '';
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
for i := 0 to 12 do Grid.Cells[i, 1] := '';
// for j := 1 to NoCases do Grid.Cells[i,j] := '';
CollectVariableNames(OS3MainFrm.DataGrid, VarList.Items);
UpdateBtnStates;
end;
procedure TLifeTableForm.VarListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end;
procedure TLifeTableForm.UpdateBtnStates;
begin
@ -395,8 +364,82 @@ begin
NoCensoredOutBtn.Enabled := (NoCensoredEdit.Text > '');
end;
initialization
{$I lifetableunit.lrs}
function TLifeTableForm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
begin
Result := false;
if ObsStartEdit.Text = '' then
begin
AMsg := 'Observation Start not specified.';
AControl := ObsStartEdit;
exit;
end;
if ObsEndEdit.Text = '' then
begin
AMsg := 'Observation End not specified.';
AControl := ObsEndEdit;
exit;
end;
if NoAliveEdit.Text = '' then
begin
AMsg := 'Number Alive not specified.';
AControl := NoAliveEdit;
exit;
end;
if NoDiedEdit.Text = '' then
begin
AMsg := 'Number Died not specified.';
AControl := NoDiedEdit;
exit;
end;
if NoCensoredEdit.Text = '' then
begin
AMsg := 'Number Censored not specified.';
AControl := NoCensoredEdit;
exit;
end;
Result := true;
end;
procedure TLifeTableForm.VarListDblClick(Sender: TObject);
var
index: Integer;
s: String;
begin
index := VarList.ItemIndex;
if index > -1 then
begin
s := VarList.Items[index];
if ObsStartEdit.Text = '' then
ObsStartEdit.Text := s
else if ObsEndEdit.Text = '' then
ObsEndEdit.Text := s
else if NoAliveEdit.Text = '' then
NoAliveEdit.Text := s
else if NoDiedEdit.Text = '' then
NoDiedEdit.Text := s
else if NoCensoredEdit.Text = '' then
NoCensoredEdit.Text := s
else
exit;
VarList.Items.Delete(index);
UpdateBtnStates;
end;
end;
procedure TLifeTableForm.VarListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end;
end.

View File

@ -887,6 +887,9 @@ object OS3MainFrm: TOS3MainFrm
Caption = 'Scheirer-Ray-Hare 2-way ANOVA'
OnClick = mnuAnalysisNonPar_SRHClick
end
object MenuItem3: TMenuItem
Caption = '-'
end
object mnuAnalysisNonPar_LifeTable: TMenuItem
Caption = 'Life Table'
OnClick = mnuAnalysisNonPar_LifeTableClick

View File

@ -46,6 +46,7 @@ type
FilterEdit: TEdit;
FilterLabel: TLabel;
MenuItem2: TMenuItem;
MenuItem3: TMenuItem;
NoCasesEdit: TEdit;
NoCasesLabel: TLabel;
NoVarsEdit: TEdit;
@ -1787,7 +1788,7 @@ procedure TOS3MainFrm.mnuAnalysisNonPar_LifeTableClick(Sender: TObject);
begin
if LifeTableForm = nil then
Application.CreateForm(TLifeTableForm, LifeTableForm);
LifeTableForm.ShowModal;
LifeTableForm.Show;
end;