Board index » delphi » Application.ProcessMessage from a called UNIT.

Application.ProcessMessage from a called UNIT.

Hi there,

In the main form, I'm calling a unit that processes a long loop. To
allow windows to process general messages, I need to call
Application.ProcessMessage method.
Since TApllication is only visible in the main form, how should I make
it visible to the called unit?

Thanks.

-Faruk.

 

Re:Application.ProcessMessage from a called UNIT.


In article <4eqcu5$...@news.puug.pt>,
   frem...@individual.puug.pt (Faruk Remane) wrote:
]-Hi there,
]-
]-In the main form, I'm calling a unit that processes a long loop. To
]-allow windows to process general messages, I need to call
]-Application.ProcessMessage method.
]-Since TApllication is only visible in the main form, how should I make
]-it visible to the called unit?
]-
]-Thanks.
]-
]--Faruk.
]-

This'll do the trick.  Use it in your unit in place of
Application.ProcessMessages.  The original source for
this comes from "Delphi Unleashed" by Charlie Calvert.
Good book...

procedure YieldToOthers;

  Var     Msg  :  TMsg;

  BEGIN   {==YieldToOthers==}
    while PeekMessage(Msg,0,0,0,PM_REMOVE) do
      BEGIN
        if (Msg.Message = WM_QUIT) then
          exit;
        TranslateMessage(Msg);
        DispatchMessage(Msg);
    END;
  END;    {==YieldToOthers==}

Mark Vaughan

Re:Application.ProcessMessage from a called UNIT.


Faruk Remane writes

Quote
> Hi there,

> In the main form, I'm calling a unit that processes a long loop. To
> allow windows to process general messages, I need to call
> Application.ProcessMessage method.
> Since TApllication is only visible in the main form, how should I make
> it visible to the called unit?

You can make the global 'Application' variable visible in ANY module by
including 'Forms' in your 'uses' statement. That's where it's defined.

--
Gregory H. Anderson        | "Honey, there're few programming
Gaffer/Best Boy/Key Grip   |  problems that can't be solved
Anderson Financial Systems |  with duct tape." -- 'Father' Duke
g...@afs.com (NeXTmail OK) |  (paraphrased), Doonesbury, 2/17/95

Re:Application.ProcessMessage from a called UNIT.


Quote
frem...@individual.puug.pt (Faruk Remane) wrote:
>Hi there,

>In the main form, I'm calling a unit that processes a long loop. To
>allow windows to process general messages, I need to call
>Application.ProcessMessage method.
>Since TApllication is only visible in the main form, how should I make
>it visible to the called unit?

        You can make it visible in the caled unit by adding it to the uses
clause. That gives a circular reference error, except it's _not_ an error
if unit2 is in the uses clause in the interface of unit1 while unit1 is
in the uses clause of the implementation section of unit2.

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...

Re:Application.ProcessMessage from a called UNIT.


Quote
m.a.vaug...@larc.nasa.gov (Mark Vaughan) wrote:
>In article <4eqcu5$...@news.puug.pt>,
>   frem...@individual.puug.pt (Faruk Remane) wrote:
>]-Hi there,
>]-
>]-In the main form, I'm calling a unit that processes a long loop. To
>]-allow windows to process general messages, I need to call
>]-Application.ProcessMessage method.
>]-Since TApllication is only visible in the main form, how should I make
>]-it visible to the called unit?
>]-
>]-Thanks.
>]-
>]--Faruk.
>]-
>This'll do the trick.  Use it in your unit in place of
>Application.ProcessMessages.  The original source for
>this comes from "Delphi Unleashed" by Charlie Calvert.
>Good book...
>procedure YieldToOthers;
>  Var     Msg  :  TMsg;
>  BEGIN   {==YieldToOthers==}
>    while PeekMessage(Msg,0,0,0,PM_REMOVE) do
>      BEGIN
>        if (Msg.Message = WM_QUIT) then
>          exit;
>        TranslateMessage(Msg);
>        DispatchMessage(Msg);
>    END;
>  END;    {==YieldToOthers==}
>Mark Vaughan

An even easier way is to put Forms in the uses clause of your unit
(implementation section).  Then your unit can access Application,
which is a global variable declared in Forms, just like any other part
of your program.

--
Tim Shea
CSI
c...@citysoft.com

Other Threads