Задача следующая.Необходимо из мемо записать последовательность действительных чисел отделенных пробелов в файл, а затем из файла прочитать эти числа и занести в список после при помощи списка вычислить число (x1-x2n)*(x3-x(2n-2))*...*(x(2n-1)-x2).
Я написал код но у меня в цикл не запускается подскажите что делать.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
OD1: TOpenDialog;
SD1: TSaveDialog;
M1: TMemo;
M2: TMemo;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
PListElement=^TListElement;
TListElement=record
val:string;
next:PListElement;
end;
Stack=^El;
El = Record
inf : string;
next : Stack;
end;
var
Form1: TForm1;
pHead,zn1:PListElement; pHead1,zn2:Stack; L:PListElement; p:integer;
implementation
{$R *.dfm}
procedure addElement(var pListHead:PListElement; var fp:textfile); //добавление элемента
var p, q : PListElement;
begin
reset(fp);
new(L);
read(fp, L.val);
p:=L;
while not eof(fp) do
begin
new(q);
read(fp, q.val);
p.next:=q;
p:=q;
inc(p);
end;
p.next:=nil;
end;
Procedure InStak(Var Beg:Stack; var fpp:textfile); //добавление элемента в Стэк
Var x:Stack;
Begin
reset(fpp);
while not eof(fpp) do
begin
New(X);
read(fpp, X^.inf);
X^.next:=Beg;
Beg:=X;
end;
End;
procedure TForm1.Button1Click(Sender: TObject); //Занесение строки в файл
var s:string; i,p:integer; f:textfile;
begin
if SD1.Execute=true then
begin
M1.Lines.SaveToFile(SD1.FileName);
M1.Lines.Clear;
end;
end;
procedure TForm1.Button2Click(Sender: TObject); //Извлечение строки из файла
var s,s1:string; f1,f:textfile; i,p:integer; c1, c2,c3:real;
begin
s:='';
if OD1.Execute then
begin
AssignFile(f, OD1.FileName);
addElement(pHead,f);
InStak(pHead1, f);
CloseFile(f);
end;
c1:=1;
p:=1;
zn1:=pHead;
zn2:=pHead1;
i:=1;
for i:=p div 2 downto 1 do
begin
if not ((zn1.val=' ') and (zn2.inf=' ')) then
c2:=StrToFloat(zn1.val);
c3:=StrToFloat(zn2.inf);
if i<>1 then
begin
c1:=c1*(c2-c3);
zn1:=zn1^.next^.next;
zn2:=zn2^.next^.next;
end
else
c1:=c1*(c2-c3);
end;
s:=FloatToStr(c1);
if SD1.Execute=true then
begin
AssignFile(f1, SD1.FileName);
rewrite(f1);
writeln(f1, s);
CloseFile(f1);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if OD1.Execute=true then
begin
M2.Lines.LoadFromFile(OD1.FileName);
end;
end;
end.