Link to home
Start Free TrialLog in
Avatar of rowem
rowem

asked on

Creating ActiveX objects on the fly

I wish to create ActiveX objects on the fly using Delphi 3 using only their GUID. If I create a form containing a TOleContainer object I can use this to host an ActiveX object. However I don't know the number of ActiveX objects I wish to host at design time and creating TOleContainer objects on the fly using TOleContainer.Create seems to fail. How can I solve this problem ?
Avatar of freter
freter

Hi rowem! Try this:

procedure TForm1.Button1Click(Sender: TObject);
var Cont: TOleContainer;
begin
  Cont := TOleContainer.Create(self);
  with cont do begin
    parent := self;
    left := 50;
    top := 50;
    width := 200;
    height := 300;
    visible := true;
    CreateObject('word.application', false);
    DoVerb(ovShow);
  end;
end;

This code creates OleContainers without any problems.
Cheers,
Freter
Ah, BTW: The DoVerb(ovShow) doesn't work with Word.Application... Sorry!
Check it out with any ActiveForm that you have created using Delphi. It works out alright, I have tried it myself.

Regards, Freter
Avatar of rowem

ASKER

Freter,

If you would like the points please feel free to submit this as the answer. The Parent:=Self is what I hadn't done. I would have thought that the parent should be set in the Create constructor though, since we pass it through as a parameter....

Regards, Michael
ASKER CERTIFIED SOLUTION
Avatar of freter
freter

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