简体   繁体   English

Delphi:TImage数组

[英]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 " 我总是得到错误:“ Project Project1.exe引发了异常类EClassNotFound并显示消息”未找到TImage“。进程已停止。使用步骤或运行继续

I have tried other codes on the internet like: 我在互联网上尝试过其他代码,例如:
Delphi: TImage.Create causes Access violation Delphi:TImage.Create导致访问冲突
http://www.delphi-central.com/tutorials/memory_game_2.aspx http://www.delphi-central.com/tutorials/memory_game_2.aspx

Nothing helps! 什么都没有帮助! Why is this happening? 为什么会这样?

Thank you. 谢谢。

Are you sure you get the exception at the line with TImage.Create? 你确定在TImage.Create的行中得到例外吗? Could it be you have an invalid DFM file still containig a TImage instance which is missing from the TForm1 declaration? 难道你有一个无效的DFM文件仍然包含TForm1声明中缺少的TImage实例吗?

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. 由于表单中没有声明TImage,并且没有其他形式的应用程序包含TImage,因此没有注册。

You can simply test by dropping a TImage onto the form. 您可以通过将TImage放到表单上来进行测试。

如果你想在表单中显示,请将此代码添加到循环:

Images[xx,yy].Parent:= Self;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM