• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

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 ?
0
rowem
Asked:
rowem
  • 3
1 Solution
 
freterCommented:
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
0
 
freterCommented:
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
0
 
rowemAuthor Commented:
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
0
 
freterCommented:
Hi Michael!

To set the parent is always neccessary and to forget it is the most common mistake when creating objects on the fly ;-)

Nevertheless, glad I could help.

Freter
0

Featured Post

Technology Partners: 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!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now