Link to home
Start Free TrialLog in
Avatar of plumothy
plumothyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Show Powerpoint Presentation Inside Delphi Application

I am trying to use TOleContainer to show a Powerpoint Presentation within the main form of my Delphi application.

As you can see from the attached code, I am part of the way there.

How do I issue commands like Go To Next Slide?

How do I set up event handlers (like you can with TPowerpointApplication - OnSlideShowNextBuild, for example)?



unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtnrs;
 
type
  TForm1 = class(TForm)
    oc1: TOleContainer;
    OpenButton: TButton;
    ShowButton: TButton;
    NextSlideButton: TButton;
    procedure OpenButtonClick(Sender: TObject);
    procedure ShowButtonClick(Sender: TObject);
    procedure NextSlideButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.OpenButtonClick(Sender: TObject);
// open the presentation
begin
  // this loads the file and displays slide 1 in the OLEContainer - great
  oc1.CreateObjectFromFile('APresentation.ppt', false);
end;
 
procedure TForm1.ShowButtonClick(Sender: TObject);
  // show the presentation
begin
  // this does nothing - I thought it would start showing the presentation
  oc1.DoVerb(1);
end;
 
procedure TForm1.NextSlideButtonClick(Sender: TObject);
// goto next slide
begin
  // I have no idea how to do this
end;
 
end.

Open in new window

Avatar of plumothy
plumothy
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I have made a little bit of progress...

I can now run the presentation, but I still don't know how to force it to show inside the OleContainer.

I would still also like to know how to get at events like OnSlideShowNextBuild, etc.

The attached code shows what I have done so far.
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtnrs, OleServer, PowerPointXP;
 
type
  TForm1 = class(TForm)
    oc1: TOleContainer;
    OpenButton: TButton;
    ShowButton: TButton;
    NextSlideButton: TButton;
    PowerPointApplication1: TPowerPointApplication;
    procedure OpenButtonClick(Sender: TObject);
    procedure ShowButtonClick(Sender: TObject);
    procedure NextSlideButtonClick(Sender: TObject);
  private
    { Private declarations }
    Pres: OleVariant;
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.OpenButtonClick(Sender: TObject);
// open the presentation
begin
  // this loads the file and displays slide 1 in the OLEContainer - great
  oc1.CreateObjectFromFile('APresentation.ppt', false);
  oc1.Run;
  Pres := oc1.OleObject;
end;
 
procedure TForm1.ShowButtonClick(Sender: TObject);
// show the presentation
begin
  // this works, but it shows full screen or in a separate Powerpoint window
  // depending on the value of Pres.SlideShowSettings.ShowType
  Pres.SlideShowSettings.Run;
 
  // how do I get it to run the show inside the OleContainer?
 
end;
 
procedure TForm1.NextSlideButtonClick(Sender: TObject);
// goto next slide
begin
  // This works provided the show is running
  Pres.SlideShowWindow.View.Next;
end;
 
end.

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ziolko,

Many thanks for that!

I can now easily get at all the Powerpoint events.

However, I am still no better off than if I had only used TPowerpointApplication.

The presentation still runs in its own window. The reason I am trying to get it working with TOleContainer is to get the presentation running within my application.

I have seen it done by other programmers, but I don't how they did it!!

Perhaps this is not possible with TOleContainer, I don't know.

Following your suggestion, my amended sample code is attached.
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtnrs, OleServer, PowerPointXP;
 
type
  TForm1 = class(TForm)
    oc1: TOleContainer;
    OpenButton: TButton;
    ShowButton: TButton;
    NextSlideButton: TButton;
    ppa: TPowerPointApplication;
    procedure OpenButtonClick(Sender: TObject);
    procedure ShowButtonClick(Sender: TObject);
    procedure NextSlideButtonClick(Sender: TObject);
  private
    { Private declarations }
    Pres: _Presentation;
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.OpenButtonClick(Sender: TObject);
// open the presentation
begin
  // this loads the file and displays slide 1 in the OLEContainer - great
  oc1.CreateObjectFromFile('APresentation.ppt', false);
  oc1.Run;
  if oc1.OleObjectInterface.QueryInterface(IID__Presentation, Pres) = S_OK then
    ppa.ConnectTo(Pres.Application);
end;
 
procedure TForm1.ShowButtonClick(Sender: TObject);
begin
  // this works, but it shows full screen or in a separate Powerpoint window
  // depending on the value of Pres.SlideShowSettings.ShowType
  Pres.SlideShowSettings.Run;
 
  // how do I get it to run the show inside the OleContainer?
 
end;
 
procedure TForm1.NextSlideButtonClick(Sender: TObject);
// goto next slide
begin
  // This works provided the show is running
  Pres.SlideShowWindow.View.Next;
end;
 
end.

Open in new window

I know that other office apps do "jump out" of olecontainer sometimes depending on office version, I never figured out universal method to deal with it but in case excel method that worked was when I created separate form put olecontainer with Align := alClient.

in your case try also:
Pres.SlideShowSettings.ShowType := ...
or
Pres.PageSetup.SlideSize := ...

ziolko.
Ziolko.

Thanks for that.

I have now tried alClient and every possibility for ShowType, SlideSize, SlideWidth, SlideHeight.

I always get either full screen or a Powerpoint window - never inside my Container.

This is obviously a black art - and those who know how to do it keep it to themselves.
>>This is obviously a black art - and those who know how to do it keep it to themselves.
guess so:)
anyway in case of excel it depends on office version.

ziolko.
Looks like no solution to this, but thanks to ziolko for the information that you provided - it taught me something I wanted to know, even hough it did not solve my problem.
thanks for points and sorry I was unable to give you any happy news

ziolko.