N
N
NikaBestyjeva2020-05-29 21:16:43
Lazarus
NikaBestyjeva, 2020-05-29 21:16:43

How to solve the problem with errors in the export and import code?

unit Unit1;

{$mode objfpc}{$H+}

interface

uses

Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Grids, StdCtrls,

ExtCtrls;

type exchange=RECORD

name:string;

kyrs1:string;

kyrs2:string;

addresses:string;

tel:string;

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;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);

begin

StringGrid1.Cells[0, 0] := 'Name';

StringGrid1.Cells[1, 0] := 'Buy rate';

StringGrid1.Cells[2, 0] := 'Sale rate';

StringGrid1.Cells[3, 0] := 'Address';

StringGrid1.Cells[4, 0] := 'Phone';

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); //EXPORT

var f:textfile;

j:integer;

x:integer;

begin

if OpenDialog1.Execute then

begin

AssignFile(f, OpenDialog1.FileName);

rewrite(f);

writeln(f,'Name / Buy Rate / Sell Rate / Address / Phone');

for j:=1 to i do

write(f,x[j-1].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;

end;

procedure TForm1.Button4Click(Sender: TObject); //IMPORT

var j,obmen:integer; f:textfile; s:string;

j:=0;

if OpenDialog1.Execute then

begin

AssignFile(f, OpenDialog1.FileName); reset(f);

readln(f, s);

//does not find or remove spaces

//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, exchange);

// showmessage(s);

obmen:=UTF8Pos(' ', s);

x[j].kyrs1 :=UTF8Copy(s,1,obmen-1);

UTF8Delete(s, 1, exchange);

// 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,

UTF8Delete(s, 1, exchange);

// 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.

5ed1513d39c18306117515.jpeg

https://yadi.sk/d/6QQW6UP5dTD47A link to the program

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