Solved

Acces to internal data from a COM interface.

Posted on 1998-04-06
1
159 Views
Last Modified: 2010-05-18
I've written a function that has 2 interfaces IObj1 en IObj2 for parameters.  The interfaces are related to a COM object OBJ.  This OBJ has an integer variable in his private section.  How can I access this integer from IObj1 or IObj2, without declaring additional  methods in the interfaces.  
This is a simplification of the problem.   The answer has to work for strings, double and even objects.
I already know the tricj with the GetInterfaceEntry etc... .  Is there a clean solution to this problem ?

Johan
0
Comment
Question by:ppr
1 Comment
 
LVL 1

Accepted Solution

by:
AndersWP earned 150 total points
ID: 1361307
You can not directly access internal variables of a COM object, you have to go through an interface; that is the fundamental principle of COM.

If you wnat to access an integer in a COM object and you do not want to enlarge your existing interfaces IObj1 and IObj2 (or whatever they are called), you can define a new interface:


IMyPrivateInteger = Interface
  [IMyPrivateInteger_GUID]
  Function GetValue: Integer;
End;

TMyObject = Class(BaseClass, IMyPrivateInteger, IObj1, iObj2)
Private
  FMyInteger: Integer;
Public
  Function GetValue: Integer;
  ...
End;

If you have e.g. an IObj1 interface to your object, you can get access the integer variable like this:

Var
  MyPrivateInteger: IMyPrivateInteger;

Begin
  Obj1.QueryInterface(IMyPrivateInteger_GUID,
                      MyPrivateInteger);
  i:=MyPrivateInteger.GetValue;
End;

Not exactly simple, but it should work. Note that you will have make interface methods for retrieving each of the private fields that you want to expose.

I hope this will help you.

Greetings,
AndersWP
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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