size of variant records lazarus / 62-General ---------------------------------------------------------------------- 440bx · 2022-01-10 23:54 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$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 · 2022-01-11 01:16 Add the offset of the field to the SizeOf the field? ---------------------------------------------------------------------- 440bx · 2022-01-11 02:31 Quote from: engkin on January 11, 2022, 02:16:40 amAdd the offset of the field to the SizeOf the field? Yes, that will do it.  I was hoping for something like "SizeTo();  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 · 2022-01-11 03:21 On a positive note, it is a compile-time value. ---------------------------------------------------------------------- PascalDragon · 2022-01-11 08:28 Quote from: 440bx on January 11, 2022, 03:31:55 amQuote from: engkin on January 11, 2022, 02:16:40 amAdd the offset of the field to the SizeOf the field? Yes, that will do it.  I was hoping for something like "SizeTo();  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. Well, the size up to some field is the offset of that field ---------------------------------------------------------------------- 440bx · 2022-01-11 08:34 Quote from: PascalDragon on January 11, 2022, 09:28:28 amWell, the size up to some field is the offset of that field Wouldn't it be the offset to the _next_ field ? (which makes the expression to calculate the size a bit confusing) ---------------------------------------------------------------------- PascalDragon · 2022-01-11 08:52 Quote from: 440bx on January 11, 2022, 09:34:45 amQuote from: PascalDragon on January 11, 2022, 09:28:28 amWell, the size up to some field is the offset of that field Wouldn't it be the offset to the _next_ field ? (which makes the expression to calculate the size a bit confusing) Right, forgot that you meant including the field