case integer of 就是为了让各种数据共享同一块存储区。意思是这个记录的一个字段代表它所存储的数据类型。另一个按指定的类型存储该数据。、
你可以这样做:
var
  x:tvariantrecord;
begin
  x.intfield:=0;
  x.nullstrfield:=3.1415927;
  (或者:
  x.intfield:=2;
  x.nullstrfield:='A';
   )
end;

解决方案 »

  1.   

    是不是。就是靠intfield来控制数据类型。用nullstrfield来取值。那为什么用intfield来控制呢?就是说为什么intfield就可以决定nullstrfield的取值呢。看来去并没有什么接系吗?
      

  2.   

    假设这个记录是别人做的一个模块传给你的(而实际应用中,的确有时根据不同的情况,它要传不同的数据类型的数据给你),你事先怎么知道它是什么类型?
    那就得先判断:
    if x.initfield=0 then ...
    else if x.inifield=1 then ...
    ...
      

  3.   

    不过我就是不理解为什么要用initfield来判断呢?
      

  4.   

    因为 case integer of end 中的数据域共享同一块存储区。所以
    case integer of 
      0:(d:double);
      1:(I:integer);
      2:(C:char);
    是如下内存影象:
     1  byte  
     2  byte  
     3  byte  
     4  byte  
     5  byte  
     6  byte  
     7  byte  
     8  byte  
    当存储 Char 时只使用了 1 byte,存储 integer 时使用了 1 byte - 4 byte,存储 Double 时使用了 1 byte - 8 byte。
    现在我将一个该类型的数据 rec 传入你的函数,你的在编写函数时你使用 rec.D 还是 rec.I 还是 rec.C 来取出数据呢?
    所以我们事先约定用 initfield 中的值来指明 case 中的类型,
    if x.initfield= then x1 := rec.D
    else if x.inifield=1 then x2 := rec.I ...写了好多(其实和 skimwater 意思一样),明白了吗?
      

  5.   

    rec是怎么传入的啊。那和  x.nullstrfield
    没什么关系啊。
      

  6.   

    nullstrfield 是其他的特定用途