Solved

GetActiveOleObject question

Posted on 2004-09-29
6
1,265 Views
Last Modified: 2008-01-09
Hi,
I am trying to use an Activex object in my application.
The VB sample coming with the object works properly opening an Application and a Document; the sample sounds like this:

Dim App, Data, pathToDoc
    Set App = GetObject(, "XXXXX.Application")
    pathToDoc = App.GetActiveDocPath

    If pathToDoc="" Then 'if no data file exists
........................
    End If
 
    Set Data = GetObject(pathToDoc) '..where pathToDoc is the full name of the Document referenced by the object

And I get full controll over the Data object

I don't know how to code in Delphi
Set Data = GetObject(pathToDoc)

Can anyone help me?
Thanks
0
Comment
Question by:dciambrone
[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
6 Comments
 
LVL 2

Accepted Solution

by:
php4delphi earned 250 total points
ID: 12183661
Delphi has no exact equivalent for GetObject function. If you want execute Application (there is no active application running) you have to use CreateOleObject function, otherwise GetActiveOleObject function.
For example,

procedure StartOrLinkToWord;
var
 V: Variant;
begin
 try
  V := GetActiveOleObject('Word.Application');
 except
  V := CreateOleObject(Word'.Application');
 end;

 // Do something with V here...
end;
0
 

Author Comment

by:dciambrone
ID: 12188432
My question is:
With the previous Activex version I used the Delphi method CreateOleObject and everithing was OK.
The new release of the activex has some problems and I am trying to work around the problem waiting for this problems to be fixed.
The above VB code works fine; is there a way to let Delphi work anyway?
Thanks in advance
0
 
LVL 6

Assisted Solution

by:david_barker
david_barker earned 250 total points
ID: 12189481
You can't exactly do the same with Delphi.
What VB does with GetObject when you just supply a filename is to determine the application to start and the object to activate, based on the file name you provide.
In Delphi, you will have to know the classname of this application, ie. "Word.Application" if the file is a Word document.

procedure Test;
var
  App       : Variant;
  pathToDoc : Variant;
  Data      : Variant;
begin
  App:=CreateOleObject('XXXXX.Application');
  pathToDoc:=App.GetActiveDocPath;
  if pathToDoc='' then // if no data file exists
  begin
    // .....
  end;
  //
  Data:=CreateOleObject('YYYYY.Application');
  Data.Open(pathToDoc);   // Open might be the correct method in your case
end;
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 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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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