unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, AppEvnts, ExtCtrls, StdCtrls, TeEngine, TeeProcs, Chart, Series, ExtDlgs; type TForm1 = class abstract(TForm) Button1: TButton; LabeledEdit1: TLabeledEdit; LabeledEdit2: TLabeledEdit; LabeledEdit3: TLabeledEdit; LabeledEdit4: TLabeledEdit; LabeledEdit5: TLabeledEdit; LabeledEdit6: TLabeledEdit; Chart1: TChart; LabeledEdit7: TLabeledEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Series1: TLineSeries; SaveTextFileDialog1: TSaveTextFileDialog; private { Private declarations } public { Public declarations } end; TStorage = class; TControl = class; // граничный класс TBorder = class(TForm1) procedure StartBtn(Sender: TObject); //Старт procedure InputParam (Sender: TObject); //Проверка ввода procedure Plot (betta : real; time : integer); //Построение графика function GetOutName (old : string) : string; private /// True _Controller: TControl; constructor Create(AOwner: TComponent); override; end; //класс-хранилище TStorage = class output : string; procedure SaveData (ro, h, r, w, db, w0, t, betta : real); //запись в файл procedure LoadFromFile (var t: array of string; var OutName : string; result : boolean); //считывание папарметров предыдущего расчета private /// True _Controller: TControl; end; //класс- контроллер TFinishEvent = procedure(Sender: TObject) of object; TControl = class private FFinish: TFinishEvent; /// True _Border: TBorder; /// True _Storage: TStorage; procedure Finish(); procedure GetData (var t: array of string); public property OnFinish: TFinishEvent read FFinish write FFinish; procedure Calc(ro, h, r, w, db, w0, t : real); //вычисление end; var Controller: TControl; Storage: TStorage; Border: TBorder; implementation {$R *.dfm} constructor TBorder.Create(AOwner: TComponent); //задание начальых параметров var param : TextFile; t : array [0..6] of string; i : integer; begin inherited; //связываем классы между собой Border._Controller := Controller; Controller._Border := Border; Controller._Storage := Storage; Storage._Controller := Controller; //интрефейс Label1.Caption := 'Параметры ротора'; Label2.Caption := 'Параметры прибора'; Label3.Caption := 'Параметры исследования'; Label4.Caption := 'Грфик зависимости выходного угла от веремни'; LabeledEdit1.EditLabel.Caption := 'Плотность, г/см3'; LabeledEdit2.EditLabel.Caption := 'Высота, см'; LabeledEdit3.EditLabel.Caption := 'Радиус, см'; LabeledEdit4.EditLabel.Caption := 'Скорость вращения, об/мин'; LabeledEdit5.EditLabel.Caption := 'Демпфирование, Н*с'; LabeledEdit6.EditLabel.Caption := 'Скорость основания, рад/сек'; LabeledEdit7.EditLabel.Caption := 'Время, сек'; LabeledEdit1.OnExit := InputParam; //обработка ввода LabeledEdit2.OnExit := InputParam; LabeledEdit3.OnExit := InputParam; LabeledEdit4.OnExit := InputParam; LabeledEdit5.OnExit := InputParam; LabeledEdit6.OnExit := InputParam; LabeledEdit7.OnExit := InputParam; Button1.OnClick := Border.StartBtn; //Старт //начальные данные.. _Controller.GetData (t); Border.LabeledEdit1.Text := t[0]; //плотность гр на см3 Border.LabeledEdit2.Text := t[1]; //Высота см Border.LabeledEdit3.Text := t[2]; //радиус основания см Border.LabeledEdit4.Text := t[3]; //скорость вращения об в мин Border.LabeledEdit5.Text := t[4]; //демпфирование Border.LabeledEdit6.Text := t[5]; //скорость основания рад в сек Border.LabeledEdit7.Text := t[6]; //время сек end; procedure TBorder.InputParam (Sender: TObject); //обработка ввода данных в TChart var V : real; code : integer; begin with sender as TLabeledEdit do begin Val (Text, v, code); if code <> 0 then Text := 'введите число!'; end; end; procedure TBorder.StartBtn(Sender: TObject); //старт var ro, h, r, w, db, w0, t : real; begin //введеные параметры ro := StrtoFloat(Border.LabeledEdit1.Text); h := StrtoFloat(Border.LabeledEdit2.Text); r := StrtoFloat(Border.LabeledEdit3.Text); w := StrtoFloat(Border.LabeledEdit4.Text); db := StrtoFloat(Border.LabeledEdit5.Text); W0 := StrtoFloat(Border.LabeledEdit6.Text); t := StrtoFloat(Border.LabeledEdit7.Text); Border._Controller.Calc (ro, h, r, w, db, w0, t); end; procedure TBorder.Plot (betta: real; time: integer); //построение граффиков begin Border.Chart1.Series[0].AddXY(time, betta); end; function TBorder.GetOutName (old : string) : string; begin //настройка диалога сохранения Border.saveTextFileDialog1.InitialDir := old; Border.saveTextFileDialog1.Filter := 'Text file|*.txt'; Border.saveTextFileDialog1.DefaultExt := 'txt'; Border.saveTextFileDialog1.FilterIndex := 1; ShowMessage ('Выходной файл...'); if Border.saveTextFileDialog1.Execute then Result := Border.SaveTextFileDialog1.FileName else Result := old; end; procedure TControl.GetData (var t: array of string); var today : TDatetime; outname : string; result : boolean; begin today := Now; Controller._Storage.LoadFromFile (t, outname, result); if not result then begin t[0] := '30'; t[1] := '4'; t[2] := '2'; t[3] := '6000'; t[4] := '2'; t[5] := '0,05'; t[6] := '100'; OutName := GetCurrentDir + '\' + DateToStr(today) + '.txt'; end; Controller._Storage.output := OutName; end; procedure TControl.Calc (ro, h, r, w, db, w0, t : real); //вычисление var Cz, Hg, m, betta : real; time : integer; begin _Border.Chart1.Series[0].Clear; //вычисление функции m := ro * pi * sqr(r) * h; //гр Cz := m * sqr(r) / 2; //гр * см2 Hg := Cz * w * 2 * pi / 360 / 60; // гр * см2 * рад / с for time := 0 to Trunc(t) do begin betta := Hg / (Db * 1000 * 100) * W0 * time * 57.3; //град в сек Border.Plot (betta, time); //построение графика end; //получение имени вых. файла _Storage.output := _Border.GetOutName (_Storage.output); //запись выходных файлов настроек и вычислений _Storage.SaveData (ro, h, r, w, db, w0, t, betta); end; procedure TControl.Finish(); //завершение работы begin if Assigned(FFinish) then FFinish(Self); // Cтандартное по закрытию end; procedure TStorage.LoadFromFile (var t: array of string; var OutName : string; result : boolean); var param : TextFile; i : integer; begin Result := false; if FileExists ('parametres.txt') then begin //с предыдущего расчета Result:=true; AssignFile (param, 'parametres.txt'); Reset (param); i := 0; while (not EOF(param)) and (i<=6) do begin readln (param, t[i]); inc (i); end; if not EOF (param) then readln (param, OutName); CloseFile (param); end; end; procedure TStorage.SaveData(ro: Real; h: Real; r: Real; w: Real; //запись в файл db: Real; w0: Real; t: Real; betta: Real); var input, output : TextFile; begin //сохранение настроек AssignFile (input, 'input.txt'); Rewrite (input); writeln (input, floattostr (ro)); writeln (input, floattostr (h)); writeln (input, floattostr (r)); writeln (input, floattostr (w)); writeln (input, floattostr (db)); writeln (input, floattostr (w0)); writeln (input, floattostr (t)); writeln (input, Storage.output); CloseFile (input); //сохранение выхода if FileExists (Storage.output) then begin AssignFile (output, Storage.output); Append (output); Writeln (output, floattostr (ro) + '|' + floattostr (h)+ '|' + floattostr (r) + '|' + floattostr (w) + '|' + floattostr (db) + '|' + floattostr (w0) + '|' + floattostr (t) + '==>' + floattostr (betta)); CloseFile (output); end else begin AssignFile (output, Storage.output); Rewrite (output); Writeln (output, floattostr (ro) + '|' + floattostr (h)+ '|' + floattostr (r) + '|' + floattostr (w) + '|' + floattostr (db) + '|' + floattostr (w0) + '|' + floattostr (t) + '==>' + floattostr (betta)); CloseFile (output); end; ShowMessage ('Данные вычисления сохранены в ' + Storage.output); end; end.