Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2011, 04:23 PM
jerbear jerbear is offline
Junior Member
 
Join Date: Jun 2009
Location: Ireland
Posts: 17
Send a message via Skype™ to jerbear
Default Cannot make a visible window modal

Hi Guys.
I know this was covered elswhere but the answers where of no help to me.

My app has a timer component and checks every so often the system time. If it passes 8pm then it displays a warning giving users 15 mins to hit the abort button otherwise mrOk is activated and the system closes down.

However after the warning windows is Displayed Modally i get the "Cannot Make A Visible Window Modal". Can't understand why I'm getting this.

The calling procedure to display the window is
Code:
TimedDlg.Execute('WARNING - SYSTEM SHUTDOWN !! ','My Warning Message here'); //Display a warning
The code for this TimedDlg I got of another Delphi website and it is as follows...

Code:
unit TimedDlgU;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, RzPopups, RzPanel, RzStatus;
type
  TTimedDlg = class(TForm)
    timerWarning: TTimer;
    btnOK: TBitBtn;
    WarningMsg: TMemo;
    btnAbort: TBitBtn;
    RzStatusBar1: TRzStatusBar;
    procedure timerWarningTimer(Sender: TObject);
    procedure btnAbortClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure Execute(Title, Contents: string); // added by you
  end;
var
  TimedDlg: TTimedDlg;
implementation
uses main;
{$R *.dfm}
Function WindowsExit(RebootParam: Longword): Boolean;
var
   TTokenHd: THandle;
   TTokenPvg: TTokenPrivileges;
   cbtpPrevious: DWORD;
   rTTokenPvg: TTokenPrivileges;
   pcbtpPreviousRequired: DWORD;
   tpResult: Boolean;
const
   SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
begin
   if Win32Platform = VER_PLATFORM_WIN32_NT then begin
     (*
     The ExitWindowsEx function fails if the calling process does not have
     the SE_SHUTDOWN_NAME privilege. This privilege is disabled by default.
     Use the AdjustTokenPrivileges function to enable this privilege.
     *)
     tpResult := OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, TTokenHd) ;
     if tpResult then
       begin
        tpResult := LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME, TTokenPvg.Privileges[0].Luid) ;
        TTokenPvg.PrivilegeCount := 1;
        TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
        cbtpPrevious := SizeOf(rTTokenPvg) ;
        pcbtpPreviousRequired := 0;
        if tpResult then
          Windows.AdjustTokenPrivileges(TTokenHd, False, TTokenPvg, cbtpPrevious, rTTokenPvg, pcbtpPreviousRequired) ;
       end;
   end;
   Result := ExitWindowsEx(RebootParam, 0) ;
end;
procedure TTimedDlg.btnAbortClick(Sender: TObject);
begin
  timerWarning.Enabled := False;
  ToggleOnOff := False;
end;
procedure TTimedDlg.Execute(Title, Contents: string);
begin
  Caption := '!! WARNING - SYSTEM SHUTDOWN !!'; // set the caption of the form
  if contents <> '' then
     WarningMsg.Text := Contents; // set the text of the memo
  timerWarning.Enabled := True; // start the timer
  ShowModal;
end;
procedure TTimedDlg.timerWarningTimer(Sender: TObject);
begin
  timerWarning.Enabled := False; // stop the timer
  ModalResult := mrOK;     // close the form
end;
end.
Can anyone help here......

Regards

Jerry
Reply With Quote
  #2  
Old 06-07-2011, 04:41 PM
jerbear jerbear is offline
Junior Member
 
Join Date: Jun 2009
Location: Ireland
Posts: 17
Send a message via Skype™ to jerbear
Angry

Stupid! Stupid! Stupid!.

I just found my problem.

I forgot to cancel the main timer which was causing the warning window to be repeated....

Damn, If only I could kick myself!!!

Sorry guys.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 09:02 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.