Цитата:
Сообщение от MegaPiha
Много мелких недочетов.
1. В 1 м коде три лишних begin end. Ну это так к слову о сокращении размеров программы.
2. В кодах A, B, C не задан n/
3. В кодах B и C надо указывать вывод не в StringGrid1 а в соответственно StringGrid5, StringGrid6
4. К вопросу об сокращении кода - ИМХО ничего сокращать не надо.
|
Спасибо.. ну на счет 1 - тут даже не буду спорить - просто соглашусь  - но убирать уже че-то стремно....
2 - n задана глобально - просто тут не видно
3 - То понятно - просто скопировал коды из случая, когда в 1 все выводилось
4 - Уже и я так думаю, что не надо  я рад хоть это работает...
ну теперь у меня осталась 1 задача - нужно эту прогу - код ниже сохранить в файле - причем что бы можно было самому указывать к нему путь - и потом, что бы при нажатии на батон можно было открыть тот файл и считать из него в стринггрид - это вообще реально сделать?  Если да - то помогите плиз, ато я толком так и не понял как просто сохранять, а им подавай что бы через обзор
вот код:
Код:
unit Unit5;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Math;
type
TForm5 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
StringGrid3: TStringGrid;
StringGrid2: TStringGrid;
StringGrid4: TStringGrid;
StringGrid5: TStringGrid;
StringGrid6: TStringGrid;
Button6: TButton;
Label5: TLabel;
Label8: TLabel;
Button10: TButton;
Label10: TLabel;
Label11: TLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label7: TLabel;
Label6: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form5: TForm5;
Y:array of array of real;
C:array of array of real;
A:array of array of real;
B:array of array of real;
n:integer;
m:integer;
k:integer;
l:integer;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm5.Button1Click(Sender: TObject);
begin
Form1.Show;
Form5.Close;
end;
procedure TForm5.Button6Click(Sender: TObject);
var i,j,t:integer;
tmp:real;
begin
begin
n:=7;
m:=11;
setlength(C,n,m);
stringgrid3.RowCount:=n;
stringgrid3.ColCount:=m;
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
C[i,j]:=cos(14*j+1);
stringgrid3.Cells[j,i]:=FormatFloat('0.00',C[i,j]);
end;
end;
begin
m:=stringgrid3.ColCount;
k:=0;
l:=10;
for i:=0 to n-1 do
begin
tmp:=C[i,k];
C[i,k]:=C[i,l];
C[i,l]:=tmp;
end;
for t:=0 to n-1 do
for j:=0 to m-1 do
stringgrid6.Cells[j,t]:=FormatFloat('0.00',C[t,j]);
end;
begin
n:=8;
m:=15;
setlength(B,n,m);
stringgrid2.RowCount:=n;
stringgrid2.ColCount:=m;
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
B[i,j]:=sin(3.2*j+4.2)+power(exp(1),tan(i));
stringgrid2.Cells[j,i]:=FormatFloat('0.00',B[i,j]);
end;
end;
begin
m:=stringgrid2.ColCount;
k:=2;
l:=4;
for i:=0 to n-1 do
begin
tmp:=B[i,k];
B[i,k]:=B[i,l];
B[i,l]:=tmp;
end;
for t:=0 to n-1 do
for j:=0 to m-1 do
stringgrid5.Cells[j,t]:=FormatFloat('0.00',B[t,j]);
end;
begin
n:=12;
m:=9;
setlength(A,n,m);
stringgrid1.RowCount:=n;
stringgrid1.ColCount:=m;
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
A[i,j]:=sin(j)/cos(j)+exp(cos(i));;
stringgrid1.Cells[j,i]:=FormatFloat('0.00',A[i,j]);
end;
end;
begin
m:=stringgrid1.ColCount;
k:=0;
l:=8;
for i:=0 to n-1 do
begin
tmp:=A[i,k];
A[i,k]:=A[i,l];
A[i,l]:=tmp;
end;
for t:=0 to n-1 do
for j:=0 to m-1 do
stringgrid4.Cells[j,t]:=FormatFloat('0.00',A[t,j]);
end;
end;
procedure TForm5.Button10Click(Sender: TObject);
var
i,j:integer;
begin
begin
for i:=0 to StringGrid6.ColCount-1 do
for j:=0 to StringGrid6.RowCount-1 do
StringGrid6.Cells[i,j]:='';
end;
begin
for i:=0 to StringGrid5.ColCount-1 do
for j:=0 to StringGrid5.RowCount-1 do
StringGrid5.Cells[i,j]:='';
end;
begin
for i:=0 to StringGrid4.ColCount-1 do
for j:=0 to StringGrid4.RowCount-1 do
StringGrid4.Cells[i,j]:='';
end;
begin
for i:=0 to StringGrid3.ColCount-1 do
for j:=0 to StringGrid3.RowCount-1 do
StringGrid3.Cells[i,j]:='';
end;
begin
for i:=0 to StringGrid2.ColCount-1 do
for j:=0 to StringGrid2.RowCount-1 do
StringGrid2.Cells[i,j]:='';
end;
begin
for i:=0 to StringGrid1.ColCount-1 do
for j:=0 to StringGrid1.RowCount-1 do
StringGrid1.Cells[i,j]:='';
end;
end;
end.
Спасибо...
|