This is my whole code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Images: array[0..29,0..39] of TImage; //array
implementation
{$R *.dfm}
//form create
procedure TForm1.FormCreate(Sender: TObject);
var xx,yy: Integer; //local variables
begin
for xx:=0 to 29 do
for yy:=0 to 39 do
begin
Images[xx,yy]:=Timage.Create(Form1);
Images[xx,yy].Canvas.Rectangle(0,0,17,17);
Images[xx,yy].Left:=xx*16;
Images[xx,yy].Top:=yy*16;
end;
end;
end.
And I always get the error : "Project Project1.exe has raised the exception class EClassNotFound with message "TImage not found". Process stopped. Use step or run to continue "
I have tried other codes on the internet like:
Delphi: TImage.Create causes Access violation
http://www.delphi-central.com/tutorials/memory_game_2.aspx
Nothing helps! Why is this happening?
Thank you.
TImage.Create( Self)
. Never use a form variable as a reference. – LU RDTForm1
. What will happen ? The images will be tied to the global Form1 parameter and this is not a good practice. In fact very bad. The Images var should be declared within the form class. – LU RDTForm1
on the fly (in code) and assign it to a variable of a different name, you're in trouble. For instance:var TheForm: TForm1;begin TheForm := TForm1.Create(nil); try TheForm.ShowModal; finally TheForm.Free; end;
. If at the point ofTheForm
being constructed, if there's not already an instance ofForm1
created, you get an AV. Always useSelf
, which will refer to the current instance of the object. – Ken White