converting delphi 2007 code to delphi XE2 -- emptyparam problem

Hi, I am trying to convert my applicantion code from delphi 2007 to delphi XE2 and i got stuck in this error "[DCC Error] ADODB_TLB.pas(4888): E2033 Types of actual and formal var parameters must be identical". This happens when we use emptyparam as an argument in a function that wants an olevariant.
Example:

function TAcadDatabase.CopyObjects(Objects: OleVariant): OleVariant;
begin
  Result := DefaultInterface.CopyObjects(Objects, EmptyParam, EmptyParam);  //this is where we get the ERROR
end;

The coyobjects function as this signature: "    function CopyObjects(Objects: OleVariant; Owner: OleVariant; var IdPairs: OleVariant): OleVariant; safecall;  "

This sample of code is from a unit that was imported (to *.pas) from a autocad library in delphi 2007. I tryied to import that same library in delphi XE2 and get lots of erros so i decided do use the .pas that i've obtained importing in delphi 2007. But don't work :-(

Help please...

thank you
0
Lara
2/8/2012 2:12:44 PM
📁 embarcadero.delphi.general
📃 4258 articles.
⭐ 0 followers.

💬 4 Replies
👁️‍🗨️ 3527 Views

Hi,

Did you try to include Variants in that unit? "uses Variants" 
I had similar problem converting outlook source. Before you
didn't have to do "uses Variants" in the unit when using EmptyParam.

Greets.
0
Robert
2/8/2012 2:43:57 PM
Hi, thank you for your help. I had already included the Variants in that unit and the error persisted.
The only way we found out to solve the problem was to use a local variable of olevariant type, then assigned that variable with EmptyParam and use it to call the function. The examples is below.

function TAcadDocument.CopyObjects(Objects: OleVariant; Owner: OleVariant): OleVariant;
*var*
  *argumento: olevariant;*
begin
  *argumento := EmptyParam;*
  Result := DefaultInterface.CopyObjects(Objects, Owner, argumento);
end;

thank you.

Problem solved! :-)




> {quote:title=Robert Triest wrote:}{quote}
> Hi,
> 
> Did you try to include Variants in that unit? "uses Variants" 
> I had similar problem converting outlook source. Before you
> didn't have to do "uses Variants" in the unit when using EmptyParam.
> 
> Greets.
0
Lara
2/8/2012 3:03:35 PM
Hello Lara,

> Hi, I am trying to convert my applicantion code from delphi 2007
> to delphi XE2 and i got stuck in this error "[DCC Error]
> ADODB_TLB.pas(4888): E2033 Types of actual and formal var
> parameters must be identical".

In earlier versions, EmptyParam was defined as a global OleVariant variable 
in both the Variants.pas and OleCtrls.pas units.  In XE2, EmptyParam is now 
defined in both units as a function that returns an OleVariant value.  The 
last parameter of the COM object's function is a 'var' parameter, so it requires 
a real variable to be passed to it.  That is why your D2007 code worked (you 
were passing a variable where a reference to a variable is expected) and 
why you have to add a local variable in your XE2 code (you cannot pass EmptyParam()'s 
result directly to a 'var' parameter).

The RTL source in XE2 does have an EMPTYPARAM_VAR define to go back to the 
old behavior, but I imagine that means you would have to recompile the RTL 
to enable it.

--
Remy Lebeau (TeamB)
0
Remy
2/8/2012 5:39:37 PM
> In earlier versions, EmptyParam was defined as a global OleVariant variable 
> in both the Variants.pas and OleCtrls.pas units.  In XE2, EmptyParam is now 
> defined in both units as a function that returns an OleVariant value.  The 
> last parameter of the COM object's function is a 'var' parameter, so it requires 
> a real variable to be passed to it.  That is why your D2007 code worked (you 
> were passing a variable where a reference to a variable is expected) and 
> why you have to add a local variable in your XE2 code (you cannot pass EmptyParam()'s 
> result directly to a 'var' parameter).

Why would they change something so significant?
How it this better when earlier code that passes EmptyParam by reference, now has to be fixed?

Edited by: Frederic Bell on Feb 18, 2012 9:47 PM

Edited by: Frederic Bell on Feb 18, 2012 9:49 PM
0
Frederic
2/19/2012 5:49:39 AM
Reply: