Solved

How to destroy an activex object?

Posted on 2011-03-16
3
905 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Ephraim Wangoya
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

740 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