unit DistrDis;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, ComCtrls;

type
  TQuantilsForm = class(TForm)
    PL1: TLabel;
    PL2: TLabel;
    PirsonL: TEdit;
    PirsonR: TEdit;
    PL3: TLabel;
    PL4: TLabel;
    Bevel1: TBevel;
    LC1: TLabel;
    CohrenN: TEdit;
    LC2: TLabel;
    CohrenD: TEdit;
    LC3: TLabel;
    Cohren: TEdit;
    Bevel2: TBevel;
    SL1: TLabel;
    StudentF: TEdit;
    SL2: TLabel;
    Student: TEdit;
    Bevel3: TBevel;
    FL1: TLabel;
    FisherN: TEdit;
    FL2: TLabel;
    FisherD: TEdit;
    FL3: TLabel;
    Fisher: TEdit;
    Bevel4: TBevel;
    QCancel: TButton;
    PirsonF: TEdit;
    Bevel5: TBevel;
    StatusBar: TStatusBar;
    procedure QCancelClick(Sender: TObject);
    procedure QFCreate(Sender: TObject);
    procedure QFUpdate(Sender: TObject);
    procedure EditValidateChar(Sender: TObject; var Key: Char);
  end;

var
  QuantilsForm: TQuantilsForm;

procedure       GetPirson(f,LR:integer;var Res:double);
  Pascal;external;
procedure       GetCohren(fnum,fdiv:integer;var Res:double);
  Pascal;external;
procedure       GetStudent(f:integer;var Res:double);
  Pascal;external;
procedure       GetFisher(fnum,fdiv:integer;var Res:double);
  Pascal;external;

{$LINK DISTRIBS.OBJ}

implementation

{$R *.DFM}

procedure TQuantilsForm.QCancelClick(Sender: TObject);
begin
  Close;
end;

procedure TQuantilsForm.QFCreate(Sender: TObject);
begin
  PirsonF.Text:='1';
  StudentF.Text:='1';
  CohrenN.Text:='1';
  CohrenD.Text:='2';
  FisherN.Text:='1';
  FisherD.Text:='1';
end;

procedure TQuantilsForm.QFUpdate(Sender: TObject);
var
  f,fn,fd : integer;
  res     : double;
  s_str   : array[1..3] of string;
begin
  s_str[1]:='Использовано ближайшее допустимое значение.';
  s_str[2]:='Нет исходных данных.';
  s_str[3]:='Операция завершена.';
  try
    if(Length(PirsonF.Text)>0) then
    begin
      f:=StrToInt(PirsonF.Text);
      if(f=0) then
      begin
        f:=1;
        PirsonF.Text:='1';
        if(ActiveControl=PirsonF) then
          StatusBar.SimpleText:=s_str[1];
      end
      else
        if(ActiveControl=PirsonF) then
          StatusBar.SimpleText:=s_str[3];
      GetPirson(f,0,res);
      PirsonL.Text:=Format('%4.4g',[res]);
      GetPirson(f,1,res);
      PirsonR.Text:=Format('%4.4g',[res]);
    end
    else
    begin
      PirsonL.Text:='';
      PirsonR.Text:='';
      if(ActiveControl=PirsonF) then
        StatusBar.SimpleText:=s_str[2];
    end;
    if((Length(CohrenN.Text)>0)and(Length(CohrenD.Text)>0)) then
    begin
      fn:=StrToInt(CohrenN.Text);
      fd:=StrToInt(CohrenD.Text);
      if(fn=0) then
      begin
        fn:=1;
        CohrenN.Text:='1';
        if(ActiveControl=CohrenN) then
          StatusBar.SimpleText:=s_str[1];
      end
      else
        if(ActiveControl=CohrenN) then
          StatusBar.SimpleText:=s_str[3];
      if(fd=0) then
      begin
        fd:=1;
        CohrenD.Text:='1';
        if(ActiveControl=CohrenD) then
          StatusBar.SimpleText:=s_str[1];
      end
      else
        if(ActiveControl=CohrenD) then
          StatusBar.SimpleText:=s_str[3];
      GetCohren(fn,fd,res);
      Cohren.Text:=Format('%4.4g',[res]);
    end
    else
    begin
      Cohren.Text:='';
      if((ActiveControl=CohrenN)or(ActiveControl=CohrenD)) then
        StatusBar.SimpleText:=s_str[2];
    end;
    if(Length(StudentF.Text)>0) then
    begin
      f:=StrToInt(StudentF.Text);
      if(f=0) then
      begin
        f:=1;
        StudentF.Text:='1';
        if(ActiveControl=StudentF) then
          StatusBar.SimpleText:=s_str[1];
      end
      else
        if(ActiveControl=StudentF) then
          StatusBar.SimpleText:=s_str[3];
      GetStudent(f,res);
      Student.Text:=Format('%4.4g',[res]);
    end
    else
    begin
      Student.Text:='';
      if(ActiveControl=StudentF) then
        StatusBar.SimpleText:=s_str[2];
    end;
    if((Length(FisherN.Text)>0)and(Length(FisherD.Text)>0)) then
    begin
      fn:=StrToInt(FisherN.Text);
      fd:=StrToInt(FisherD.Text);
      if(fn=0) then
      begin
        fn:=1;
        FisherN.Text:='1';
        if(ActiveControl=FisherN) then
          StatusBar.SimpleText:=s_str[1];
      end
      else
        if(ActiveControl=FisherN) then
          StatusBar.SimpleText:=s_str[3];
      if(fd=0) then
      begin
        fd:=1;
        FisherD.Text:='1';
        if(ActiveControl=FisherD) then
          StatusBar.SimpleText:=s_str[1];
      end
      else
        if(ActiveControl=FisherD) then
          StatusBar.SimpleText:=s_str[3];
      GetFisher(fn,fd,res);
      Fisher.Text:=Format('%4.4g',[res]);
    end
    else
    begin
      Fisher.Text:='';
      if((ActiveControl=FisherN)or(ActiveControl=FisherD)) then
      StatusBar.SimpleText:=s_str[2];
    end;
  except
    on EConvertError do StatusBar.SimpleText:=s_str[2];
  end;
end;

procedure TQuantilsForm.EditValidateChar(Sender: TObject; var Key: Char);
begin
  if((not((Key in ['0'..'9'])or(Key=#8)))or(Length(TEdit(Sender).Text)>7)) then
  begin
    Key := #27;
  end;
end;

end.

