Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

safe way to create mulitple instances of form

Hello all,

what's the safe way to dynamically create multiple instances of a form? I need for the user to create and close as many instances as desired, like opening several email editors in outlook.

Here's what I've tried:

I declare a dynamic array "aforms" of tform to use as a stack.

Each instance is created like this:

iNewFrm := get_new_or_unused_array_element()

aforms[inewfrm] := tmyform.create(nil);
aforms[inewfrm].show;


in my get_new_or_unused_array_element() function I scan for unused elements
for i := 0 to length(aforms)-1 do
if aforms[i] = nil then {return that element to recycle, otherwise increment array with setlength}

the problem with this is that previously used array elements never get set back to nil after the forms closed ... i use ca := free in the onclose handler.

any ideas?

thx,

kim

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hello all,
    :
    : what's the safe way to dynamically create multiple instances of a
    : form? I need for the user to create and close as many instances as
    : desired, like opening several email editors in outlook.
    :
    : Here's what I've tried:
    :
    : I declare a dynamic array "aforms" of tform to use as a stack.
    :
    : Each instance is created like this:
    :
    : iNewFrm := get_new_or_unused_array_element()
    :
    : aforms[inewfrm] := tmyform.create(nil);
    : aforms[inewfrm].show;
    :
    :
    : in my get_new_or_unused_array_element() function I scan for unused
    : elements
    : for i := 0 to length(aforms)-1 do
    : if aforms[i] = nil then {return that element to recycle, otherwise
    : increment array with setlength}
    :
    : the problem with this is that previously used array elements never
    : get set back to nil after the forms closed ... i use ca := free in
    : the onclose handler.
    :
    : any ideas?
    :
    : thx,
    :
    : kim
    :
    I would use a TList to hold all the forms. You should also use the Application variable as the form's parent. That way the forms will not appear as new processes in the taskbar.
    An alternative is to make your application into an MDI application. That way you can let windows handle the document forms.
Sign In or Register to comment.