Re: EInvalidOp in D2007 FillChar & Move



Hi John,

From your symptoms, it appears that some other code has left data on the
FPU stack, causing it to overflow when FillChar or Move try to use it. Do
you have a code snippet with which I can reproduce the symptoms to
investigate this further?

Some of the compiler magic routines pass a floating point parameter on the
FPU stack. If the called routine in turn calls FillChar or Move it could
lead to trouble.

Example:


program Program1;

{$APPTYPE CONSOLE}

uses
SysUtils, Variants;

type
TMyVariantClass = class(TCustomVariantType)
public
procedure Clear(var V: TVarData); override;
procedure Copy(var Dest: TVarData; const Source: TVarData;
const Indirect: Boolean); override;
end;

var
MyVarType: TMyVariantClass;
DummyData: array[0..100] of Byte;

{ TMyVariantClass }

procedure TMyVariantClass.Clear(var V: TVarData);
begin
FillChar(DummyData, SizeOf(DummyData), 0);
end;

procedure TMyVariantClass.Copy(var Dest: TVarData; const Source: TVarData;
const Indirect: Boolean);
begin
end;

procedure Test;
var
TestVar1, TestVar2: Variant;
MyInt: Integer;
MyDouble: Double;
begin
MyInt := 1;
MyDouble := 1;
{This works}
TVarData(TestVar1).VType := MyVarType.VarType;
TestVar1 := MyInt;
{This doesn't work}
TVarData(TestVar2).VType := MyVarType.VarType;
TestVar2 := MyDouble;
end;

begin
MyVarType := TMyVariantClass.Create;
try
Test;
except
Writeln('FAIL');
end;
end.


Regards,
Pierre


.