Note that there are some explanatory texts on larger screens.

plurals
  1. PORTTI Delphi Create as TValue an n-dimensional matrix
    primarykey
    data
    text
    <p>Good day,</p> <p><a href="http://www.delphifeeds.com/postings/60805-tvalue_in_depth" rel="nofollow noreferrer">TValue</a> is a Delphi-2010 and up RTTI feature.</p> <p>Following on from my <a href="https://stackoverflow.com/questions/4561569/rtti-dynamic-array-tvalue-delphi-2010">earlier question</a>, I had tried to make recurrent function to return a TValue as a n-dimensional. matrix(2D, 3D, 4D...)</p> <p>for example, this procedure will show a n-dimensional matrix(it will list all elements from a n-dimensional matrix as TValue variable):</p> <pre><code>Procedure Show(X:TValue); var i:integer; begin if x.IsArray then begin for i:=0 to x.GetArrayLength-1 do show(x.GetArrayElement(i)); writeln; end else write(x.ToString,' '); end; </code></pre> <p>I don't understand how to create a function to create from a TValue an n-dimensional matrix. For example i need a Function CreateDynArray(Dimensions:array of integer; Kind:TTypeKind):TValue; and the function will return a TValue which is a dynamic array how contain the dimenssions for example:</p> <p>Return=CreateDynArray([2,3],tkInteger); will return a TValue as tkDynArray and if i will show(Return) will list</p> <pre><code>0 0 0 0 0 0 </code></pre> <p>Is not terminated. From a TValue i try to create a DynArray with n-dimensions</p> <pre><code>Procedure CreateArray(var Value:TValue; NewDimmension:integer; NewValue2Kind:TTypeKind; NewValue2:TValue; IsLast:Boolean); var i:integer; NewValue:TValue; len:Longint; begin If Value.IsArray then// we have components in this dimension begin for i:=0 to Value.GetArrayLength-1 do// list all begin NewValue:=Value.GetArrayElement[i]; CreateArray(newValue,NewDimension,NewValue2Kind,NewValue2,IsLast); Value.SetArrayElement(i,NewValue); end; end; end else begin if isLast then begin len:=NewDimension; DynArraySetLength(PPointer(Value.GetRefereneToRawData)^,Value.TypeInfo,1,@len); //set length to NewDimension for i:=0 to NewDimension-1 do //Fill all with 0 Value.SetArrayElement(i,NewValue2); end else begin len:=NewDimension; DynArraySetLength(PPointer(Value.GetRefereneToRawData)^,Value.TypeInfo,1,@len);//I will create len TValues end; end; var Index:array of integer; Value:TValue; ValuKind:TTypeKind; ...... ...... .... Case token of tokInt: begin ValueKind:=tkInteger; Value:=0; end; ..... end; Index:=GetIndexFromSintacticTree;//for example if i have int[20][30] index=[20,30] for i:=0 to high(index) do begin if i = high(index) then CreateArray(Variable.Value,Index[i],ValueKind,Value,True) else CreateArray(Variable.Value,Index[i],ValueKind,Value,False) //Variable.Value is TValue end; //first TValue have 1 element, after that it will have 20 elements, and after that will have 20*30 elements </code></pre> <p><img src="https://i.stack.imgur.com/I9ubT.png" alt="The ideea"></p> <p>Thank you very much, and have a nice day!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload