Alert when closing app

Had to update an older app compiled with 1.7. Had setup to alert user when they closed app and had used this in 1.7 scripting:

function OnWindowCloseQuery (WindowName: String): Boolean;
begin
 // Ask user if they really wish to close window
 Result := True;                       
 if MessageBox("Exit Software?"#13#10#13#10"Did You Save Your Work? Click Yes if So!"#13#10#13#10"Choose No to Cancel & Then Save...", 
 "Exit Confirmation", MB_YESNO+MB_ICONWARNING) = IDNO then Result := False;   
end; 

This is what I used in 2.1. Issue having is clicking “No” button also closes the app:

procedure OnCloseWindow(WindowName: String);
begin
 // When a window is closed by the user.
  // Ask user if they really wish to close window
 Result := True;                       
 if MessageBox("Exit Software?"#13#10#13#10"Did You Save Your Work? Click Yes if So!"#13#10#13#10"Choose No to Cancel & Then Save...", 
 "Exit Confirmation", MB_YESNO+MB_ICONWARNING) = IDNO then Result := False; 
end; 

Please help me get the above working in 2.1.

Thanks

procedure OnCloseWindow(WindowName: String);

This is a procedure and not a function, so Result will not be used.

Try changing
procedure OnCloseWindow(WindowName: String);
to
function OnWindowCloseQuery (WindowName: String): Boolean;

Thank you for reply. Will try this after the holidays.

Now I see where I was confused. Simply assumed that the string:

procedure OnCloseWindow(WindowName: String);

was new way in V2. That is what I get for assuming:)

Thanks again for waking me up…

One thing I discovered when using scripting to show exit alert: it does not work when exiting app from the menubar file/exit application

Works when using the far right X button though.

Yes, Exit Application will cause the application to be terminated. If the user chooses it, it will not fire the Close Window event.

Does not work for me using the code you helped me with.

The exit popup works perfect when user clicks the X button top left.

The very top menubar, file/exit application does not work. If user chooses this method the app closes without popup exit intent appearing, just closes without interaction.

It’s because the menu item is associated to the Exit Application action, which causes the app to be terminated without any asking from user. That’s why it isn’t firing the OnWindowCloseQuery event.