Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: array of TImage

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.

like image 911
SmRndGuy Avatar asked Jan 16 '23 20:01

SmRndGuy


2 Answers

Are you sure you get the exception at the line with TImage.Create? Could it be you have an invalid DFM file still containig a TImage instance which is missing from the TForm1 declaration?

Normally all classes used as children in a form or datamodule are automatically registered for streaming. As there is no TImage declared in the form and no other form of the application contains a TImage, there is no registration.

You can simply test by dropping a TImage onto the form.

like image 74
Uwe Raabe Avatar answered Jan 25 '23 08:01

Uwe Raabe


and if you want to show in form add this code to loop:

Images[xx,yy].Parent:= Self;
like image 35
MohsenB Avatar answered Jan 25 '23 09:01

MohsenB