Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-04

fpc + linux, problem with VarArrayCreate, variant

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ryszard Kadow

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;
Flávio Etrusco
to Ryszard Kadow

You can simplify the use-case a lot: simply trying to assign any value to a Variant after it's been assigned an array throws an exception. It seems one is not allowed to reassign a Variant which was already initialized to a VarArray - which IMHO is a good thing ;-) Variable reuse should have a capital punishment =P

BTW, I couldn't even create a varWord array (TBH I never did this in Delphi anyway), FPC 2.0.2 throws a not-much-useful "VarArrayCreate exception".

After assigning a varByte array, assigning '0' or '0.0' throws "no interface supported" and assigning 'Null' or calling 'VarClear' throws "varpointer is locked".

It doesn't seem to be any reports about these bugs in the tracker...

-Flávio

Ryszard Kadow wrote 74 lines
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; _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal