Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-02

creating multiple non-modal form instances

10 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

I have a listing screen (grid based) that allows various views and filters - selected by the user. I want the user to be able to open multiple instances of that listing screen. Each with there own views and filters.

How do I create such multiple instances?
Do I keep calling something like the following:

   Application.CreateForm(TLearnerListForm, frmBrLearners);

frmBrLearners being a global variable of TLearnerListForm. Though I hate global variable!

How do I track such instances? By tracking I mean something like a MDI interface's 'Windows' menu item?
My application is a SDI style app. If the user has many forms open, I want them to somehow be able to bring a certain form to the front. Or should I not bother and they simply use the taskbar for that. Then again, what if the app is run under Linux and the window manager doesn't have a taskbar?

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 13 lines
Hi, I have a listing screen (grid based) that allows various views and filters - selected by the user. I want the user to be able to open multiple instances of that listing screen. Each with there own views and filters. How do I create such multiple instances? Do I keep calling something like the following: Application.CreateForm(TLearnerListForm, frmBrLearners); frmBrLearners being a global variable of TLearnerListForm. Though I hate global variable!

Just do a

  With TLearnerListForm.Create(Application) do
    begin
    Initialize;
    Show;
    end;

You can keep track of them with the Screen.Forms property:

For I:=0 to Screen.FormCount-1 do
  If Screen.Forms[i] is TLearnerListForm then

and that's it.
Well, at least in Delphi, but I assume lazarus can do the same.

Michael.

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys: I have a listing screen (grid based) that allows various views and filters - selected by…
Graeme Geldenhuys wrote
How do I create such multiple instances?

The following seems to work.... Anybody see any issues with this?

========================
procedure DisplayLearners;
var
  frm: TLearnerListForm;
begin
  frm := TLearnerListForm.Create(Application);
  { very basic unique name and should probably be improved}
  frm.Name := frm.Name + IntToStr(Screen.FormCount + 1);
  frm.Show;
end;
========================

Also, TLearnerListForm's CloseAction is set to caFree in the OnClose event handler.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 15 lines
On Tue, Feb 3, 2009 at 11:16 AM, Graeme Geldenhuys wrote: > > How do I create such multiple instances? The following seems to work.... Anybody see any issues with this? ======================== procedure DisplayLearners; var frm: TLearnerListForm; begin frm := TLearnerListForm.Create(Application); { very basic unique name and should probably be improved} frm.Name := frm.Name + IntToStr(Screen.FormCount + 1);
That will break if you have for example 5 forms, close form 4 and then
create a new form.

Michael.

Show quoted text 21 lines
frm.Show; end; ======================== Also, TLearnerListForm's CloseAction is set to caFree in the OnClose event handler. Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: Just do a With TLearnerListForm.Create(Application) do begin Initialize; Show; end; You…
Michael Van Canneyt wrote 8 lines
Just do a With TLearnerListForm.Create(Application) do begin Initialize; Show; end;

Where is "Initialize" defined? I only found "InitializeWnd", or did you mean Initialize is a custom method I wrote myself?

You can keep track of them with the Screen.Forms property: For I:=0 to Screen.FormCount-1 do If Screen.Forms[i] is TLearnerListForm then

Thank you very much! It's amazing how if you are used to mostly designing modal forms, then switching to non-modal takes some extra thinking. ;-)

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: That will break if you have for example 5 forms, close form 4 and then create a new form.…
Michael Van Canneyt wrote 5 lines
> { very basic unique name and should probably be improved} > frm.Name := frm.Name + IntToStr(Screen.FormCount + 1); That will break if you have for example 5 forms, close form 4 and then create a new form.

Yup, I noticed that right after I posted the message. :-)

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: On Tue, Feb 3, 2009 at 11:20 AM, Michael Van Canneyt Where is "Initialize" defined? I…
Graeme Geldenhuys wrote 13 lines
On Tue, Feb 3, 2009 at 11:20 AM, Michael Van Canneyt wrote: > > Just do a > > With TLearnerListForm.Create(Application) do > begin > Initialize; > Show; > end; Where is "Initialize" defined? I only found "InitializeWnd", or did you mean Initialize is a custom method I wrote myself?

The latter, yes :-)

Michael.

Reply by email

Malcolm Poole
to Graeme Geldenhuys: I have a listing screen (grid based) that allows various views and filters - selected by…
Graeme Geldenhuys wrote 9 lines
How do I track such instances? By tracking I mean something like a MDI interface's 'Windows' menu item? My application is a SDI style app. If the user has many forms open, I want them to somehow be able to bring a certain form to the front. Or should I not bother and they simply use the taskbar for that. Then again, what if the app is run under Linux and the window manager doesn't have a taskbar?

