Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SDI ShowModal howto?

38 views
Skip to first unread message

Olrik Larsen

unread,
Jan 15, 1999, 3:00:00 AM1/15/99
to
Hello Delphians!

Does anyone know how to show a modal form without disabling other
children in an SDI application?
What I mean is that if I have a FrmMain, Frm1 & Frm2 and shows a modal
window from within Frm1 I would be glad if one could access both
FrmMain and Frm2 without first closing the newly created modal form
(frmMain is the owner off both Frm1 and Frm2).

Thanks
Olrik Larsen
Ol...@MercuryGroup.dk
www.MercuryGroup.dk

Alan Gauld

unread,
Jan 15, 1999, 3:00:00 AM1/15/99
to
Olrik Larsen wrote:
> What I mean is that if I have a FrmMain, Frm1 & Frm2 and shows a modal
> window from within Frm1 I would be glad if one could access both
> FrmMain and Frm2 without first closing the newly created modal form
> (frmMain is the owner off both Frm1 and Frm2).

I think you can dynamically create an instance of frm1 with
no parent and then showModal. This will not affect frmMain.

Caveat: I haven't actually tried this!

Alan G.

Question?

unread,
Jan 15, 1999, 3:00:00 AM1/15/99
to
Olrik

If I understand what you asking:

1. As for I know, you cannot active and use another form while you are in a
showmodal form ie frmForm2; frmMain would be in the background waiting for
release of frmForm2. Use the Show method.
2. However to the above statement, you can access variables, objects and
classes (as long as those forms are in auto-create status). You can access
those variables, objects, classes via the uses clause. While in frmForm2
you can access those items with the following syntax:
{ accessing items going backwards }
with frmForm2 do begin
frmMain.dbeditFirstName.Text := ?? { assigning a component }
^form
^component or variable or method
^
assignment
frmMain.dbCustomer.FieldByName('FIRSTNAME').AsString := ??
frmMain.SetupPrinters; { activating methods }
frmMain.sLastName := editLastName.Text; { assigning variables }
{ do whatever next }
end;
3. If you are dynamically creating your forms, it creates a problems. You
have to assign your variables, objects, classes, etc. before you show your
new form. For example, you are in your main form, you have to send data to
frmForm2 instead of getting info from frmMain. (that been a problem for me,
if anyone as a different way please respond). Here's a example:
{ populating a new form dynamically }
with frmMain do begin
{ use with no auto-create }
frmForm2 := TfrmForm2.Create(Application);
try
frmForm2.sLastName := "DOE" { assigning variables }
frmForm2.dbCustomer.DataSource := ?? { assigning components }
frmForm2.dbeditFirstName.Text := ??
frmForm2.InitVars; { activating methods }
{ you get the picture }
frmForm2.ShowModal;
finally
frmForm2.Free;
end;
end;
This should work!
Hope this helps! If I missed anything or if anything I said is wrong,
please respond!
Maurice

Olrik Larsen wrote in message <369f57ec...@forums.inprise.com>...


>Hello Delphians!
>
>Does anyone know how to show a modal form without disabling other
>children in an SDI application?

>What I mean is that if I have a FrmMain, Frm1 & Frm2 and shows a modal
>window from within Frm1 I would be glad if one could access both
>FrmMain and Frm2 without first closing the newly created modal form
>(frmMain is the owner off both Frm1 and Frm2).
>

Olrik Larsen

unread,
Jan 15, 1999, 3:00:00 AM1/15/99
to
On Fri, 15 Jan 1999 16:11:16 +0000, Alan Gauld
<alan....@gssec.bt.co.uk> wrote:

>Olrik Larsen wrote:
>> What I mean is that if I have a FrmMain, Frm1 & Frm2 and shows a modal
>> window from within Frm1 I would be glad if one could access both
>> FrmMain and Frm2 without first closing the newly created modal form
>> (frmMain is the owner off both Frm1 and Frm2).
>

>I think you can dynamically create an instance of frm1 with
>no parent and then showModal. This will not affect frmMain.
>

Nope! No can do!

All options tested:

Frm1 | ModalFrm
------------------------------
Nil | Nil
Nil | Self
Self | Nil
Self | Self

None of them is possible!

Peter Below (TeamB)

unread,
Jan 15, 1999, 3:00:00 AM1/15/99
to
> Does anyone know how to show a modal form without disabling other
> children in an SDI application?
> What I mean is that if I have a FrmMain, Frm1 & Frm2 and shows a modal
> window from within Frm1 I would be glad if one could access both
> FrmMain and Frm2 without first closing the newly created modal form
> (frmMain is the owner off both Frm1 and Frm2).
>
Olrik,

a modal form is always application-modal, there is no such thing as a
"form-modal" form build into the VCL. But you can fake it. In the
following example TForm3 is the form-modal form. It should not be
autocreated (as true for all modal forms). Form1 has a button that
creates the form and shows it form-modally:

procedure TForm1.Button1Click(Sender: TObject);
begin
with tform3.Create(Application) do
try
if ShowFormmodal(self) = mrOK then
showmessage('Closed OK')
else
showmessage('Closed by cancel');
finally
free
end;
end;

As you see the construct is the same as usually used to show a modal
form, but instead of ShowModal a custom method of TForm3 is called:
ShowFormmodal. The implementation of TForm3 is this (i deleted the form
variable, a Good Thing to do for non-autocreated forms):

unit Unit3;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls;

type
TForm3 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure wmSyscommand( var msg: TWMSyscommand );
message WM_SYSCOMMAND;
public
{ Public declarations }
Function ShowFormModal( ModalParent: TForm ): Integer;
Procedure Close; // hides TCustomForm.Close
end;

var
Form3: TForm3;

implementation

{$R *.DFM}

{ TForm3 }

function TForm3.ShowFormmodal( ModalParent: TForm ): Integer;
begin
{ Show self and disable the modalparent }
Show;
ModalParent.Enabled := False;

{ Enter a message loop modelled after TCustomForm.ShowModal. Loop
exits if the forms ModalResult changes from mrNone or the
Application is terminated. }
repeat
Application.HandleMessage;
if Application.Terminated Then
ModalResult := mrCancel;
until ModalResult <> mrNone;

{ Return the forms ModalResult, enable the parent and close self.
This hides the form, it is not destroyed. That needs to be done
by the caller, who created it in the first place. }
Result := ModalResult;
ModalParent.Enabled := True;
Close;

{ Make sure the caller form becomes active }
ModalParent.BringToFront;
end;

procedure TForm3.Button1Click(Sender: TObject);
begin
ModalResult := mrOK;
end;

procedure TForm3.wmSyscommand(var msg: TWMSyscommand);
begin
{ Trap attempts to close the form via close box or system menu
or Alt-F4, treat that as cancel. }
if (msg.CmdType and $FFF0) = SC_CLOSE then
ModalResult := mrCancel
else
inherited;
end;

procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
{ Make sure form stays in existence after ShowFormmodal returns
to caller.}
Action := caHide;
end;

procedure TForm3.Close;
begin
If ModalResult = mrNone then
ModalResult := mrCancel;
inherited Close;
end;

procedure TForm3.Button2Click(Sender: TObject);
begin
Close;
end;

end.

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitely requested!


Olrik Larsen

unread,
Jan 17, 1999, 3:00:00 AM1/17/99
to
Hello Maurice!

Thanks for your reply but, the question was to have a SDI interface
where the main form shows a form and having that form showing a modal
form but without interfering with any other forms owned by the main
SDI form. (look at Peter Below's answer)!

Thanks
Olrik Larsen
Ol...@MercuryGroup.dk
www.MercuryGroup.dk

On Fri, 15 Jan 1999 11:20:19 -0500, "Question?" <ray.m...@epa.gov>
wrote:

>>Does anyone know how to show a modal form without disabling other
>>children in an SDI application?
>>What I mean is that if I have a FrmMain, Frm1 & Frm2 and shows a modal
>>window from within Frm1 I would be glad if one could access both
>>FrmMain and Frm2 without first closing the newly created modal form
>>(frmMain is the owner off both Frm1 and Frm2).
>>

Olrik Larsen

unread,
Jan 17, 1999, 3:00:00 AM1/17/99
to
Hello Peter!

Thanks Peter! That was a very nice answer, thanks a lot!
I will look into it moday or tuesday and probably put it in my
repository. :->>

Thanks
Olrik Larsen
Ol...@MercuryGroup.dk
www.MercuryGroup.dk

On Fri, 15 Jan 1999 23:19:54 +0100, "Peter Below (TeamB)"
<10011...@compuXXserve.com> wrote:

>> Does anyone know how to show a modal form without disabling other
>> children in an SDI application?
>> What I mean is that if I have a FrmMain, Frm1 & Frm2 and shows a modal
>> window from within Frm1 I would be glad if one could access both
>> FrmMain and Frm2 without first closing the newly created modal form
>> (frmMain is the owner off both Frm1 and Frm2).
>>

Olrik Larsen

unread,
Jan 18, 1999, 3:00:00 AM1/18/99
to
Hello Peter !

Thanks again! that worked just fine!

I added a boolean value that tells wether its a modal or formmodal
form, so it's possible to show the form as a standard modal form.

Thanks
Olrik Larsen
Ol...@MercuryGroup.dk
www.MercuryGroup.dk

Olrik Larsen

unread,
Jan 18, 1999, 3:00:00 AM1/18/99
to
0 new messages