Solved

How to destroy an activex object?

Posted on 2011-03-16
3
890 Views
Last Modified: 2012-05-11
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
Comment
Question by:IT79637
3 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 250 total points
ID: 35148994
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
 
LVL 32

Expert Comment

by:ewangoya
ID: 35149767

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
 
LVL 1

Author Closing Comment

by:IT79637
ID: 35160118
Works for me!
Thanks!
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question