Q
qqjm
Unregistered / Unconfirmed
GUEST, unregistred user!
你的bb还没有创建就能执行bb.Init?????
执行前加上这句吧:bb:=TGA.create();
记着,对像都要先创建了再使用
下面的代码是正确的,真是不明白你为什么会错
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TGA=class(Tobject)
private
a1:array of array of integer;
public
procedure Init();
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
type
bb = record
a1:integer;
a2:array of integer;
end;
var
aa: array[0..2] of bb;
ta: Tga;
begin
setlength(aa[0].a2 ,1);
aa[0].a2[1]:=1;
showmessage(inttostr(aa[0].a2[1]));
ta:=Tga.Create();
ta.Init;
ta.Free;
end;
{ TGA }
procedure TGA.Init;
begin
setlength(a1,5);
setlength(a1,0);//到这里也只是初始化了第一维,那第二维呢?应该用setlength(a1,5,0);吧
end;
end.
执行前加上这句吧:bb:=TGA.create();
记着,对像都要先创建了再使用
下面的代码是正确的,真是不明白你为什么会错
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TGA=class(Tobject)
private
a1:array of array of integer;
public
procedure Init();
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
type
bb = record
a1:integer;
a2:array of integer;
end;
var
aa: array[0..2] of bb;
ta: Tga;
begin
setlength(aa[0].a2 ,1);
aa[0].a2[1]:=1;
showmessage(inttostr(aa[0].a2[1]));
ta:=Tga.Create();
ta.Init;
ta.Free;
end;
{ TGA }
procedure TGA.Init;
begin
setlength(a1,5);
setlength(a1,0);//到这里也只是初始化了第一维,那第二维呢?应该用setlength(a1,5,0);吧
end;
end.