Solved

Acces to internal data from a COM interface.

Posted on 1998-04-06
1
155 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

12 Experts available now in Live!

Get 1:1 Help Now