Cast object as OleVariant in Delphi

Posted by Alan Clark on Stack Overflow See other posts from Stack Overflow or by Alan Clark
Published on 2010-05-05T08:23:06Z Indexed on 2010/05/05 8:28 UTC
Read the original article Hit count: 184

Filed under:
|
|

Is there a way to pass a wrap and unwrap a TObject descendent in an OleVariant? I am trying to pass a TObject across automation objects. I know it's not a good idea but I don't have a good alternative.

Something like this:

function GetMyObjAsVariant;
var
  MyObj: TMyObj;
begin
  MyObj := TMyObj.Create;
  result := OleVariant(MyObj);
end;

Which would be used by a client as

var
  MyObj: TMyObj;
begin
  MyObj := GetMyObjAsVariant as TMyObj;
end;

This fails to compile, returning

E2015 Operator not applicable to this operand type.

© Stack Overflow or respective owner

Related posts about delphi

Related posts about com