Solved

Acces to internal data from a COM interface.

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

19 Experts available now in Live!

Get 1:1 Help Now