Solved

Acces to internal data from a COM interface.

Posted on 1998-04-06
1
160 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
[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
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

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!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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