Each session can only have one form with a particular name. Thus, you can't have 2 instances named 'IWForm1' in any session.
First thing you have to ask yourself is:
- Why do you need 2 instances of the same form in a session?
- Can't you just use the same instance over and over, instead of creating a new one? or...
- Can't you destroy the old instance before creating a new one?
- Why do you need to set a particular name to that form? (in general, the name of the form is irrelevant).
TIWApplication has several methods to help you to manage your forms:
Code:
function TIWApplication.FindFormByName(const AFormName: string): TComponent;
function TIWApplication.FindFormByClassName(const AFormClassName: string): TComponent;
You can use something like this:
Code:
function TIWForm1.GetOrCreateForm(AFormClass: TIWAppFormClass): TIWAppForm;
var
LForm: TComponent;
begin
LForm := WebApplication.FindFormByClassName(AFormClass.ClassName);
if not Assigned(LForm) then begin
LForm := AFormClass.Create(WebApplication);
end;
Result := LForm as TIWAppForm;
end;
I use a function like the one above to create my forms in my IW applications, and I use it like this:
Code:
procedure TIWForm2.Button1Click(Sender: TObject);
var
LForm: TIWAppForm;
begin
LForm := GetOrCreateForm(TIWForm1);
LForm.Show;
end;
As you can see, I just need the class of the form, I don't need to specify or deal with the name of the form instance. IW will do that for you automatically, unless you have a good reason to do so.
The function GetOrCreateForm() creates a new form of the class TIWForm1 if one doesn't exist. Otherwise it will return the existing instance.
When you don't need this instance anymore, all you need to do is call its Release() method.
So, let's say that
Code:
procedure TIWForm2.Button1Click(Sender: TObject);
var
LForm: TIWAppForm;
begin
Self.Release; // release current form TIWForm2
LForm := GetOrCreateForm(TIWForm1); // creates a new instance of TIWForm1 (or returns an existing instance)
LForm.Show; // makes this new instance the active form
end;
Also note that IWForm2.Release can be safely called before creating a new form of class TIWForm1 (and making it the active form). Release just marks the form for destruction, it doesn't destroy it immediately.