在delphi中,一个单元里定义一个类,怎么在这个类中定义一个record?注意是在类中定义,不是在单元里定义。

在delphi中,一个单元里定义一个类,怎么在这个类中定义一个record?注意是在类中定义,不是在单元里定义,谢谢
在类里定义的record,始终要提示一个错误,不知道能不能解决

可以的。下面是完整的示例代码:
{
在类中定义记录
by 宋银海
2012年8月15日
}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TRecClass=Class
type
TRRec=record
A:integer;
end;
private
public
Test:TRRec;
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);
var
testRC:TRecClass;
begin
testRC:=TRecClass.Create;
testRC.Test.A:=3;
ShowMessage(IntToStr(testRC.Test.A));
testRC.Free;
end;
end.追问

编译时有这个提示,我写时也是这样,是在DELPHI7下,不知道您怎么实现的,请指教,谢谢

追答

Delphi7中不允许这样定义。
在Delphi2010中可以。

追问

哦,那这个版本升级可真够大的,经测试真的可以,谢谢了,以后要多在新的版本上做东西了。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-08-15
type
Tclassname= record

end;追问

不行的,在单元中可以这么定义,但类中会报错

第2个回答  2012-08-15
type
TownBook = record
Code : string;
Name : string;
Price : string;
OwnDays : integer;
end;追问

不行的,在单元中可以这么定义,但类中会报错

第3个回答  2012-08-15
不能追问

确定吗?因为我才从其它语言转到DELPHI开发,其它语言中类里可以定义结构的,现在DELPHI的资料太少了,有些问题也找不到答案

第4个回答  2012-08-15
有这个必要么?追问

这不是问题,谢谢