### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Alias / Absolute (avoid variants) inside Records?  (Read 299 times)

#### trn76

• New Member
• Posts: 39
##### Alias / Absolute (avoid variants) inside Records?
« on: October 30, 2020, 04:39:38 pm »
How can I use Alias / Absolute (avoid variant in records) inside Records? ...or some other neat solution, that would make my day now that I've had some more coffe'!

Code: Pascal  [Select][+][-]
1. ..
2.
3. type
4.
5.   Thead_info       = packed array [0..10-1] of cuchar;
6.   Thead_archive    = packed array [0..31-1] of cuchar;
7.   Thead_filename   = packed array [0..256-1] of cuchar;
8.   Thead_comment    = packed array [0..256-1] of cuchar;
9.
10.   PPack = ^TPack;
11.   TPack = record
12.
13.     crc           : cuint;
14.     sum           : cuint;
15.
16.     pack_size     : cuint;
17.     unpack_size   : cuint;
18.
19.     mode          : cint;
20.
21.     year          : cuint;
22.     month         : cuint;
23.     day           : cuint;
24.     hour          : cuint;
25.     minute        : cuint;
26.     second        : cuint;
27.
28.     attributes    : cuint8;
29.     //pack_mode     : cuint8;       // <--- replace this
30.
35.
36.     total_pack    : cuint;
37.     total_unpack  : cuint;
38.     total_files   : cuint;
39.     merge_size    : cuint;
40.
41.     filFile       : file;
42.     filName       : string;
43.     filError      : cuint;
44.     filList       : PStringArray;
45.
46.     nodeList      : Pnode;
47.
48.     pack_mode     : cuint8 absolute head_archive[11];    // <--- with this ?
49.
50.   end;
51.

Yes I could do this:
Code: Pascal  [Select][+][-]
1. procedure something;
2. var pack: TPack;
3.     mode: cuint8;
4. begin
5.   // access
6.   mode := pack.head_archive[11] and \$1F;
7.   // but this is cleaner:
8.   mode := pack.pack_mode and \$1F;
9. end;
10.

...hope you get my drift

#### ASerge

• Hero Member
• Posts: 1706
##### Re: Alias / Absolute (avoid variants) inside Records?
« Reply #1 on: October 30, 2020, 06:44:45 pm »
Code: Pascal  [Select][+][-]
1. {\$MODE OBJFPC}
3.
4. type
5.   TheadArchive = array[0..31-1] of UInt8;
6.
7.   TPack = record
8.   strict private
9.     function GetPackMode: UInt8; inline;
10.   public
11.     Attributes: Int8;
13.     filError: Cardinal;
14.     property PackMode: UInt8 read GetPackMode;
15.   end;
16.
17. function TPack.GetPackMode: UInt8;
18. begin
20. end;
21.
22. var
23.   Pack: TPack;
24.   Mode: UInt8;
25. begin
26.   Mode := Pack.HeadArchive[11] and \$1F;
27.   Mode := Pack.PackMode and \$1F;
28. end.
Code: ASM  [Select][+][-]
1. # [29] Mode := Pack.HeadArchive[11] and \$1F;
2.         movw    U_\$P\$PROJECT1_\$\$_PACK+12(%rip),%ax
3.         andw    \$31,%ax
4. # Var Mode located in register al
5. .Ll6:
6. # [30] Mode := Pack.PackMode and \$1F;
7.         movw    U_\$P\$PROJECT1_\$\$_PACK+12(%rip),%ax
8.         andw    \$31,%ax
9. # Var Mode located in register al

#### bytebites

• Sr. Member
• Posts: 364
##### Re: Alias / Absolute (avoid variants) inside Records?
« Reply #2 on: October 30, 2020, 06:48:53 pm »
Code: Pascal  [Select][+][-]
2. type
3.      TPack = record
4. ....
5.       filError      : cuint;
6.       filList       : PStringArray;
7.
8.       nodeList      : Pnode;
9.
10.       //pack_mode     : cuint8; absolute head_archive[11];    // <--- with this ?
11.       function packmode:cuint8;
12.     end;
13.
14. ...
15.
16. function TPack.packmode: cuint8;
17. begin
18.   result:=pack_size and \$1f;
19. end;
20.

#### marcov

• Global Moderator
• Hero Member
• Posts: 9003
• FPC developer.
##### Re: Alias / Absolute (avoid variants) inside Records?
« Reply #3 on: October 30, 2020, 07:16:14 pm »