Jump to content

Ian Branch

Members
  • Content Count

    284
  • Joined

  • Last visited

  • Days Won

    1

Ian Branch last won the day on August 8 2019

Ian Branch had the most liked content!

Community Reputation

37 Excellent

Technical Information

  • Delphi-Version
    Delphi 10.3 Rio

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Ian Branch

    Detect Windows shutdown?

    Hmmm. OK. I still have something amiss/NQR. On telling the PC to shutdown with the App running Windows immediately goes to the Shutting down screen. Reminder, I am on a Win 10 PC. This is my full code att.. unit Unit3; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs; type TForm3 = class(TForm) procedure FormShow(Sender: TObject); // private { Private declarations } procedure WMQueryEndSession(var Msg: TWMQueryEndSession); message WM_QueryEndSession; // detect Windows shutdown message procedure SaveData; // routine to save data to disk public { Public declarations } end; function ShutdownBlockReasonCreate(Handle: hWnd; Reason: LPCWSTR): Bool; stdcall; external user32; function ShutdownBlockReasonDestroy(Handle: hWnd): Bool; stdcall; external user32; var Form3: TForm3; DataToBeSaved: Boolean; implementation {$R *.dfm} procedure TForm3.WMQueryEndSession(var Msg: TWMQueryEndSession); begin if DataToBeSaved then begin Msg.Result := lResult(True); // disallow Windows from shutting down SaveData; end; Msg.Result := lResult(False); // allow Windows shutdown end; // Set DataToBeSaved to False after saving data procedure TForm3.FormShow(Sender: TObject); begin DataToBeSaved := True; end; procedure TForm3.SaveData; begin ShutdownBlockReasonCreate(Application.MainForm.Handle, 'please wait while muting...'); // Save data to disk files // ... beep; beep; beep; DataToBeSaved := False; // ShutdownBlockReasonDestroy(Application.MainForm.Handle); end; end. At least it builds now. πŸ˜‰
  2. Ian Branch

    Detect Windows shutdown?

    Ahhhh. Ha! Testing..
  3. Ian Branch

    Detect Windows shutdown?

    Yes I found it informative but I get a "E2169 Field definition not allowed after methods or properties" error pointing at the external user32; 😞 type TForm3 = class(TForm) procedure FormShow(Sender: TObject); procedure WMQueryEndSession(var Msg: TWMQueryEndSession); message WM_QueryEndSession; // detect Windows shutdown message procedure SaveData; // routine to save data to disk function ShutdownBlockReasonCreate(hWnd: HWND; Reason: LPCWSTR): Bool; stdcall; external user32; function ShutdownBlockReasonDestroy(hWnd: HWND): Bool; stdcall; external user32; The following is as I understand it att.. procedure TForm3.WMQueryEndSession(var Msg: TWMQueryEndSession); begin if DataToBeSaved then begin Msg.Result := lResult(True); // disallow Windows from shutting down SaveData; end; Msg.Result := lResult(False); // allow Windows shutdown end; // Set DataToBeSaved to False after saving data procedure TForm3.FormShow(Sender: TObject); begin DataToBeSaved := True; end; procedure TForm3.SaveData; begin ShutdownBlockReasonCreate(Application.MainForm.Handle, 'please wait while muting...'); // Save data to disk files // ... beep; beep; beep; DataToBeSaved := False; // ShutdownBlockReasonDestroy(Application.MainForm.Handle); end;
  4. Ian Branch

    Detect Windows shutdown?

    OK. I'll have another try. I have had a look at the article above and am trying to integrate the ShutdownBlockReason.... functions. Where are the declared/defined?
  5. Ian Branch

    Detect Windows shutdown?

    OK. Didn't see the "ShutdownBlockReasonCreate function" note. Had a look. It's cryptic to me and doesn't really give me any insight as to what is required. 😞 Guys, Let's forget about it. Thank you for your attempts to educate me. I apologise for my lack of knowledge/skill.
  6. Ian Branch

    Detect Windows shutdown?

    Hi Cristian, Clearly I don't understand the documentation. Hi David, IIUC the code had the 'True' & 'False' around the wrong way?? I also think the Msg.Result := 0; // disallow Windows from shutting down was in the wrong place and should have been before the ShowMessage, AND should have been.. Msg.Result := 1; // disallow Windows from shutting down I'm trying here guys but this is all new to me.
  7. Ian Branch

    Detect Windows shutdown?

    Hi Cristian, Yes I know. My issue/point is that I am NOT getting the message. Hence it would seem that the procedure isn't being called.
  8. Ian Branch

    Detect Windows shutdown?

    Hi Cristian, Thank you for your input. I don't want to stop it, just delay/pause it while the App writes to the log and closes the database gracefully. Hence the procedure TMainForm.SaveData; Then Windows can shut down. ATT the message display is purely to confirm that something is happening in the routine.
  9. Ian Branch

    Detect Windows shutdown?

    Hi Guys, Thanks to all for your input. I am out of my league here but this is what I have att from Dr Google. ;-). private { Private declarations } DataToBeSaved: Boolean; procedure WMQueryEndSession(var Msg: TWMQueryEndSession); message WM_QueryEndSession; // detect Windows shutdown message procedure SaveData; // routine to save data to disk Then.. procedure TMainForm.WMQueryEndSession(var Msg: TWMQueryEndSession); begin if DataToBeSaved then if MessageDlg('Windows is shutting down! First save data changes?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin Msg.Result := 0; // disallow Windows from shutting down beep; SaveData; end; Msg.Result := 1; // allow Windows shutdown end; // Set DataToBeSaved to False after saving data procedure TMainForm.SaveData; begin // Save data to disk files // ... DataToBeSaved := False; end; ..... ..... procedure TMainForm.FormCreate(Sender: TObject); begin // DataToBeSaved := True; // .... .... In my Win 10 dev PC, when I tell windows to shutdown it goes straight to the green Shutting Down screen. I never see the MessageDlg prompt. 😞 Am I missing some other nuance? I noted David's comments and reference. I need this to work on my Win 10 PC as well as the Customer's Win 7, later I hope to be Win 10, PCs. Again, thoughts, suggestions, code appreciated. Regards & TIA, Ian
  10. Ian Branch

    Detect Windows shutdown?

    Hi Team, D10.3.3. I want to detect Windows shutdown in Win 7 and Win 10 in order to ensure data is saved before the App gets clobbered. I have tried a few examples using.. { Private declarations } procedure WMQueryEndSession(var Msg: TWMQueryEndSession); message WM_QUERYENDSESSION; plus its associated routine, without success. I suspect the above may be OK in Win 7, haven't tried it yet, but not for Win 10. Anybody got code working as desired in Win 10? Regards & TIA, Ian
  11. Thank you for your continued commitment and support to make a great tool even better.
  12. Ian Branch

    Reinstall original Indy?

    Hi Remy, Thanks for the reply/info. I used the term 'generic' as it didn't have any '260' in the .bpl file names as opposed to the 'Indy10' I have installed from GitHub. I'm not going to play with the Registry. πŸ˜‰ Modifying the source for the 3rd party library will obviously be required each time there is an update. Not the most desirable thing to deal with. I shall consider my options further. Regards & Tks again, Ian.
  13. Ian Branch

    Reinstall original Indy?

    Hi Team, I have Indy10 installed with my D10.3.3. No problem. Works fine. When I installed Indy10 I removed the generic Indy libraries. Turns out that was a mistake. :-( For reasons of comparability another 3rd Party library I need to reinstall the generic Indy that came with D10.3.3. Whilst retaining Indy10. Can anybody advise where/how I might do that please? Regards & TIA, Ian
  14. Ian Branch

    Delphi Closedown Error

    Well done on your patience and persistence.
  15. Thaks Kas. I'll stick with it then. Ian
Γ—