Strange record

Hi

I have a book but i can't seem to understand something in it...

[code]
var
vr : record
case something : byte of
0 : (a : longint);
1 : (loword, hiword : word);
2 : (bArray : array[1..4] of byte);
end;
begin
vr.a:=65536*1996+512;
writeln(vr.loword); { 512 }
writeln(vr.hiword); { 1996 }
writeln(vr.bArray); { 2 }
end.
[/code]

It says that it's a special kind of record. How does this work?

Comments

  • : Hi
    :
    : I have a book but i can't seem to understand something in it...
    :
    : [code]
    : var
    : vr : record
    : case something : byte of
    : 0 : (a : longint);
    : 1 : (loword, hiword : word);
    : 2 : (bArray : array[1..4] of byte);
    : end;
    : begin
    : vr.a:=65536*1996+512;
    : writeln(vr.loword); { 512 }
    : writeln(vr.hiword); { 1996 }
    : writeln(vr.bArray); { 2 }
    : end.
    : [/code]
    :
    : It says that it's a special kind of record. How does this work?

    It's similar to a union in C/C++. Basically it's like having 3 different structures sharing the same memory. In this case, it creates 3 different ways to interact with a 32bit number. vr.a will access it as a whole, vr.loword/hiword will access it as 2 16bit numbers, and vr.barray accesses it as 4 8 bit numbers.

  • : It's similar to a union in C/C++. Basically it's like having 3 different structures sharing the same memory. In this case, it creates 3 different ways to interact with a 32bit number. vr.a will access it as a whole, vr.loword/hiword will access it as 2 16bit numbers, and vr.barray accesses it as 4 8 bit numbers.
    :

    Can you give me a link to read more detaliated of it because it's very comlpicated for me(i've just started programming)...
  • :
    : : It's similar to a union in C/C++. Basically it's like having 3 different structures sharing the same memory. In this case, it creates 3 different ways to interact with a 32bit number. vr.a will access it as a whole, vr.loword/hiword will access it as 2 16bit numbers, and vr.barray accesses it as 4 8 bit numbers.
    : :
    :
    : Can you give me a link to read more detaliated of it because it's very comlpicated for me(i've just started programming)...
    :
    Use Google and search for "Case Variant Record". Here's one hit:

    http://www.delphibasics.co.uk/RTL.asp?Name=Record

    School's in session already?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories