?
Solved

Acces to internal data from a COM interface.

Posted on 1998-04-06
1
Medium Priority
?
162 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 450 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

Technology Partners: 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 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…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

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