Forum > General

size of variant records

(1/2) > >>

440bx:
Hello,

Does FPC provide a way to determine the size of a variant record up to and including a specific field/variant ?

For instance, in the following sample:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$APPTYPE CONSOLE} type  TSOME_VARIANT_TYPE = record    VariantSize          : DWORD;     SomeField            : qword;     case integer of      1 : (           a : byte;          );       2 : (           b : word;          );       3 : (           c : DWORD;          );       4 : (           d : qword;          );  end; var  Size : DWORD; begin   { how to get the size up to and including field a or b or c ?               }   { Size := ???                                                               }end.Is there a way to determine the size of the record up to and including a (but not b, c and d) ? or upto and including b (or c) excluding the fields that follow it ?

Thank you for your help.

engkin:
Add the offset of the field to the SizeOf the field?

440bx:

--- Quote from: engkin on January 11, 2022, 02:16:40 am ---Add the offset of the field to the SizeOf the field?

--- End quote ---
Yes, that will do it.  I was hoping for something like "SizeTo(<Record.Fieldname>);  Can't have it all, I guess ;)

Thank you for the suggestion.  At least it tells me that there isn't a really straightforward/direct way of getting the size up to some field.

engkin:
On a positive note, it is a compile-time value.

PascalDragon:

--- Quote from: 440bx on January 11, 2022, 03:31:55 am ---
--- Quote from: engkin on January 11, 2022, 02:16:40 am ---Add the offset of the field to the SizeOf the field?

--- End quote ---
Yes, that will do it.  I was hoping for something like "SizeTo(<Record.Fieldname>);  Can't have it all, I guess ;)

Thank you for the suggestion.  At least it tells me that there isn't a really straightforward/direct way of getting the size up to some field.

--- End quote ---

Well, the size up to some field is the offset of that field ;)

Navigation

[0] Message Index

[#] Next page

Go to full version