Board index » delphi » Invalid Variant Type when initializing Variant

Invalid Variant Type when initializing Variant


2005-05-27 07:33:51 AM
delphi32
I am using D7.1. I am working with some maintenance code that randomly
gives an "Invalid Variant Type" exception (EVariantBadVarTypeError). I have
tracked it down the following code.
TSearchType = record
Cache : Boolean;
Value : Variant;
Key : Longint;
Tree : TSortNode;
end;
TSearchTypeArray = array [0..100000] of TSearchType;
PSearchTypeArray = ^TSearchTypeArray;
TMyClass = class
private
SearchTable : PSearchTypeArray;
NumItems : Longint;
MaxedLimit : Boolean;
public
constructor Create(size : Longint);
end
constructor TMyClass.Create(size : Longint);
var
i : Longint;
begin
inherited Create;
// Allocate the Search table entries.
NumItems := size;
GetMem(SearchTable, NumItems * SizeOf(TSearchType));
// Initialize the Search table entries to Unassigned.
for i := 0 to NumItems - 1 do
begin
SearchTable^[i].Value := Unassigned; // error randomly occurs on this
line
SearchTable^[i].Cache:=false;
SearchTable^[i].tree:=NIL;
end;
end;
I was under the impression that I should only get this error if I try to
assign a normal datatype to an unassigned variant.
Any ideas?
 
 

Re:Invalid Variant Type when initializing Variant

I posted this in the incorrect newgroup. Reposted in
borland.public.delphi.rtl.win32.
"Isaac Alexander" <XXXX@XXXXX.COM>writes
Quote
I am using D7.1. I am working with some maintenance code that randomly
gives an "Invalid Variant Type" exception (EVariantBadVarTypeError). I
have
tracked it down the following code.

TSearchType = record
Cache : Boolean;
Value : Variant;
Key : Longint;
Tree : TSortNode;
end;

TSearchTypeArray = array [0..100000] of TSearchType;
PSearchTypeArray = ^TSearchTypeArray;

TMyClass = class
private
SearchTable : PSearchTypeArray;
NumItems : Longint;
MaxedLimit : Boolean;
public
constructor Create(size : Longint);
end

constructor TMyClass.Create(size : Longint);
var
i : Longint;
begin
inherited Create;

// Allocate the Search table entries.
NumItems := size;
GetMem(SearchTable, NumItems * SizeOf(TSearchType));

// Initialize the Search table entries to Unassigned.
for i := 0 to NumItems - 1 do
begin
SearchTable^[i].Value := Unassigned; // error randomly occurs on
this
line
SearchTable^[i].Cache:=false;
SearchTable^[i].tree:=NIL;
end;
end;

I was under the impression that I should only get this error if I try to
assign a normal datatype to an unassigned variant.

Any ideas?