Solved

OLEVariant problem

Posted on 2002-06-11
15
2,780 Views
Last Modified: 2008-02-26
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

0
Comment
Question by:jpcs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
15 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 7072033
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


 

0
 
LVL 9

Expert Comment

by:ITugay
ID: 7072041
seems error in second parameter

also you can try:

NetSize.SetSlotValue (OTA_LOGO_LOGO, @test);


0
 
LVL 1

Author Comment

by:jpcs
ID: 7073306
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jpcs
ID: 7073382
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
0
 
LVL 9

Expert Comment

by:ITugay
ID: 7074673
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.
0
 
LVL 2

Expert Comment

by:SChertkov
ID: 7074856
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);
0
 
LVL 1

Author Comment

by:jpcs
ID: 7075192
Hi Igor!

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

Thanks anyway
0
 
LVL 1

Author Comment

by:jpcs
ID: 7075199
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
0
 
LVL 2

Expert Comment

by:SChertkov
ID: 7075202
Did you try
NetSize.SetSlotValue (OTA_LOGO_LOGO, test.OleObject) ?
0
 
LVL 2

Accepted Solution

by:
SChertkov earned 200 total points
ID: 7075210
It is no matter.
In this case use test.DefaultInterface
0
 
LVL 1

Author Comment

by:jpcs
ID: 7075216
I just figured now something:

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

Does this helps with the answer?

thanks
0
 
LVL 1

Author Comment

by:jpcs
ID: 7075223
No, SChertkov, DefaultInterface returns IAGFileRef, and delphi requires OleVariant.
0
 
LVL 2

Expert Comment

by:SChertkov
ID: 7075232
Try following
var
  DummyVar: OleVariant;


begin
.....

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

0
 
LVL 1

Author Comment

by:jpcs
ID: 7075241
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;
0
 
LVL 2

Expert Comment

by:SChertkov
ID: 7075242
Try following
var
  DummyVar: OleVariant;


begin
.....

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

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question