Not the same question!!
I want to create a record containing two Integer,a Union,with the Union is not at the bottom of Record type,and after the Union there are a Integer in the record.
such as:
rec =record
int1 :Integer;
Union{the CASE ..OF structure}
{NOTED..}
int2 :integer;
end;
曾有清华的一本讲Pascal的书中提到变体记录只能位于record的最后,如果Delphi
不在这方面有扩展的话,那只能定义一个中间类型作Union,然后再加入最后的record中
如下例:
type myunion=record
case Integer of
1 : (s: PChar);
2 : (i: Integer);
end;
rec= record
Int1 :integer;
Union: myunion;
Int2 :Integer;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
r:rec;
begin
r.Int1:=12;
r.Union.s:='this is a string';
r.Int2:=14;
Label1.Caption:=inttohex(r.Union.i,8);
end;
可编译通过,但如要对rec存入磁盘可能要花费一些功夫。