Forum > General
[SOLVED] Static array RTTI
(1/1)
avk:
Suppose we have a static array type, such as:
--- 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";}};} ---type TMyArray = array[1..3, 2..4, 0..1] of Integer; ...
Is it possible to recover the exact structure of some variable of this type using RTTI?
Thanks in advance.
jamie:
Not sure about the number of DIMS but you can get the Lo(), HI() and length of each element at runtime. But you still need to know the Dim count.
I have a class I wrote way back which does allow me to remap the array and of course determine the DIM layout at runtime. All memory layouts are contiguous and if changes are made during runtime they are remapped and that includes the number of DIM element.
I Think in your case however, you could get away with using multiple arrays whereby each one can be determined and reconfigured that points to the next! etc.
ASerge:
--- Quote from: avk on December 19, 2022, 08:02:22 am ---Is it possible to recover the exact structure of some variable of this type using RTTI?
--- End quote ---
Only if each dimension is defined by an explicit type.
--- 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";}};} ---{$MODE OBJFPC}{$APPTYPE CONSOLE} uses TypInfo; procedure PrintArrayInfo(ArrTypeInfo: PTypeInfo);var ArrTypeData: PTypeData; ItemTypeInfo: PTypeInfo; ItemTypeData: PTypeData; i: SizeInt;begin ArrTypeData := GetTypeData(ArrTypeInfo); Writeln(ArrTypeInfo^.Name, ' is ', ArrTypeData^.ArrayData.DimCount, ' dimensions array of ', ArrTypeData^.ArrayData.ElType^.Name); for i := 0 to ArrTypeData^.ArrayData.DimCount - 1 do begin ItemTypeInfo := ArrTypeData^.ArrayData.Dims[i]; ItemTypeData := GetTypeData(ItemTypeInfo); Writeln(ItemTypeInfo^.Name, ' ', ItemTypeData^.MinValue, '..', ItemTypeData^.MaxValue); end;end; type TRange1 = 17..19; TRange2 = 123..124; TRange3 = 5..5; TMyArray = array[TRange1, TRange2, TRange3, 7..8] of string; begin PrintArrayInfo(TypeInfo(TMyArray)); Readln;end.Result:
--- Code: Text [+][-]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";}};} ---TMyArray is 4 dimensions array of ShortStringTRange1 17..19TRange2 123..124TRange3 5..5ShortInt -128..127
As far as I know, it's the same in Delphi - if the array range is not declared, it does not fall into RTTI.
avk:
Thank you all very much for your help.
Navigation
[0] Message Index