Solved

OLEVariant problem

Posted on 2002-06-11
15
2,770 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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