Files

92 lines
1.8 KiB
ObjectPascal

unit ProbChiSqrUnit;
{$mode objfpc}{$H+}
{$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls,
FunctionsLib;
type
{ TChiSqrProbForm }
TChiSqrProbForm = class(TForm)
Bevel1: TBevel;
CancelBtn: TButton;
ChiSqrEdit: TEdit;
ComputeBtn: TButton;
DFEdit: TEdit;
Panel1: TPanel;
ProbEdit: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ResetBtn: TButton;
ReturnBtn: TButton;
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
ChiSqrProbForm: TChiSqrProbForm;
implementation
{$R *.lfm}
uses
Math, MathUnit, Utils;
{ TChiSqrProbForm }
procedure TChiSqrProbForm.ResetBtnClick(Sender: TObject);
begin
ChiSqrEdit.Text := '';
DFEdit.Text := '';
ProbEdit.Text := '';
end;
procedure TChiSqrProbForm.ComputeBtnClick(Sender: TObject);
var
chiSqr, prob: double;
DF: integer;
begin
if not MyTryStrToFloat(ChiSqrEdit.Text, chiSqr) then
begin
ChiSqrEdit.SetFocus;
ErrorMsg('No valid number.');
exit;
end;
if not TryStrToInt(DFEdit.Text, DF) or (DF <= 0) then begin
DFEdit.SetFocus;
ErrorMsg('No a valid integer (must be positive).');
exit;
end;
prob := 1.0 - ChiSquaredProb(ChiSqr, DF);
ProbEdit.Text := Format('%6.4f', [prob]);
end;
procedure TChiSqrProbForm.FormActivate(Sender: TObject);
var
w: Integer;
begin
w := MaxValue([CancelBtn.Width, ResetBtn.Width, ComputeBtn.Width, ReturnBtn.Width]);
CancelBtn.Constraints.MinWidth := w;
ResetBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
ReturnBtn.Constraints.MinWidth := w;
end;
end.