[fpc-pascal] "Variant array locked" error for now apparent reason

Graeme Geldenhuys graemeg.lists at gmail.com
Thu Jan 4 10:52:55 CET 2007


As the subject line says, I keep getting this error and I can't see why!
I'm trying to get the last 4 unit test errors fixed running the tiOPF
project under FPC 2.1.1. (latest SVN revision)

The tiOPF function tiVariantArrayToString() converts a Variant Array
to a String. I placed some writeln() statements in the code to see how
far it gets before the error occurs. As you can see from the backtrace
output, that it finishes (exits) the function, and then the error
occurs.  Also nowhere in the code do I lock the variant array, as I am
not modifying it, just iterating through it's elements.

Hope someone can shed some light on this issue - I'm stuck!  :-(



------  Error Start  ------
  <ListOfErrors>
    <Error>
      <Message>TTestTIUtils.tiVariantArrayToString: Variant array
locked</Message>
      <ExceptionClass>EVariantArrayLockedError</ExceptionClass>
      <ExceptionMessage>Variant array locked</ExceptionMessage>
      <SourceUnitName>/mnt/data/programming/3rdParty/tiOPF2/Source/Core/tiUtils.pas</SourceUnitName>
      <LineNumber>890</LineNumber>
      <FailedMethodName>_INTTOSTR</FailedMethodName>
    </Error>
  </ListOfErrors>

------  Error End  --------



------------ The Code   ------------
function  tiVariantArrayToString(AValue: Variant): string;
  //---------
  procedure appendVariantToStringList(pStringList: TStringList;
      pVariant: Variant; var pIndent: integer);
  var
    i: integer;
    iLow: integer;
    iHigh: integer;
  begin
    if VarIsArray(pVariant) then
//    if tiIsVariantOfType(pVariant, varArray) then
    begin
      iLow := varArrayLowBound(pVariant, 1);
      iHigh := varArrayHighBound(pVariant, 1);
      for i := iLow to iHigh do
      begin
        inc(pIndent);

        if i = iLow then
          pStringList.add(tiSpace(pIndent*3) + '[');

        appendVariantToStringList(pStringList, pVariant[i], pIndent);

        if i = iHigh then
          pStringList.add(tiSpace(pIndent*3) + ']');

        dec(pIndent);
      end;
    end
    else
    begin
      pStringList.add(tiSpace(pIndent*3 + 1) + varToStr(pVariant));
    end;
  end;

var
  lStringList : TStringList;
  pIndent : integer;
  dimcount: integer;
begin
  lStringList := TStringList.Create;
  try
    pIndent := -1;
writeln('*** Start  ***');
    appendVariantToStringList(lStringList, AValue, pIndent);
writeln('*** Finish  ***');
    result := lStringList.Text;
  finally
    lStringList.free;
  end;
writeln('*** Exit  ***');
end;

-----------  Code End  --------------

... and the backtrace ....


-----------  Backtrace Start  ----------

(gdb) run
Starting program: /UnitTests/GUI/fpcUnitTIOPFGui
[Thread debugging using libthread_db enabled]
[New Thread -1213237024 (LWP 12705)]
InitKeyboardTables - Duplicate Keysymstring="=" for keycode=126 ignored.
  Existing: vkey=57, flags=0x00 New: vkey=227, flags=0x00
[New Thread -1215480912 (LWP 12711)]
*** Start  ***
*** Finish  ***
*** Exit  ***

[Switching to Thread -1213237024 (LWP 12705)]

Breakpoint 1, 0x08060196 in fpc_raiseexception ()
(gdb) bt
#0  0x08060196 in fpc_raiseexception ()
#1  0x0824c21c in VARIANTS_VARARRAYLOCKEDERROR () at tiUtils.pas:2784
#2  0x0824c4c7 in VARIANTS_RAISEVAREXCEPTION$HRESULT () at tiUtils.pas:2784
#3  0x0824c558 in VARIANTS_VARRESULTCHECK$HRESULT () at tiUtils.pas:2784
#4  0x08247e69 in VARIANTS_SYSVARCLEARPROC$TVARDATA () at tiUtils.pas:2023
#5  0x080605dd in SYSTEM_VARIANT_CLEAR$TVARDATA ()
#6  0x08062326 in fpc_decref ()
#7  0x0823e1c1 in TIVARIANTARRAYTOSTRING (AVALUE={VARIANT} 0xbfe6562c)
    at tiUtils.pas:1309
#8  0x082b6bb5 in TTESTTIUTILS__TIVARIANTARRAYTOSTRING (this=0xb78eb240)
    at tiUtils_TST.pas:1709
#9  0x082007e7 in FPCUNIT_TTESTCASE_$__RUNTEST ()
#10 0x0820071e in FPCUNIT_TTESTCASE_$__RUNBARE ()
#11 0x082017aa in FPCUNIT_PROTECTTEST$TTEST$TTESTRESULT ()
#12 0x082018a1 in FPCUNIT_TTESTRESULT_$__RUNPROTECTED$TTEST$TPROTECT ()
#13 0x082017e0 in FPCUNIT_TTESTRESULT_$__RUN$TTESTCASE ()
#14 0x082006cb in FPCUNIT_TTESTCASE_$__RUN$TTESTRESULT ()
#15 0x082011c1 in FPCUNIT_TTESTSUITE_$__RUNTEST$TTEST$TTESTRESULT ()
#16 0x083cf820 in _$FPCUNIT$_Ld39 ()
#17 0x08201176 in FPCUNIT_TTESTSUITE_$__RUN$TTESTRESULT ()
#18 0x00000070 in ?? ()
#19 0xb7f4f760 in ?? ()
#20 0xb70a1980 in ?? ()
#21 0x00140022 in ?? ()
#22 0xb7a93680 in ?? ()
<...snip...>
----------- Backtrace End ---------------


-- 
Graeme Geldenhuys

There's no place like S34° 03.168'  E018° 49.342'



More information about the fpc-pascal mailing list