unit Unit5;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, ValEdit;

type
  TForm5 = class(TForm)
    ValueListEditor1: TValueListEditor;
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ValueListEditor1Click(Sender: TObject);
    {procedure ValueListEditor1StringsChange(Sender: TObject); }
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form5: TForm5;
  mass:array[0..1,0..50] of string[100];

   procedure change(var s:string;substrdel,substrins:string);


implementation
Uses Mainmodule, unit2;
{$R *.dfm}


procedure TForm5.Button1Click(Sender: TObject);
var i,n,row:integer;
fileway,filename:string;
fs:Tfilestream;
begin
n:=ValuelistEditor1.RowCount;
row:=form2.StringGrid1.Row;
for i:=1 to n-1 do
begin
{ValuelistEditor1.Strings.ValueFromIndex[i]:='привет';}
{mass[0,i]:=Valuelisteditor1.Keys[i]; }
mass[1,i]:=Valuelisteditor1.Values[Valuelisteditor1.Keys[i]];
end;
filename:=form2.StringGrid1.Cells[0,row];
change(filename,'/','-');
fileway:=ExtractFilepath(Application.ExeName)+'TechnicalDatafi\'+filename+'.dat';//Запись файла с тех. данными агрегата
  fs:=TFileStream.Create(fileway,fmCreate);
  fs.write(mass,sizeof(mass));
  fs.Free;
Form2.StringGrid1.Cells[9,row]:='TechnicalDatafi\'+ValuelistEditor1.Strings.ValueFromIndex[0]+'.dat';
Close;
end;

procedure TForm5.FormShow(Sender: TObject);
var n,i,row:integer;
fileway,filename:string;
fs:Tfilestream;
begin
n:=ValuelistEditor1.RowCount;
row:=form2.StringGrid1.Row;
filename:=form2.StringGrid1.Cells[0,row];
change(filename,'/','-');
fileway:=ExtractFilepath(Application.ExeName)+'TechnicalDatafi\'+filename+'.dat'; //

if fileExists(fileway) then
begin
  fs:=TFileStream.Create(fileway,fmOpenRead);
  fs.read(mass,sizeof(mass));
  fs.Free;
for i:=1 to n-1 do
begin
{ValuelistEditor1.Strings.ValueFromIndex[i]:='привет';}
Valuelisteditor1.Values[Valuelisteditor1.Keys[i]]:=mass[1,i];
end;
end;



Valuelisteditor1.Values[Valuelisteditor1.Keys[1]]:=filename; //название агрегата
Valuelisteditor1.Values[Valuelisteditor1.Keys[4]]:=form2.StringGrid1.Cells[1,row]; //название компрессора
Valuelisteditor1.Values[Valuelisteditor1.Keys[6]]:=form2.StringGrid1.Cells[2,row]; //название конденсатора
Valuelisteditor1.Values[Valuelisteditor1.Keys[5]]:=form2.StringGrid1.Cells[5,row]; //количество компрессоров
Valuelisteditor1.Values[Valuelisteditor1.Keys[7]]:=form2.StringGrid1.Cells[6,row]; //количество конденсаторов
Valuelisteditor1.Values[Valuelisteditor1.Keys[9]]:=cs.pol[strtoint(form2.StringGrid1.Cells[4,row])];
Valuelisteditor1.Values[Valuelisteditor1.Keys[8]]:=inttostr(cs.Numfuns[strtoint(form2.StringGrid1.Cells[4,row])]);
Valuelisteditor1.Values[Valuelisteditor1.Keys[14]]:=floattostr(cs.FunsCurrent[strtoint(form2.StringGrid1.Cells[4,row])])+' X '+inttostr(cs.Numfuns[strtoint(form2.StringGrid1.Cells[4,row])]*strtoint(form2.StringGrid1.Cells[6,row]));
Valuelisteditor1.Values[Valuelisteditor1.Keys[13]]:=floattostr(cs.Funscap[strtoint(form2.StringGrid1.Cells[4,row])]*cs.Numfuns[strtoint(form2.StringGrid1.Cells[4,row])]*strtoint(form2.StringGrid1.Cells[6,row]));

{for i:=0 to n-2 do
begin
ValuelistEditor1.Strings.ValueFromIndex[i]:='привет';
end;}
end;
 procedure change(var s:string;substrdel,substrins:string);
 var k:integer;
 begin
 k:=pos(substrdel,s);
 if k<>0 then
 begin
 delete(s,k,length(substrdel));
 insert(substrins,s,k);
 end;

 end;

{procedure TForm5.ValueListEditor1StringsChange(Sender: TObject);
var row:integer;
begin
row:=form2.StringGrid1.Row;
{Valuelisteditor1.Values[Valuelisteditor1.Keys[15]]:=floattostr(strtofloatdef(Valuelisteditor1.Values[Valuelisteditor1.Keys[10]],0)+strtofloatdef(Valuelisteditor1.Values[Valuelisteditor1.Keys[12]],0));
Valuelisteditor1.Values[Valuelisteditor1.Keys[16]]:=floattostr(strtofloatdef(Valuelisteditor1.Values[Valuelisteditor1.Keys[11]],0)+cs.FunsCurrent[strtoint(form2.StringGrid1.Cells[4,row])]*cs.Numfuns[strtoint(form2.StringGrid1.Cells[4,row])]*strtoint(form2.StringGrid1.Cells[6,row]));
end;}

procedure TForm5.ValueListEditor1Click(Sender: TObject);
var row:integer;
begin
row:=form2.StringGrid1.Row;
if valuelisteditor1.Row=15 then
begin
Valuelisteditor1.Values[Valuelisteditor1.Keys[15]]:=floattostr(strtofloatdef(Valuelisteditor1.Values[Valuelisteditor1.Keys[13]],0)+strtofloatdef(Valuelisteditor1.Values[Valuelisteditor1.Keys[11]],0));// Общая потребляемая мощность
end;
if valuelisteditor1.Row=16 then
begin
Valuelisteditor1.Values[Valuelisteditor1.Keys[16]]:=floattostr(strtofloatdef(Valuelisteditor1.Values[Valuelisteditor1.Keys[12]],0)+cs.FunsCurrent[strtoint(form2.StringGrid1.Cells[4,row])]*cs.Numfuns[strtoint(form2.StringGrid1.Cells[4,row])]*strtoint(form2.StringGrid1.Cells[6,row]));
end;
end;

end.
