【发布时间】:2011-10-26 11:10:17
【问题描述】:
我想要一个带有“多态”的记录(结构)。它将在所有情况下使用几个字段,我只想在需要时使用其他字段。我知道我可以通过在记录中声明的变体部分来实现这一点。我不知道是否有可能在设计时我只能访问我需要的元素。更具体地说,请看下面的示例
program consapp;
{$APPTYPE CONSOLE}
uses
ExceptionLog,
SysUtils;
type
a = record
b : integer;
case isEnabled : boolean of
true : (c:Integer);
false : (d:String[50]);
end;
var test:a;
begin
test.b:=1;
test.isEnabled := False;
test.c := 3; //because isenabled is false, I want that the c element to be unavailable to the coder, and to access only the d element.
Writeln(test.c);
readln;
end.
这可能吗?
【问题讨论】:
标签: delphi delphi-2009 record