Показать сообщение отдельно
  #1  
Старый 10.04.2011, 17:51
Nicole Nicole вне форума
Прохожий
 
Регистрация: 10.04.2011
Сообщения: 1
Репутация: 10
Восклицание Массив и число Фибоначчи

Есть прога по выводу главной диагонали матрицы. Теперь надо сделать так, чтобы на этой диагонали прога находила первое (по порядку) число Фибоначчи.
Пробовал непременно выделять из stringgrid элементы, переводить их в числа и сравнивать на пример равенства сумме предыдущих, но выдается злополучная ошибка " is not a valid integer value.
Надо, чтобы само число Фибоначчи при его наличии показывалось в LabeledEdit1 и выскакивал showmessage('найдено число фибоначчи'). В случае отсутствия - showmessage('число фибоначчи не найдено').
Сможет кто-нибудь помочь?

Код:
unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Spin, Grids, ExtCtrls;

type
  TForm3 = class(TForm)
    Button1: TButton;
    StringGrid1: TStringGrid;
    SpinEdit1: TSpinEdit;
    Label1: TLabel;
    Button2: TButton;
    Button3: TButton;
    Label2: TLabel;
    Button4: TButton;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    StringGrid2: TStringGrid;
    Button5: TButton;
    StringGrid3: TStringGrid;
    LabeledEdit1: TLabeledEdit;
    procedure Button1Click(Sender: TObject);
    procedure SpinEdit1Change(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
Form3.Hide;
Form2.Show;
end;

procedure TForm3.SpinEdit1Change(Sender: TObject);
var
   i,j:integer;
begin
StringGrid1.ColCount:=SpinEdit1.Value+1;
StringGrid1.Width:=StringGrid1.ColCount*66;
if StringGrid1.Width>66*2 then StringGrid1.Width:=66*11;
for j:=1 to StringGrid1.ColCount do
begin
StringGrid1.Cells[j,0]:=IntToStr(j);
end;
StringGrid1.RowCount:=SpinEdit1.Value+1;
StringGrid1.Height:=StringGrid1.RowCount*26;
if StringGrid1.Height>26*2 then StringGrid1.Height:=26*11;
for i:=1 to StringGrid1.RowCount do
begin
StringGrid1.Cells[0,i]:=IntToStr(i);
end;
end;

procedure TForm3.Button2Click(Sender: TObject);
var
   i,j:integer;
begin
i:=0;
for j:=0 to StringGrid1.ColCount-1 do
begin
StringGrid2.Cells[j,i]:=StringGrid1.Cells[j+1,j+1];
StringGrid2.ColCount:=StringGrid1.ColCount-1;
end;
end;

procedure TForm3.Button5Click(Sender: TObject);
var
   i,j:integer;
begin
for i:=1 to StringGrid1.RowCount-1 do
for j:=1 to StringGrid1.ColCount-1 do
StringGrid1.Cells[j,i]:=IntToStr(random(10));
end;

end.
Ответить с цитированием