Recent

Author Topic: assigning to Array of const  (Read 995 times)

MortenB

  • Jr. Member
  • **
  • Posts: 59
Re: assigning to Array of const
« Reply #15 on: April 12, 2021, 09:13:47 pm »
I made myself something similar a few years back...
Just to give you an idea of something that actually work.
Array Of Const is quite useful as an unknown count of unknown parameter types to a procedure or a function.
This is just ONE of many procedures I made.
Maybe you can get some inspiration from it :)

Code: Pascal  [Select][+][-]
  1. PROCEDURE TShelves.TAdd.ColumnRow(RowData : ARRAY OF CONST; LocalType:BYTE); // No errorchecking. Only adds according to type. Also increase the size of the type's array.
  2.   VAR
  3.     ix : INTEGER ;   xx : EXTENDED;   asx : ^AnsiString;
  4.                                       wsx : ^WideString;
  5.     OldRowPointer : INTEGER;
  6.   BEGIN
  7. {
  8. AllVTypes : ARRAY[0..18] OF AnsiString =('vtInteger','vtBoolean'  ,'vtChar'      ,'vtExtended' ,'vtString'    ,'vtPointer' ,'vtPChar',
  9.                                          'vtObject' ,'vtClass'    ,'vtWideChar'  ,'vtPWideChar','vtAnsiString','vtCurrency',
  10.                                          'vtVariant','vtInterface','vtWideString','vtInt64'    ,'vtQWord'     ,'vtUniCodeString');   }
  11.     WITH pTheColumn^ DO BEGIN
  12.       OldRowPointer := RowCount;
  13.       CASE RowData[0].VType OF
  14.         0: BEGIN
  15.              ix := RowData[0].VInteger;
  16.              AddWholeNumbersToColumn(ix,LocalType);
  17.              IF ErrorMessage = '' THEN INC(RowCount);
  18.            END;
  19.         1:   {  1 } BEGIN SetLength(IfBoolean    , RowCount+1); IfBoolean    [RowCount] := RowData[0].VBoolean; INC(RowCount); END;// vtBoolean  ... Boolean
  20.         3: BEGIN
  21.              xx := RowData[0].VExtended^;  // Probably not needed, but shorter to write in below lines!
  22.              CASE LocalType OF // vtExtended ... Double, TDate, TTime, Real, Extended
  23.                 9 : BEGIN SetLength(IfDouble     , RowCount+1); IfDouble     [RowCount] := xx; INC(RowCount); END;// Double
  24.                10 : BEGIN SetLength(IfExtended   , RowCount+1); IfExtended   [RowCount] := xx; INC(RowCount); END;// Extended
  25.                12 : BEGIN SetLength(IfTime       , RowCount+1); IfTime       [RowCount] := xx; INC(RowCount); END;// TTime
  26.                13 : BEGIN SetLength(IfDate       , RowCount+1); IfDate       [RowCount] := xx; INC(RowCount); END;// TDate
  27.                14 : BEGIN SetLength(IfDateTime   , RowCount+1); IfDateTime   [RowCount] := xx; INC(RowCount); END;// TDateTime
  28.              END;
  29.            END;
  30.         4:   { 15 } BEGIN SetLength(IfShortString, RowCount+1); IfShortString[RowCount] := RowData[0].VString^; INC(RowCount); END;// vtString   ... ShortString
  31.        11:   { 16 } BEGIN
  32.                       asx := @RowData[0].VAnsiString;
  33.                       AddAnsiStringToColumn(asx^,LocalType);
  34.                       IF ErrorMessage = '' THEN INC(RowCount);
  35.                     END;
  36.        12:   { 11 } BEGIN SetLength(IfCurrency   , RowCount+1); IfCurrency   [RowCount] := RowData[0].VCurrency^; INC(RowCount); END;// vtCurrency;
  37.        15:   { 17 } BEGIN
  38.                           wsx := @RowData[0].VWideString;
  39.                           SetLength(IfWideString , RowCount+1); IfWideString [RowCount] := wsx^; INC(RowCount); // vtWideString
  40.                     END;
  41.        16:   {  8 } BEGIN SetLength(IfInt64      , RowCount+1); IfInt64      [RowCount] := RowData[0].VInt64^; INC(RowCount); END;// vtInt64
  42.        17:   {  5 } BEGIN SetLength(IfQWord      , RowCount+1); IfQWord      [RowCount] := RowData[0].VQWord^; INC(RowCount); END;// QWord
  43.       END;
  44.       IF RowCount = OldRowPointer THEN ErrorMessage :='Error! Column-Data was not added.'
  45.     END;
  46.   END;
  47.  

 

TinyPortal © 2005-2018