N
N
NikaBestyjeva2020-05-31 23:01:30
Lazarus
NikaBestyjeva, 2020-05-31 23:01:30

What is wrong with the export and import code, or how to remake it more rationally?

unit Unit1;

{$mode objfpc}{$H+}

interface


uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Grids, StdCtrls,
  ExtCtrls,Menus;

type  obmen=RECORD
  name:string;
  kyrs1:integer;
  kyrs2:integer;
  adres :string;
  tel:word;
end;


  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    LabeledEdit1: TLabeledEdit;
    OpenDialog1: TOpenDialog;
    StringGrid1: TStringGrid;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure LabeledEdit1Change(Sender: TObject);
  private
    function FindMinSelIndex: integer;
    function FindMaxBuyIndex: integer;
  public

  end;

var
  Form1: TForm1;
       x: array [0..100] of obmen;
  i: integer;

  j:array [0..100] of obmen;

f2: textfile;

f3: file;

f4:file of integer;

f5:file of char;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
  begin

  StringGrid1.Cells[0, 0] := 'Название';
  StringGrid1.Cells[1, 0] := 'Курс покупки';
  StringGrid1.Cells[2, 0] := 'Курс продажи';
  StringGrid1.Cells[3, 0] := 'Адрес';
  StringGrid1.Cells[4, 0] := 'Телефон';
end;

procedure TForm1.LabeledEdit1Change(Sender: TObject);
begin
  StringGrid1.RowCount := StrToInt(LabeledEdit1.Text) + 1;
end;



procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
begin
  i := FindMinSelIndex;
  ShowMessage(StringGrid1.Cells[0, i] + ', ' + StringGrid1.Cells[3, i] + ', ' + StringGrid1.Cells[4, i]);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  i: integer;
begin
  i := FindMaxBuyIndex;
  ShowMessage(StringGrid1.Cells[0, i] + ', ' + StringGrid1.Cells[3, i] + ', ' + StringGrid1.Cells[4, i]);
end;
  procedure TForm1.Button3Click(Sender: TObject);         //ЭКСПОРТ

var f:textfile;
 j:integer ;
 x:integer;

begin
if OpenDialog1.Execute then
begin

AssignFile(f, OpenDialog1.FileName);
rewrite(f);
writeln(f,'Название / Курс покупки / Курс продажи/ Адрес  / Телефон');
for j:=1 to i do
write(f,x[j-0].name+' ');
write(f,x[j-1].kurs1+' ');
write(f,x[j-1].kyrs2+' ');
write(f,x[j-1].adres+' ');
writeln(f,x[j-1].tel+' ');
end;
closefile(f);
end;


procedure TForm1.Button4Click(Sender: TObject);      //ИПОРТ
  var j,obmen:integer; f:textfile; s:string;

j:=1;
if OpenDialog1.Execute then
begin

AssignFile(f, OpenDialog1.FileName); Reset(f);
readln(f, s);

//не находит или не удаляет пробелы
//showmessage(s);

s:='';
while not eof(f) do begin
readln(f, s);

//showmessage(s);
obmen:=UTF8Pos(' ', s);
x[j].name :=UTF8Copy(s,1,obmen-1); // showmessage('4'+x[j].nommarsh+'g');
UTF8Delete(s, 1, obmen);
// showmessage(s);
obmen:=UTF8Pos(' ', s);
x[j].kyrs1 :=UTF8Copy(s,1,obmen-1);
UTF8Delete(s, 1, obmen);
// showmessage(s);

obmen:=UTF8Pos(' ', s);
x[j].kyrs2:=UTF8Copy(s,1,obmen-1);
UTF8Delete(s, 1,obmen);
// showmessage(s);
// showmessage(s);
obmen:=UTF8Pos(' ', s);
x[j].tel :=UTF8Copy(s,1,obmen-1);
UTF8Delete(s, 1, obmen);
// showmessage(s);
obmen:=UTF8Pos(' ', s);
x[j].adres :=UTF8Copy(s,1,obmen-1);
j:=j+1;
end;
i:=j;
closefile(f);
end;
end;



function TForm1.FindMinSelIndex: integer;
var
  i, rc, imin: integer;
begin
  imin := 1;
  rc := StringGrid1.RowCount;
  for i:=2 to rc-1 do
    if StrToFloat(StringGrid1.Cells[2, i]) < StrToFloat(StringGrid1.Cells[2, imin]) then
      imin := i;

  FindMinSelIndex := imin;
end;

function TForm1.FindMaxBuyIndex: integer;
var
  i, rc, imax: integer;
begin
  imax := 1;
  rc := StringGrid1.RowCount;
  for i:=2 to rc-1 do
    if StrToFloat(StringGrid1.Cells[1, i]) > StrToFloat(StringGrid1.Cells[1, imax]) then
      imax := i;

  FindMaxBuyIndex := imax;
end;

end.

5ed40cc03cf6b405253250.jpeg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question