Delphi 5 & TPowerPointApplication component

Hello,

I want to use The TPowerPointApplication to open a powerpoint presentation from my app. I set the ConnectKind property to "ckNewInstance" but when I connect the component, it only works if powerpoint is already running.

Why the ConnectKind property doesn't  work like ConnectKind in TWordApplication or TExcelApplication (which open a new instance every time I connect) ?

What Can I do?
LVL 1
logosapienceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RBertoraCommented:
You can launch ppt your self:

try something along the lines of:

try
  ppt.connect;
except on exception do
begin
  WinExec(PChar(ExecString),SW_SHOW);
  ppt.connect;
end;
end;

Rob ;-)
0
kretzschmarCommented:
8^) just keep looking ...
0
logosapienceAuthor Commented:
I know that it works like that but
 - There is a message when powerpoint appears (wizard)
 - If there is already a powerpoint opened before launching my app,  the presentation is opened in it and when the component disconnects, any powerpoint opened is killed (even if it were executed before my app).
- Word & Excel components work well, why Powerpoint doesn't ?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

RBertoraCommented:
logosapience :
Why?:
Because, the order in which the delphi developers developed those components was:

Word.
Excell.
Powerpoint.

Powerpoint was not tested as rigirously as word & excell, and they will only likely fix that in a bug release.



But if all you want to do is open and run a presentation then you can do the following..

uses comobj;

var
  PowerPointApp : Variant;

// to connect to ppt or load it if it is not running:
  try
    PowerPointApp := GetActiveOleObject('PowerPoint.Application');
  except on exception do
    PowerPointApp := CreateOleObject('PowerPoint.Application');
  end;

// to show ppt and windowstate 3 = maximise:
  PowerPointApp.Visible := True;
  PowerPointApp.Caption := 'MyPowerpoint...';
  PowerPointApp.WindowState := 3;


// to load the presentation
      PowerPointApp.Presentations.Open('c:/LoadFileName.ppt');


// to run the presentation

  PowerPointApp.Activepresentation.SlideShowSettings.run;

Rob ;-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
logosapienceAuthor Commented:
OK thanks, it works well but
 - When powerPoint is already there, it doesn't create a new instance and take the already exiting powerpoint.
- How can I close powerPoint after?
0
RBertoraCommented:
 try
    // this line connects to an open power point,
    PowerPointApp := GetActiveOleObject('PowerPoint.Application');
  except on exception do
//this line will open a new version of ppt
    PowerPointApp := CreateOleObject('PowerPoint.Application');
  end;

so if you want to always open a  new ppt then just use one line instead of the above:
    PowerPointApp := CreateOleObject('PowerPoint.Application');

to quit : simply PowerpointApp.Quit;
Rob ;-)
0
logosapienceAuthor Commented:
It keeps the already existing pwp with :
PowerPointApp := CreateOleObject('PowerPoint.Application');

When I do PwpApp.Quit, the presentation is closed but pwp remains active... I only close when I close my app...
0
RBertoraCommented:
Ok I can give you a work around solution, but could you please first confirm that what is happening on my machine also is happening on yours:

I can't seem to load 2 power point applications...ie just by double clicking the exe file, it seems power point only alows one instance to run at a time... if this is the case then I am working on a solution to your problem as we speak

Rob ;-)
0
logosapienceAuthor Commented:
You're right, I can't launch 2 instances of Pwp...
0
RBertoraCommented:
Ok because Powerpoint does not allow more than one instance, the only thing left in your last question was to close power point.. here is a way to do it:

Rob;-)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, comobj;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function FindWindowByTitle( const Title : string ) : HWnd;
  end;

var
  Form1: TForm1;
  PowerPointApp : Variant;
  si  : TStartupInfo;
  pi  : TProcessInformation;
  dw1 : dword;

implementation

{$R *.DFM}

function TForm1.FindWindowByTitle( const Title : string ) : HWnd;
var
PrevWin, NextWin : HWnd;
WinName  : array[0..256] of char;
begin
  NextWin:=FindWindow(nil,nil);
  GetWindowText(NextWin, WinName, SizeOf(WinName) );
  repeat
    PrevWin:=NextWin;
    GetWindowText(NextWin, WinName, SizeOf(WinName) );
    NextWin:=GetNextWindow(NextWin,GW_HWNDNEXT);
  until (PrevWin = NextWin) or (StrPas(WinName) = Title);
  if (StrComp(WinName, PChar(Title)) = 0 ) then begin
    Result:= PrevWin;
  end
  else
  begin
    Result:= 0;
  end;
end;


// connect to powerpoint
procedure TForm1.Button1Click(Sender: TObject);
begin
  PowerPointApp := CreateOleObject('PowerPoint.Application');
  PowerPointApp.Visible := True;
  PowerPointApp.Caption := 'MyPowerpoint...';
  PowerPointApp.WindowState := 3;
end;

// close powerpoint
procedure TForm1.Button2Click(Sender: TObject);
begin
  sendmessage(FindWindowByTitle('MyPowerpoint...'),WM_CLOSE,0,0);
end;

end.
0
logosapienceAuthor Commented:
Thanks very much for your help !!
0
RBertoraCommented:
Pleasure, and thanks for the Agrade!
Rob ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.