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

2025-04-13 04:18:05
推荐回答(5个)
回答1:

可以的。下面是完整的示例代码:
{
在类中定义记录
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.

回答2:

type
Tclassname= record

end;

回答3:

type
TownBook = record
Code : string;
Name : string;
Price : string;
OwnDays : integer;
end;

回答4:

不能

回答5:

有这个必要么?