
28.07.2014, 11:32
|
Новичок
|
|
Регистрация: 05.04.2010
Сообщения: 85
Репутация: 10
|
|
исправил код. теперь все работает.
Код:
unit USPS;
interface
uses
Windows, Messages, SysUtils, Classes, Forms;
type
TspsStroka=class
Npr, Npk, X, Y:{array of }Real;
constructor create();
procedure read(str:string);
end;
TSPS=class
name:string;
SpsStrokaCount:Cardinal;
SizeOfmas:Cardinal;
spsStroki:array {[0..99999]} of TspsStroka;
constructor create(openname:string);
procedure read({str:string}openname:string);
procedure writetofile(savename:string);
end;
implementation
constructor TspsStroka.create();
begin
Npr:=0;
Npk:=0;
X:=0;
Y:=0;
end;
constructor TSPS.create(openname:string);
var
t:TStringList;
i:Integer;
str:string;
begin
name:=openname;
SpsStrokaCount:=0;
t:=TStringList.Create;
t.LoadFromFile(openname);
SizeOfmas:=0;
for i:=0 to t.Count-1 do begin
Application.ProcessMessages();
str:=t[i];
if str[1]='H' then Continue;
inc(SizeOfmas);
end;
SetLength(spsStroki,SizeOfmas);
t.Free;
end;
procedure TspsStroka.read(str:string);
begin
Npr:=strtofloat(copy(str,2,16));
Npk:=strtofloat(copy(str,18,8));
X:=strtofloat(copy(str,47,9));
Y:=strtofloat(copy(str,56,10));
end;
procedure tsps.read({str:string}openname:string);
var
i:Cardinal;
str:string;
t:TStringList;
begin
t:=TStringList.Create;
t.LoadFromFile(openname);
for i:=0 to t.Count-1 do begin
Application.ProcessMessages();
str:=t[i];
if str[1]='H' then Continue;
spsStroki[SpsStrokaCount]:=TspsStroka.create();
spsStroki[SpsStrokaCount].read(str);
Inc(SpsStrokaCount);
end;
t.Free;
end;
procedure TSPS.writetofile(savename:string);
var
ft:TStringList;
i:Integer;
str:string;
begin
ft:=TStringList.Create;
for i:=0 to SizeOfmas-1 do begin
Application.ProcessMessages();
str:=floatToStr(spsStroki[i].Npr)+#9+floatToStr(spsStroki[i].Npk)+#9+floatToStr(spsStroki[i].X)+#9+floatToStr(spsStroki[i].Y);
ft.Add(str);
str:='';
end;
ft.SaveToFile(savename);
ft.Free;
end;
end.
|