<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV>I forgot how important it was to start with the lowest dimension first when 
<BR>multiplieing dimensions.</DIV>
<DIV> </DIV>
<DIV>This is the only slightly dangerous issue/problem remaining which could 
<BR>probably be solved by a compiler.</DIV>
<DIV> </DIV>
<DIV>The compiler could perhaps put it in the correct order somehow.</DIV>
<DIV> </DIV>
<DIV>Maybe the programmer would need to indicate the order of the dimensions 
like <BR>so:</DIV>
<DIV> </DIV>
<DIV>Block.Order := 2;<BR>Element.Order := 1;</DIV>
<DIV> </DIV>
<DIV>Corrected version 0.07 test program:</DIV>
<DIV> </DIV>
<DIV>// *** Begin of Test Program ***</DIV>
<DIV> </DIV>
<DIV>program TestProgram;</DIV>
<DIV> </DIV>
<DIV><BR>{$APPTYPE CONSOLE}</DIV>
<DIV> </DIV>
<DIV>{</DIV>
<DIV> </DIV>
<DIV>TDynamicIndex</DIV>
<DIV> </DIV>
<DIV>alternative version 0.06 created on 3 july 2011 by Skybuck Flying.</DIV>
<DIV> </DIV>
<DIV>TDynamicIndex reduced to the most basic/simpelst form so that it can be 
used<BR>for many other types/arrays and so forth.</DIV>
<DIV> </DIV>
<DIV>Instead TMemory is created which accepts TDynamicIndex as parameters to 
do<BR>lookups. TMemory also has been made more generic so it can 
contain<BR>different kinds of types.</DIV>
<DIV> </DIV>
<DIV>A more realistic example.</DIV>
<DIV> </DIV>
<DIV>There might still be room to improve this technique if TDynamicIndex 
could<BR>be used as the loop variable. This will be examined in a next 
(alternative)<BR>version ! ;)</DIV>
<DIV> </DIV>
<DIV><BR>(It's all about reducing the ammount of code and keep it as simple and 
well<BR>readable/understandable/self documenting as possible<BR>with quick 
insight into what everthing does which is good for 
algorithm<BR>design/development/inspection)</DIV>
<DIV> </DIV>
<DIV>(re-created from my usenet posting from my archive, delphi 
overwrite<BR>this example with the project file of another folder 
?!<BR>fortunately nothing was lost in the process except this text 
slightly<BR>reformatted.)</DIV>
<DIV> </DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV>{</DIV>
<DIV> </DIV>
<DIV>alternative version 0.07 created on 3 july 2011 by Skybuck Flying.</DIV>
<DIV> </DIV>
<DIV>Very nice :</DIV>
<DIV> </DIV>
<DIV>TDynamicIndex improvements:</DIV>
<DIV> </DIV>
<DIV>+ Build-in support for enumerators<BR>+ Build-in enumerator for 
TDynamicIndex<BR>+ Implicit conversion to integer   (index is returned 
as integer)<BR>+ Implicit conversion to string    (index is 
returned as string)<BR>+ Additional properties to get value (index) and 
dimension.</DIV>
<DIV> </DIV>
<DIV>DynamicIndex can now be used in for in loops ! ;) =D</DIV>
<DIV> </DIV>
<DIV>TMemory improvements:<BR>+ memory cleaned up via setting count property to 
zero</DIV>
<DIV> </DIV>
<DIV>!!! CAUTION !!!:</DIV>
<DIV> </DIV>
<DIV>It is important to write the lowest dimensions first and the highest 
<BR>dimensions later<BR>when multiplieing otherwise it won't work 
properly.</DIV>
<DIV> </DIV>
<DIV>!!!!!!!!!!!!!!!</DIV>
<DIV> </DIV>
<DIV><BR>}</DIV>
<DIV> </DIV>
<DIV><BR>uses<BR>SysUtils;</DIV>
<DIV> </DIV>
<DIV>type<BR>{<BR>TDynamicIndexEnumerator = record<BR>private<BR>  FArray: 
TBytes;<BR>  FIndex: Integer;<BR>  function GetCurrent : 
integer;<BR>public</DIV>
<DIV> </DIV>
<DIV>end;<BR>}</DIV>
<DIV> </DIV>
<DIV>TDynamicIndex = record<BR>private<BR>  mIndex : integer;<BR>  
mDimension : integer;</DIV>
<DIV> </DIV>
<DIV>  function GetCurrent : TDynamicIndex; inline;</DIV>
<DIV> </DIV>
<DIV>  function StoreIndex( ParaIndex : integer ) : TDynamicIndex; 
inline;<BR>public<BR>  constructor Create( ParaDimension : integer );</DIV>
<DIV> </DIV>
<DIV>  property IndexOperator[ ParaIndex : integer ] : TDynamicIndex read 
<BR>StoreIndex; default;</DIV>
<DIV> </DIV>
<DIV>  property Dimension : integer read mDimension write 
mDimension;<BR>  property Value : integer read mIndex write mIndex;</DIV>
<DIV> </DIV>
<DIV>  class operator Multiply( ParaA, ParaB : TDynamicIndex ) : 
TDynamicIndex;</DIV>
<DIV> </DIV>
<DIV>  // enumerator functions<BR>  function MoveNext : Boolean; 
inline;<BR>  property Current : TDynamicIndex read GetCurrent;</DIV>
<DIV> </DIV>
<DIV>  function GetEnumerator : TDynamicIndex;</DIV>
<DIV> </DIV>
<DIV>  // implicit operator so .Value doesn't need to be used when 
assinging the <BR>dynamic index to an integer ;)<BR>  class operator 
Implicit( ParaDynamicIndex : TDynamicIndex  ) : integer;</DIV>
<DIV> </DIV>
<DIV>  // another implicit operator so it automatically gets converted to a 
<BR>string ! ;) :)<BR>  class operator Implicit( ParaDynamicIndex : 
TDynamicIndex ) : string;<BR>end;</DIV>
<DIV> </DIV>
<DIV>constructor TDynamicIndex.Create( ParaDimension : integer 
);<BR>begin<BR>mIndex := 0;<BR>mDimension := 1;</DIV>
<DIV> </DIV>
<DIV>if ParaDimension > 1 then<BR>begin<BR>  mDimension := 
ParaDimension;<BR>end;<BR>end;</DIV>
<DIV> </DIV>
<DIV>function TDynamicIndex.StoreIndex( ParaIndex : integer ) : 
TDynamicIndex;<BR>begin<BR>mIndex := ParaIndex;<BR>result.mIndex := 
mIndex;<BR>result.mDimension := mDimension;<BR>end;</DIV>
<DIV> </DIV>
<DIV>class operator TDynamicIndex.Multiply( ParaA, ParaB : TDynamicIndex ) : 
<BR>TDynamicIndex;<BR>begin<BR>result.mIndex := ParaA.mIndex + (ParaA.mDimension 
* ParaB.mIndex);<BR>result.mDimension := ParaA.mDimension * 
ParaB.mDimension;<BR>end;</DIV>
<DIV> </DIV>
<DIV>function TDynamicIndex.MoveNext : Boolean;<BR>begin<BR>result := 
false;</DIV>
<DIV> </DIV>
<DIV>mIndex := mIndex + 1;<BR>if mIndex < mDimension then<BR>begin<BR>  
result := true;<BR>end;<BR>end;</DIV>
<DIV> </DIV>
<DIV>function TDynamicIndex.GetCurrent : 
TDynamicIndex;<BR>begin<BR>result.mIndex := mIndex;<BR>result.mDimension := 
mDimension;<BR>end;</DIV>
<DIV> </DIV>
<DIV>function TDynamicIndex.GetEnumerator : 
TDynamicIndex;<BR>begin<BR>result.mIndex := -1;<BR>result.mDimension := 
mDimension;<BR>end;</DIV>
<DIV> </DIV>
<DIV>class operator TDynamicIndex.Implicit( ParaDynamicIndex : 
TDynamicIndex  ) : <BR>integer;<BR>begin<BR>result := 
ParaDynamicIndex.mIndex;<BR>end;</DIV>
<DIV> </DIV>
<DIV>class operator TDynamicIndex.Implicit( ParaDynamicIndex : TDynamicIndex ) : 
<BR>string;<BR>begin<BR>result := IntToStr( ParaDynamicIndex.mIndex 
);<BR>end;</DIV>
<DIV> </DIV>
<DIV>type<BR>TMemory<GenericType> = class<BR>private</DIV>
<DIV> </DIV>
<DIV>protected<BR>  mMemory : array of GenericType;<BR>  mCount : 
integer;</DIV>
<DIV> </DIV>
<DIV>  procedure SetCount( ParaCount : integer );</DIV>
<DIV> </DIV>
<DIV>  function GetElement( ParaIndex : TDynamicIndex ) : 
GenericType;<BR>  procedure SetElement( ParaIndex : TDynamicIndex; 
ParaValue : <BR>GenericType );</DIV>
<DIV> </DIV>
<DIV>public<BR>  constructor Create;<BR>  destructor Destroy; 
override;</DIV>
<DIV> </DIV>
<DIV>  property Count : integer read mCount write SetCount;</DIV>
<DIV> </DIV>
<DIV>  property Element[ ParaIndex : TDynamicIndex ] : GenericType read 
<BR>GetElement write SetElement; default;<BR>end;</DIV>
<DIV> </DIV>
<DIV>constructor TMemory<GenericType>.Create;<BR>begin<BR>inherited 
Create;</DIV>
<DIV> </DIV>
<DIV>end;</DIV>
<DIV> </DIV>
<DIV>destructor TMemory<GenericType>.Destroy;<BR>begin<BR>Count := 
0;</DIV>
<DIV> </DIV>
<DIV>inherited Destroy;<BR>end;</DIV>
<DIV> </DIV>
<DIV>procedure TMemory<GenericType>.SetCount( ParaCount : integer 
);<BR>begin<BR>mCount := ParaCount;<BR>SetLength( mMemory, mCount 
);<BR>end;</DIV>
<DIV> </DIV>
<DIV>function TMemory<GenericType>.GetElement( ParaIndex : TDynamicIndex ) 
: <BR>GenericType;<BR>begin<BR>result := mMemory[ParaIndex.Value];<BR>end;</DIV>
<DIV> </DIV>
<DIV>procedure TMemory<GenericType>.SetElement( ParaIndex : TDynamicIndex; 
<BR>ParaValue : GenericType );<BR>begin<BR>mMemory[ParaIndex.Value] := 
ParaValue;<BR>end;</DIV>
<DIV> </DIV>
<DIV><BR>procedure Main;<BR>var<BR>mBlockCount : integer;<BR>mElementCount : 
integer;</DIV>
<DIV> </DIV>
<DIV>mMemory : TMemory<integer>;</DIV>
<DIV> </DIV>
<DIV>mBlock : TDynamicIndex;<BR>mElement : TDynamicIndex;</DIV>
<DIV> </DIV>
<DIV>vBlockIndex : TDynamicIndex;<BR>vElementIndex : 
TDynamicIndex;<BR>begin<BR>// smaller values set to make the program end soon to 
test clean up too ;)<BR>mBlockCount := 5;<BR>mElementCount := 20;</DIV>
<DIV> </DIV>
<DIV>mMemory := TMemory<integer>.Create;<BR>mMemory.Count := mBlockCount * 
mElementCount;</DIV>
<DIV> </DIV>
<DIV>// functions as a dimension holder ;)<BR>mBlock := TDynamicIndex.Create( 
mBlockCount );<BR>mElement := TDynamicIndex.Create( mElementCount );</DIV>
<DIV> </DIV>
<DIV>// functions as index iterators<BR>vBlockIndex := mBlock;<BR>vElementIndex 
:= mElement;</DIV>
<DIV> </DIV>
<DIV>for vBlockIndex in mBlock do<BR>begin<BR>  for vElementIndex in 
mElement do<BR>  begin<BR>   mMemory[ vElementIndex * vBlockIndex 
] := (vElementIndex * <BR>vBlockIndex).Value; // nice and short ! ;)<BR>  
end;<BR>end;</DIV>
<DIV> </DIV>
<DIV>for vBlockIndex in mBlock do<BR>begin<BR>  for vElementIndex in 
mElement do<BR>  begin<BR>   writeln( 'BlockIndex: ' + 
vBlockIndex + ' ElementIndex: ' + vElementIndex <BR>+ ' mMemory: ', mMemory[ 
vElementIndex * vBlockIndex ] );</DIV>
<DIV> </DIV>
<DIV>   // I would still ike to be able to write it like this, but I 
don't know <BR>if it's possible to make writeln recgonized it<BR>   // 
and how to do it ;) :) the above method is better for dialogs though 
<BR>;)<BR>//   writeln( 'BlockIndex: ', vBlockIndex, ' ElementIndex: 
', vElementIndex, <BR>'mMemory: ', mMemory[ vElementIndex * vBlockIndex ] 
);<BR>  end;<BR>  readln;<BR>end;</DIV>
<DIV> </DIV>
<DIV>mMemory.Free;<BR>end;</DIV>
<DIV> </DIV>
<DIV>begin<BR>try<BR>  Main;<BR>except<BR>  on E: Exception 
do<BR>   Writeln(E.ClassName, ': ', 
E.Message);<BR>end;<BR>ReadLn;<BR>end.</DIV>
<DIV> </DIV>
<DIV>// *** End of Test Program ***</DIV>
<DIV> </DIV>
<DIV>Bye,<BR>  Skybuck. <BR></DIV>
<DIV>
<DIV 
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
<DIV 
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
<DIV 
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
<DIV 
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
<DIV 
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none"> </DIV></DIV></DIV></DIV></DIV></DIV></DIV></DIV></BODY></HTML>