2
votes

I would like to query the display name of an OLE application, which is embedded in my Delphi XE4 Win32 app.

TOleContainer class is used and the container can contain different OLE applications (e.g. MS Word, MS Excel, ...), dependent on what file is edited within.

What I want to be returned is Microsoft Word 2007 (or 2010 or 2013 or ...) or at least Microsoft Word, as it is displayed in the title bar of a normal Word instance.


EDIT: TOndrej's answer was very helpful. Thank you.

Unfortunally, as described in my comment underneath his answer, it does not show the real application caption. I found this question on SO. It's said there, that I could access the host application's caption with _Application.Caption property. I don't have an instance of _Application but IOleObject. Typecast (MyOleObjectInterface as _Application) failed.

How can the OleObject be accessed as _Application?

1
What is _Application? It's not an interface type that I recognise.David Heffernan
@David You can find it in units Excel2010 and Word2010 in Delphi XE4, for example.René Hoffmann
There's not a single application interface that all interfaces derive from or support.David Heffernan

1 Answers

6
votes

See IOleObject.GetUserType method:

function GetOleObjectAppName(const OleObject: IOleObject): string;
var
  AppName: PWideChar;
begin
  OleCheck(OleObject.GetUserType(USERCLASSTYPE_APPNAME, AppName));
  try
    Result := AppName;
  finally
    CoTaskMemFree(AppName);
  end;
end;

Usage example:

  ShowMessage(GetOleObjectAppName(OleContainer1.OleObjectInterface));