[fpc-pascal] fpc + linux, problem with VarArrayCreate, variant

Ryszard Kadow ryszard at sims.pl
Thu Apr 20 10:46:23 CEST 2006


helllo!


Variable V is variant type, 
in first step V must be  array type (V := VarArrayCreate)
in second step type varBYte.

In delphi and lazarus everything is ok.

in  fpc 2.0.2 (linux) program show  error  EVariantInvalidOpError.

See example below.

where is error?


=================


example:




var v      : variant;
    v2     : variant;
    p_wart : variant;
Type Tarr = array[0..2] of word;
var  p : ^Tarr;
begin
  V := VarArrayCreate( [0,2], varword);
  p := VarArrayLock(V);
  try
    writeln('0');
    p^[0] := word(11);
    writeln('1');
    P^[1] := word(22);
    writeln('2');
    p^[2] := word(33);
    writeln('3');
  finally
    p_wart := V;
    VarArrayUnlock(V);
    VarClear(V);
  end;

  writeln('p[1]=', p_wart[1]);
  try
    if VarIsArray(V) then writeln('V is array');
    V := Unassigned;
    
    V2 := Byte(0);
    writeln('4');     // ok !
    V := V2;          // <-- An unhandled exception occurred at $080645C6 :
    writeln('5');     // EVariantInvalidOpError : Invalid variant operation

    V  := Byte(2);
    writeln('6');
    p_wart := V;
    writeln('7');
  except
    on E: Exception do Writeln(E.Message, ', nr=',E.HelpContext);
  end;

  readln;


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20060420/538f85e0/attachment.html>


More information about the fpc-pascal mailing list