Solved

OLEVariant problem

Posted on 2002-06-11
15
2,744 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now