Board index » delphi » Novice in Need-freeing a form from another form's OnShow event

Novice in Need-freeing a form from another form's OnShow event

If anyone could help I would be eternally grateful.
I have an application with 16 forms full of labels editboxes buttons
etc. and run out of stack memory before the 10th form is created - so
I set the project not to autocreate the forms and each one creates its
successor. but after calling say form 3 I would like to free the
memory used by form 2. It seemed the best way to do this is in the
onShow or onActivate event of Form3. I tried both Form2.free and
Form2.destroy but end up with either a gpf or form 3 disapears.

Also, How do I determine whether or not an object exists is there some
kind of ifExist method that I can use? Some of the forms that I am
using I hide and some I try to free but then I don't know what exists
and what doesn't.

Lastly, I would like to create a procedure that uses objects that have
incremented names like label1, label2, label3, etc.
as in
writestring(section1, label1.caption,'0');
writeString(section1,label2.caption,'0');
writeString(section1,label3.caption,'0'); etc
I tried creating a string variable and then incrementing it like
labelvar : string;

labelvar := 'label' + i + '.caption'
where i holds a number that can be incremented
and then rewriting the statement to WriteString(section1,labelvar,'0')
but (naturally) i don't get the caption property of the label object i
just get a string. Any Ideas??? Please??? Pretty Please???

 

Re:Novice in Need-freeing a form from another form's OnShow event


Quote
Kurt Batsche wrote in message <345fe747.11589...@news.futureone.com>...
>If anyone could help I would be eternally grateful.
>I have an application with 16 forms full of labels editboxes buttons
>etc. and run out of stack memory before the 10th form is created - so
>I set the project not to autocreate the forms and each one creates its
>successor. but after calling say form 3 I would like to free the
>memory used by form 2. It seemed the best way to do this is in the
>onShow or onActivate event of Form3. I tried both Form2.free and
>Form2.destroy but end up with either a gpf or form 3 disapears.

You must control this programmatically.  One way to do it is have one
"Parent" form with as many "Children" as you want.  That way, the parent can
track who is alive and who is dead.

Quote
>Also, How do I determine whether or not an object exists is there some
>kind of ifExist method that I can use? Some of the forms that I am
>using I hide and some I try to free but then I don't know what exists
>and what doesn't.

The function you want is Assigned(var), like:
if Assigned(theForm) then...
It checks for memory assignment, as the name suggests.

Quote
>Lastly, I would like to create a procedure that uses objects that have
>incremented names like label1, label2, label3, etc.
>as in
>writestring(section1, label1.caption,'0');
>writeString(section1,label2.caption,'0');
>writeString(section1,label3.caption,'0'); etc
>I tried creating a string variable and then incrementing it like
>labelvar : string;

>labelvar := 'label' + i + '.caption'
>where i holds a number that can be incremented
>and then rewriting the statement to WriteString(section1,labelvar,'0')
>but (naturally) i don't get the caption property of the label object i
>just get a string. Any Ideas??? Please??? Pretty Please???

Just set up an array of TLabel to as big as you are going to want-- that
should do the trick.

Re:Novice in Need-freeing a form from another form's OnShow event


On Wed, 05 Nov 1997 03:41:00 GMT, kbat...@futureone.com (Kurt Batsche)
wrote:

Quote
>I set the project not to autocreate the forms and each one creates its
>successor. but after calling say form 3 I would like to free the
>memory used by form 2.

Does form n-1 need to exist in order for form n to be created?  If not
then consider a tab set that could destroy form n-1 and create form n
in the 'on change' event.

[snip]

Quote
>labelvar := 'label' + i + '.caption'
>where i holds a number that can be incremented
>and then rewriting the statement to WriteString(section1,labelvar,'0')
>but (naturally) i don't get the caption property of the label object i
>just get a string. Any Ideas??? Please??? Pretty Please???

I think if you have a label on your form, you have a 'tag' property in
that label (check your object inspector).  Stick your integer in
there.  I am guessing what you are trying to do.

***Attention spammers!***
Use of this e-mail address for unsolicited messages implies
your acceptance of a $1000 fee charged to you. I do not want
nor respond favorably to 'spam'.

Re:Novice in Need-freeing a form from another form's OnShow event


.. creating each form in a succession

I think the problems will disappear if you use one main form for organizing
all other forms.

... how to know if an object exist?

You may use an advanced solution, or you just may assign nil to the objects
as you free them.

... labelvar: String;
    ...
    labelvar := 'Label1.caption';

I guess you are trying to catch Label1.Caption. First retrieve the pointer
to Label1. If you don't know how many Label controls there are, search for
all controls that is TLabels (if Control[ i] is TLabel ...), and test
TLabel( Control[ i]).Name ( if I have not misunderstood your problem).

Kjell / Norway

Other Threads