trichview.com

trichview.support




Re: freeing controls


Return to index


Author

Message

Michael Philbrick

Posted: 02/11/2005 19:56:49


Sergey,


I forgot one important thing in my first post.


Actually, my sequence of events is this:


1) AddControlEx (using an instance of a control as shown in the code in my

original post -- btnYes)

2) once the control has been clicked (in this case a button) it is no longer

needed so I call DeleteControl to remove it.

3) if it is needed again as the user is interacting with the document I call

AddControlEx again using the same instance of the local variable (btnYes).

4) again, it is deleted after it is clicked

5) finally, I clear the entire TRichViewEdit control which supposedly frees

the controls or controls.


In my original post, the problem I am having actually happens when I create

the control only once, not twice as in the above example. What I left out

of my description is that I call DeleteControl.


Since I will never have more than one instance of the control at the same

time, it seems that the most logical solution is to be able to call a function

after I am done with the control that truly deletes it and frees the memory

without having to call TRichViewEdit.Clear. I need to make sure that the

pointer to the control is completely freed so that btnYes=nil. This does

not seem to happen even when Clear is called.


Thanks.



"Michael Philbrick" <mphilbrick@integraprise.com> wrote:

>

>Sergey,

>

>Here is my code:

>

>  with rvMacNav do begin

>    btnYes := TBitBtn.Create(nil);

>    AddControlEx('', btnYes, -1, rvvaMiddle);

>    FormatTail;

>    with btnYes do begin

>      Kind := bkYes;

>      Default := False;

>      Width := 50;

>      OnClick := btnYesClick;

>    end;

>  end;

>

>My understanding is that I do not need to free this component. If I call

>rvMacNav.Clear, according to the documentation, this component will be freed.

>

>However, that does not seem to be the result I am getting. I may create

and

>destroy multiple instances during one session. In each case I will create

>an instance, later call Clear, then create another instance, call Clear,

>etc. I will never create two instances without clearing in between.

>

>However, when I run this code in a rvMacNavKeyUp event:

>

>if (btnYes <> nil) and (btnYes.Parent <> nil) and (char(Key) in ['Y','N'])

>then ...

>

>It will return True in the following instance:

>

>1) create the component with the above code.

>2) call rvMacNav.Clear

>3) create the component again.

>4) call rvMacNav.Clear

>

>In other words, it will not return True the first time it is created and

>supposedly destroyed with Clear. It will only happen after the second and

>subsequent Clear statements.

>

>I realize that there may be some problems with my code and I cannot really

>send you all of it. Therefore, could you clarify a few things for me:

>

>1) Is it true that calling TRichViewEdit.Clear should completely free a

component

>so TComponent=nil?

>2) Is there any problem with creating multiple instances of a component

without

>calling Clear?

>3) Is there any way to destroy the component without calling Clear?

>4) What is the best way to test to see if a component exists? I thought

about

>SelectControl or FindControl but I really don't want the overhead of iterating

>through all the items in the document. There must be something simpler than

>the test I used, particularly because it appears to fail the second time

>around.

>

>Thanks.

>

>(I know that I have been asking a lot of questions, but that is a good thing

>-- I am doing so much more with this component that I could do with the

last

>word processing component I used!!)

>





Powered by ABC Amber Outlook Express Converter