Solved

OLEVariant problem

Posted on 2002-06-11
15
2,756 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 259
System restore point 4 91
proper way to parse text with delphi 7 99
Using idhttp to login to instagram 2 75
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

929 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

9 Experts available now in Live!

Get 1:1 Help Now