Board index » delphi » Problem with ShowModal method

Problem with ShowModal method

Please reply anybody,

in my application when I try to show one of my forms
modally i.e. say  Form1.ShowModal,  DELPHI produces a message
'Cannot make a visible window modal'. I have number of other
forms which I have to display modally and they work OK
but not this one. I could not find any obvious reason and Borland
documentation is not particularly helpful. If anyone knows how
to deal with it PLEASE reply as soon as you can.

Janette.

--
Mayes uk

 

Re:Problem with ShowModal method


Quote
Mayes uk <Ma...@d-m-g.demon.co.uk> wrote:
>Please reply anybody,

>in my application when I try to show one of my forms
>modally i.e. say  Form1.ShowModal,  DELPHI produces a message
>'Cannot make a visible window modal'. I have number of other
>forms which I have to display modally and they work OK
>but not this one. I could not find any obvious reason and Borland
>documentation is not particularly helpful. If anyone knows how
>to deal with it PLEASE reply as soon as you can.

Are all of your forms being created by the main application (ie.
Application.CreateForm(TForm, Form1) in your project file)?  If so, then
the app is already showing the form, and so your Form1.ShowModal wouldn't
work. One solution would be to set Form1's Visible property to False,
then call the ShowModal event.

Marc

Re:Problem with ShowModal method


In article <44eupn$...@news.halcyon.com>
           mchap...@mstarlabs.com "Marc Chapman" writes:

Quote
> Mayes uk <Ma...@d-m-g.demon.co.uk> wrote:
> >Please reply anybody,

> >in my application when I try to show one of my forms
> >modally i.e. say  Form1.ShowModal,  DELPHI produces a message
> >'Cannot make a visible window modal'. I have number of other
> >forms which I have to display modally and they work OK
> >but not this one. I could not find any obvious reason and Borland
> >documentation is not particularly helpful. If anyone knows how
> >to deal with it PLEASE reply as soon as you can.

> Are all of your forms being created by the main application (ie.
> Application.CreateForm(TForm, Form1) in your project file)?  If so, then
> the app is already showing the form, and so your Form1.ShowModal wouldn't
> work. One solution would be to set Form1's Visible property to False,
> then call the ShowModal event.

> Marc

Dear Marc,

thank you for a quick responce to my message. Yes, my Form1 is created
by the main application but so are my other modal forms which I have
no problem with. The first thing I tried was to set Visible property
to FALSE but it did't work. If you (or anyone who reads this article)
can think of any other reason which could possibly cause this problem
please reply.

Janette.
--
Mayes uk

Re:Problem with ShowModal method


I'm writing an app that will use plug-in DLL's with common functions.
This will necessitate calling functions using GetProcAddress.  Could
someone shed some light on doing this?

I'm calling LoadLibrary to get the handle to the DLL, and I can call
GetProcAddress to get the address of the function, but now that I have
this address, what do I do?

Any help would be appreciated.

Re:Problem with ShowModal method


Can you pass a TCanvas object to a DLL for drawing?  For example, I have
the following code in a DLL:

procedure DoSomething(PassedCanvas:tcanvas);export;
begin
        tcanvas(PassedCanvas).fillrect(rect(0,0,32,32));
end;

When I call this up in my app, I get a GPF.  I've tried re-writing the
procedure to accept a device context, but then the rectangle is drawn on
whatever had the focus last, including the desktop, a button, or even the
Delphi IDE.

Anyone had any luck doing this?

Re:Problem with ShowModal method


Quote
za...@aol.com (ZaneR) wrote:
>Can you pass a TCanvas object to a DLL for drawing?  For example, I have
>the following code in a DLL:

>procedure DoSomething(PassedCanvas:tcanvas);export;
>begin
>        tcanvas(PassedCanvas).fillrect(rect(0,0,32,32));
>end;

>When I call this up in my app, I get a GPF.  I've tried re-writing the
>procedure to accept a device context, but then the rectangle is drawn on
>whatever had the focus last, including the desktop, a button, or even the
>Delphi IDE.

>Anyone had any luck doing this?

some points:

1) A TCanvas is just a wrapper around an HDC.many times, trying to use
a canvas outside the delphi ide will fail because the canvas hdc is
invalid. sounds like you're getting this type of problem.
2) I've had good success by either:

a) forcing the canvas to get an hdc with a call to RequiredState
b) getting my own hdc with GetDC and setting the handle property of
the canvas to it.

hope this helps. email me if you still have problems; this is an
area i want to work on myself soon.

--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/  Green Meddler  kilga...@tde.com   Nathan F. Wallace _/
_/     http://www.webcom.com/~kilgalen/welcome.html     _/
_/     http://www.webcom.com/~kilgalen/nerelon.html     _/
_/    C.I.U.P.K.C. Software -- Unleashing the Power!    _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Re:Problem with ShowModal method


On 1 Oct 1995 15:02:22 -0400, za...@aol.com (ZaneR) wrote:

Quote
>Can you pass a TCanvas object to a DLL for drawing?  For example, I have
>the following code in a DLL:

>procedure DoSomething(PassedCanvas:tcanvas);export;
>begin
>        tcanvas(PassedCanvas).fillrect(rect(0,0,32,32));
>end;

>When I call this up in my app, I get a GPF.  I've tried re-writing the
>procedure to accept a device context, but then the rectangle is drawn on
>whatever had the focus last, including the desktop, a button, or even the
>Delphi IDE.

I don't recommend it. As a general rule, you cannot pass Delphi
graphics objects between an application and a DLL. The Graphics unit
maintains information that is kept in a module's data segment (such as
a list of TCanvas objects). Using graphical objects in different
modules confuses Delphi when it tried to maintain these private lists.

Instead, you can pass a canvas Handle, and create a new TCanvas object
in the DLL. When you do this, you might need to spend a little extra
work recreating the proper state of the TCanvas object in the DLL. The
details depend on how you are using it.

If you tried this without success, what, exactly, did you try?  How
did you obtain the DC handle, and how did you use it in the DLL?
--
Ray Lischner         (li...@tempest-sw.com)
Tempest Software, Corvallis, Oregon, USA

Re:Problem with ShowModal method


Quote
In article <44moju$...@newsbf02.news.aol.com>, za...@aol.com (ZaneR) writes:
>Can you pass a TCanvas object to a DLL for drawing?  For example, I have
>the following code in a DLL:

>procedure DoSomething(PassedCanvas:tcanvas);export;
>begin
>        tcanvas(PassedCanvas).fillrect(rect(0,0,32,32));
>end;

>When I call this up in my app, I get a GPF.  I've tried re-writing the
>procedure to accept a device context, but then the rectangle is drawn on
>whatever had the focus last, including the desktop, a button, or even the
>Delphi IDE.

All this makes me suspicious that you're not setting things up for the
call properly.  Are you ".Create"-ing the TCanvas before passing it to
to DoSomething()?  When using the HDC approach, are you allocating a new
DC for your application before passing it?

Quote
>Anyone had any luck doing this?

Regards,

-* Stephen *-
Stephen Posey
University of New Orleans
Email  : S...@uno.edu
WWW    : http://www.uno.edu/~slp

Other Threads