Solved

How to destroy an activex object?

Posted on 2011-03-16
3
871 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now