Delphi 레코드 레코드의 변형

1153 단어 Delphi
program Day4;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Util in 'Util.pas';


type
    TPerson = packed record
        ID : integer;
        case IsFullJob : Boolean of
            true: (
                Year : Cardinal;
            );
            false:(
                Hour : word;
            );
    end;


var
    s : string;
    ss : ShortString;
    p : TPerson;

begin
    Writeln('sizeof integer:',sizeof(integer));
    Writeln('sizeof cardinal:',sizeof(cardinal));
    Writeln('sizeof word:',sizeof(word));
    Writeln('sizeof boolean:',sizeof(boolean));
    Writeln('sizeof TPERSON:',sizeof(Tperson));

    p.ID := 110;
    p.Year := $80000001;      //$8 = 1000 b
    Writeln('p.year:',p.year);
    Writeln('p.hour:',p.hour);
    p.IsFullJob := true;
    Writeln('p.IsFullJob:',p.IsFullJob);

    readln;
end.

C와 유사한 연합체 유니언.

좋은 웹페이지 즐겨찾기