


Delphi 10, помогите с программой
Что-то пытаюсь сделать чтобы все данные в таблице 1 записывались в текстовый файл, оно записывает только игрик, а икс не записывается, кто-то может помочь с этим?
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids,
VclTee.TeeGDIPlus, VCLTee.TeEngine, VCLTee.Series, Vcl.ExtCtrls,
VCLTee.TeeProcs, VCLTee.Chart;
type
TForm2 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Chart1: TChart;
Series1: TLineSeries;
StringGrid2: TStringGrid;
Label1: TLabel;
StringGrid3: TStringGrid;
StringGrid4: TStringGrid;
StringGrid5: TStringGrid;
Button2: TButton;
SaveDialog1: TSaveDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
function f(a, x: real):real;
begin
result:=(1/sqrt(1+sqr(a*x)));
end;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var a, x, xn, xk, hx: real;
k, n: integer;
begin
//Настройка таблица и ее шапки
with StringGrid1 do
begin
fixedcols:=0;
colcount:=2;
rowcount:=2;
cells[0,0]:='x';
cells[1,0]:='y';
end;
a:=strtofloat(edit1.Text);
xn:=strtofloat(edit2.Text);
xk:=strtofloat(edit3.Text);
//Шаг
hx:=0.1;
n:=round((xk-xn)/hx);
//Очистка графика
series1.Clear;
for k:=0 to n do
begin
x:=xn+k*hx;
with StringGrid1 do
begin
cells[0,k+1]:=FormatFloat('0.00', x);
cells[1,k+1]:=FormatFloat('0.0000', f(a,x));
if k<n then rowcount:=rowcount+1;
end;
end;
with StringGrid2 do
begin
fixedcols:=0;
colcount:=2;
rowcount:=2;
cells[0,0]:='x';
cells[1,0]:='y';
end;
for k:=0 to n do
begin
x:=xn+k*hx;
with StringGrid2 do
begin
cells[0,k+1]:=FormatFloat('0.00', x);
cells[1,k+1]:=FormatFloat('0.0000', f(a+0.1,x));
if k<n then rowcount:=rowcount+1;
end;
end;
with StringGrid3 do
begin
fixedcols:=0;
colcount:=2;
rowcount:=2;
cells[0,0]:='x';
cells[1,0]:='y';
end;
for k:=0 to n do
begin
x:=xn+k*hx;
with StringGrid3 do
begin
cells[0,k+1]:=FormatFloat('0.00', x);
cells[1,k+1]:=FormatFloat('0.0000', f(a+0.2,x));
if k<n then rowcount:=rowcount+1;
end;
end;
with StringGrid4 do
begin
fixedcols:=0;
colcount:=2;
rowcount:=2;
cells[0,0]:='x';
cells[1,0]:='y';
end;
for k:=0 to n do
begin
x:=xn+k*hx;
with StringGrid4 do
begin
cells[0,k+1]:=FormatFloat('0.00', x);
cells[1,k+1]:=FormatFloat('0.0000', f(a+0.3,x));
if k<n then rowcount:=rowcount+1;
end;
end;
with StringGrid5 do
begin
fixedcols:=0;
colcount:=2;
rowcount:=2;
cells[0,0]:='x';
cells[1,0]:='y';
end;
for k:=0 to n do
begin
x:=xn+k*hx;
with StringGrid5 do
begin
cells[0,k+1]:=FormatFloat('0.00', x);
cells[1,k+1]:=FormatFloat('0.0000', f(a+0.4,x));
if k<n then rowcount:=rowcount+1;
end;
end;
//Построение графика по данным из таблицы
for k:=1 to StringGrid1.RowCount-1 do
Series1.AddXY(strtofloat(StringGrid1.Cells[0,k]),strtofloat(StringGrid1.Cells[1,k]),'',clRed);
end;
procedure TForm2.Button2Click(Sender: TObject);
Var f: TextFile;
i, k: Integer;
s,s1:string;
begin
if SaveDialog1.Execute //выполняется диалог 'Сохранить как'
then begin //введено имя файла
AssignFile(f,SaveDialog1.FileName);
Rewrite(f); // создаем файл
Append(f); // открываем файл
for i:=1 to StringGrid1.RowCount-1 do
begin
for k:=1 to StringGrid1.colcount-1 do
begin
s1 := s1 + ' ' + StringGrid1.cells[k, i];
end;
Writeln(f, s1); // пишем значения ячеек
s1 := '';
end;
CloseFile(f);
end;
end;
end.
А нафига было разводить антимонию с паскалевскими файлами? Чем конкретно тебя не устроил метод TStringGrid.Rows.SaveToFile ?