Link to home
Start Free TrialLog in
Avatar of jpcs
jpcs

asked on

OLEVariant problem

Hi!

I have a ActiveX component, that is giving me some problems. I'll try to explain :

The ActiveX after install, was instaled correctly.
However, there was another COM that didn't install, but with Project>Import Type Library>Install (after finding the .DLL file), it worked just fine.

The problem, was when an instruction requested a OLEVARIANT var type, and in a demo written in VB it worked just fine, in Delphi I just got a "Types of actual and formal var parameters must be identical" error.

As follows, I'll post the VB and my Delphi code, so that you may help me.


Thanks


======= VB CODE ==========
Public Sub OperatorLogo(sPath As String, sTelNumber As String, dManufacturer As Long, Optional sPhoneType As Long)
Dim oFileRef As New AGFileRef
   
    oFileRef.SetFileFullPath (sPath)
    oFileRef.SetFilePublicName ("OperatorLogo.dat")
    oFileRef.SetAutoDelete (False)
     

    oConfigFrame.SetSlotValue OTA_LOGO_TARGET, sTelNumber
    oConfigFrame.SetSlotValue OTA_LOGO_PHONE_MANUFACTURER, dManufacturer   '// Only Nokia for the moment
   
   
    ' oConfigFrame.SetSlotValue OTA_LOGO_PHONE_MODEL, sPhoneType            '// Optional slot
   
    oConfigFrame.SetSlotValue OTA_LOGO_LOGO, oFileRef <==== Line OK in VB!!!

========= DELPHI CODE ===========
var MyNumber : OleVariant;
    Manufactor : OleVariant;
    test : TAGFileRef;

const OTA_LOGO_TARGET = 'Target';
      OTA_LOGO_PHONE_MANUFACTUROR = 'PhoneManufacturer';
      OTA_LOGO_LOGO = 'Logo';
begin

   test := TAGFileRef.Create(Self);
   test.SetFileFullPath('d:\1.bmp');
   test.SetFilePublicName('PictureMessage.dat');
   test.SetAutoDelete(0);

   MyNumber := '+351919004504';
   Manufactor := OTA_LOGO_PHONE_MANUFACTUROR;
   NetSize.SetSlotValue (OTA_LOGO_TARGET, MyNumber);
   NetSize.SetSlotValue(OTA_LOGO_PHONE_MANUFACTUROR, Manufactor);

   NetSize.SetSlotValue (OTA_LOGO_LOGO, test); <===== ERROR LINE!!!


=========
If you need any code, you can also write me at jsantos98@softhome.net


Best Regards
Joao Santos

Avatar of Igor UL7AAjr
Igor UL7AAjr
Flag of Kazakhstan image

hi,

>> "Types of actual and formal var parameters must be identical"

usually you can see this message if paramter declared as VAR but you trying to pass immediate value or constant.

eg:

var
  OTA_LOGO_LOGO: Variant;

begin
  OTA_LOGO_LOGO := 'Logo';
......
  NetSize.SetSlotValue (OTA_LOGO_LOGO, test);
......

-----
Igor


 

seems error in second parameter

also you can try:

NetSize.SetSlotValue (OTA_LOGO_LOGO, @test);


Avatar of jpcs
jpcs

ASKER

Hi Igor!

First of all, thanks for the comment. Howerver, the first one can't be used, since the var MUST be of type "AGFileRef" wich is located in the second ActivX as I tried to explain. (Remember the VB line "Dim oFileRef As New AGFileRef"). Defining it as a string didn't work!


Your second tip simply didn't work.

I think that if there is a way to convert the test var to OLEVariant, it should work, but I haven't been able to do that!

Thanks
Avatar of jpcs

ASKER

Hi Igor!

First of all, thanks for the comment. Howerver, the first one can't be used, since the var MUST be of type "AGFileRef" wich is located in the second ActivX as I tried to explain. (Remember the VB line "Dim oFileRef As New AGFileRef"). Defining it as a string didn't work!


Your second tip simply didn't work.

I think that if there is a way to convert the test var to OLEVariant, it should work, but I haven't been able to do that!

Thanks
Hi,

I see....

There is some problem. OLEVariant can not be assigned to pointer, but any object reference is pointer indeed.
The way to pass Pointer as OLEVariant parameter is convert pointer to integer. I'm not sure it will work but try:

var
  O: OLEVariant;
.....
  O := Integer(test);

in some cases this trick can pass. There is sample how to convert pointer to OLEvariant and then back:

var
  O: OLEVariant;
  T: TObject;
begin
  T := TObject.Create;
  O := Integer(T);
  T := Pointer(Integer(O));
.......

Seems it's all help I can provide you.

------
Igor.
If you import as TAGFileRef from TypeLib it means what
TAGFileRef is Delphi wrapper for ActiveX.
In this case you must pass ActiveX as
NetSize.SetSlotValue (OTA_LOGO_LOGO, test.OleObject);
Avatar of jpcs

ASKER

Hi Igor!

Once again it didn't work... It just passed the pointer ID (Integer).

Thanks anyway
Avatar of jpcs

ASKER

Hi SChertkov!

Sorry, but it doesn't have that property.

The NetSize Component has it, but has I stated before, the ActiveX from TAGFileRef had to be manually inserted using Project>Import Type Library>Install (the ActiveX file appear only there and not on the usual Component>Import ActiveX control).

Any Idea?

Thanks
Did you try
NetSize.SetSlotValue (OTA_LOGO_LOGO, test.OleObject) ?
ASKER CERTIFIED SOLUTION
Avatar of SChertkov
SChertkov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jpcs

ASKER

I just figured now something:

The NetSize Component derives from TOleControl, and the TAGFileRef from TOleServer!

Does this helps with the answer?

thanks
Avatar of jpcs

ASKER

No, SChertkov, DefaultInterface returns IAGFileRef, and delphi requires OleVariant.
Try following
var
  DummyVar: OleVariant;


begin
.....

DummyVar := test.DefaultInterface as IDispatch;
NetSize.SetSlotValue (OTA_LOGO_LOGO, DummyVar);
....

Avatar of jpcs

ASKER

Sorry.... working Code:

var MyResult : OleVariant;
    test : TAGFileRef;

begin
   test := TAGFileRef.Create (self);
   test..... // AGFileRef properties
   
   MyResult := test.DefaultInterface;
   NetSize.SetSlotValue (OTA_LOGO_LOGO, MyResult);

   ...
end;
Try following
var
  DummyVar: OleVariant;


begin
.....

DummyVar := test.DefaultInterface as IDispatch;
NetSize.SetSlotValue (OTA_LOGO_LOGO, DummyVar);
....