Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 954
  • Last Modified:

How to destroy an activex object?

Hi,

I am using an imaging ActiveX control called TImageMan.  I've placed one TImageMan control on the form.  From that  component, I create many instances "on the fly."  I add a row and column number to the end of "IM" ( e.g IM11, IM12, IM21,IM22) to make each instance unique.  See code  below.


How do I destroy the instances of TImageMan (IM11, IM12, IM21, IM22, etc...?) so I can rerun the program multiple times without closing it down?

Thanks.
type
TForm1 = class(TForm)
    IM: TImageMan;

procedure....
var
  IM : TImageMan;
.
.
.
IM :=  TImageMan.Create(self);
IM.Name := 'IM'+IntToStr(i)+IntToStr(j);
.
.
end;

Open in new window

0
IT79637
Asked:
IT79637
1 Solution
 
jimyXCommented:
Use for loop and free all of them:

procedure....
var
  IM : TImageMan;
.
.
.
IM :=  TImageMan.Create(self);
IM.Name := 'IM'+IntToStr(i)+IntToStr(j);
.
.
//var
//  k,l : integer;
for k := 1 to i do
  for l := 1 to j do
    begin
      (FindComponent('IM'+IntToStr(k)+IntToStr(l)) as TImageMan).Free;
    end;
end;
0
 
Ephraim WangoyaCommented:

You dont need to destroy the components since the are owned by the form

IM :=  TImageMan.Create(self);

When the form is destroyed, the component is destroyed as well, so you dont have to worry about it
0
 
IT79637Author Commented:
Works for me!
Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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