Che cosa c'è di sbagliato in questo codice?
codice:
type
Stati = (sBianco, sNero);
TElemento = class
Immagine: TImage;
Stato: Stati;
procedure OnImageClick(Sender: TObject);
end;
const
Max = 3;
var
Form1: TForm1;
Elementi: array [1..Max,1..Max] of TElemento;
implementation
{$R *.dfm}
procedure TElemento.OnImageClick(Sender: TObject);
begin
showmessage('');
end;
procedure DrawTheState(Elm: TElemento);
begin
//Elm.Immagine.Canvas.Brush.Color := Col;
Elm.Immagine.Canvas.Ellipse(0,0,29,29);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
J: Integer;
begin
for J := 1 to MAX do
for I := 1 to MAX do
begin
Elementi[I,J].Immagine:= TImage.Create(Self); // ***QUI C'E' L'ERRORE***
Elementi[I,J].Immagine.Parent := Self;
Elementi[I,J].Immagine.Width := 30;
Elementi[I,J].Immagine.Height := 30;
Elementi[I,J].Immagine.Left := I*32+100;
Elementi[I,J].Immagine.Top := J*32+100;
Elementi[I,J].Immagine.OnClick := Elementi[I,J].OnImageClick;
Elementi[I,J].Stato := sBianco;
DrawTheState(Elementi[I,J]);
end;
end;
end.
Come mai viene lanciata un'eccezione da TImage.Create alla riga segnalata? Che ho sbagliato?
Il programma dovrebbe creare e mostrare a schermo 9 TElemento e mostrare a schermo, in posizioni 3x3, la relativa immagine.
Aiutatemi per favore... non capisco...