自动生成控件遇到的问题
我在程序中自动生成了一组image和label控件,程序运行时可以显示控件但是提示 Invalide pointer operation,出错指在project文件的最后一行.
下面是整个单元的源代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
procedure FormDblClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormDblClick(Sender: TObject);
begin
Close;
end;
procedure TForm1.FormShow(Sender: TObject);
var
stImage: Array of TImage;
stLabel: Array of TLabel;
i,j,Rows,Space1,ColWidth: integer;
begin
Rows:=6;
Space1:=5;
ColWidth:=150;
SetLength(stImage,10);
SetLength(stLabel,10);
for i:=1 to 10 do
begin
j:= (i div Rows)+1;
stImage[i]:=TImage.Create(self);
stImage[i].Parent:=form1;
stImage[i].Picture.LoadFromFile('d9.ico');
stImage[i].Name:='image'+IntToStr(i);
if i<Rows then stImage[i].Top:=2+35*((i mod Rows)-1)
else stImage[i].Top:=2+35*(i mod Rows);
stImage[i].Left:=2+ColWidth*(j-1);
stLabel[i]:=TLabel.Create(self);
stLabel[i].Parent:=form1;
stLabel[i].Caption:=IntToStr(i);
stLabel[i].Width:=100;
stLabel[i].Name:='label'+IntToStr(i);
stLabel[i].Top:=stImage[i].Top+10;
stLabel[i].Left:=stImage[i].Left+32+Space1;
end;
end;
end.
问题点数:50、回复次数:2Top
1 楼boatzm(晓舟怕麻烦)【IUnKnown】(#_#!)回复于 2004-11-03 22:48:01 得分 50
for i:=1 to 10 do
// 动态数组下标是从0 开始的。 所有没有10 这个上标。。。。明白怎样改了吧。Top
2 楼Mcy(机动工程车)回复于 2004-11-03 22:50:37 得分 0
晕倒,我怎么印象中pascal的数字是从1开始.
不过问题解决了.非常感谢!Top