My first commissioned app worked like that - you could open any number of reports which used the same forms and could be accessed by a dynamically created menu on the main form. If I remember correctly I had a TList to which each form was added as it was created and when the report forms closed they called a procedure of the main form which removed them from the TList.

Regards,
Malcolm

Reply by email

Darmawan Sugiarto
How about time. You can used time as form name
frm.Name := frm.Name + DateTimeToStr(Now);

=============INTOSOFT============

ALEXIO CHAOS

Yahoo Messager

=================================

--- On Tue, 2/3/09, Graeme Geldenhuys wrote:

Earlier message 23 lines
From: Graeme Geldenhuys Subject: Re: [Lazarus] creating multiple non-modal form instances To: "General mailing list" Date: Tuesday, February 3, 2009, 1:45 AM On Tue, Feb 3, 2009 at 11:33 AM, Michael Van Canneyt wrote: >>???{ very basic unique name and should probably be improved} >>???frm.Name := frm.Name + IntToStr(Screen.FormCount + 1); > > That will break if you have for example 5 forms, close form 4 and then > create a new form. Yup, I noticed that right after I posted the message. :-) Regards, ? - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Darmawan Sugiarto

Just Share my app. I used Link List to do this

procedure close_list_form(formclass:TFormClass);
var
?? _i:integer;
?? _temp:Plistform;
begin
? for _i:=0 to mainform.TB.ButtonCount-1 do mainform.TB.Buttons[0].Destroy;
? _curr:=_head;
? while (_currnil) do
? begin
??? if _curr^.form^.ClassName=formclass.ClassName then
??? begin
????? if _curr^.backnil then
??????? _curr^.back^.next:=_curr^.next;
????? if _curr^.nextnil then
??????? _curr^.next^.back:=_curr^.back;
????? if _curr=_head then _head:=_curr^.next;
????? if _curr=_tail then _tail:=_curr^.back;
????? dispose(_curr);
??? end
??? else
????? mainform.add_menu_btn(_curr^.form^.Caption);
??? _curr:=_curr^.next;
? end;
end;
procedure find_list_form(formclass:TFormClass);
var
?? _find:boolean;
begin
? _curr:=_head;
? _find:=false;
? while (_currnil)and(not _find) do
? begin
??? if _curr^.form^.ClassName=formclass.ClassName then _find:=true
??? else _curr:=_curr^.next;
? end;
end;
function new_list_form(formclass:TFormClass;_par:integer = 0):boolean;
var
?? _flag:boolean;
?? _i:integer;
begin
? _flag:=true;
? find_list_form(formclass);
? if _curr=nil then
? begin
??? try
????? _curr:=new(Plistform);
????? _curr^.back:=nil;
????? _curr^.next:=nil;
????? _curr^.form:=new(Pform);
????? _curr^.form^:=formclass.Create(mainform);
????? mainform.add_menu_btn(_curr^.form^.Caption);
????? if _head=nil then
????? begin
??????? _head:=_curr;
??????? _tail:=_curr;
????? end
????? else
????? begin
??????? _tail^.next:=_curr;
??????? _curr^.back:=_tail;
??????? _tail:=_curr;
????? end;
??? except
??? on Exception do _flag:=false;
??? end;
? end;
? if _currnil then
? begin
??? _curr^.form^.Tag:=_par;
??? _curr^.form^.Show;
? end;
? Result:=_flag;
end;?

Do you find any problem ? Thanks

=============INTOSOFT============

ALEXIO CHAOS

Yahoo Messager

=================================

--- On Tue, 2/3/09, Malcolm Poole wrote:

Earlier message 24 lines
From: Malcolm Poole Subject: Re: [Lazarus] creating multiple non-modal form instances To: "General mailing list" Date: Tuesday, February 3, 2009, 11:52 AM Graeme Geldenhuys wrote: > How do I track such instances? By tracking I mean something like a MDI > interface's 'Windows' menu item? > My application is a SDI style app. If the user has many forms open, I > want them to somehow be able to bring a certain form to the front. Or > should I not bother and they simply use the taskbar for that.? Then > again, what if the app is run under Linux and the window manager > doesn't have a taskbar? > >??? My first commissioned app worked like that - you could open any number of reports which used the same forms and could be accessed by a dynamically created menu on the main form. If I remember correctly I had a TList to which each form was added as it was created and when the report forms closed they called a procedure of the main form which removed them from the TList. Regards, Malcolm

Reply by email