@wp: if I check your app on Linux with 2.2.4 then I get an operation was cancelled messagebox when selecting cancel or no and after canceling the savedialog. I take it that is the intended behaviour ?
Yes. That's fine because it tells me that the bug is not in the general TFileDialog/TCommonDialog code, but in the win32 widgetset code. And in fact there is the win32-specific function TFileDialogEvents.OnFileOK which does not reset the FDialog.UserChoice in case of CanClose is false. With the following modification, the overall behaviour is correct, on Windows:
function TFileDialogEvents.OnFileOk(pfd: IFileDialog): HResult; stdcall; // removed the {$ifdef...} instructions
var
CanClose: Boolean;
begin
Result := TWin32WSOpenDialog.ProcessVistaDialogResult(pfd, FDialog);
if Succeeded(Result) then
begin
FDialog.UserChoice := mrOK; //DoCanClose needs this
CanClose := True;
FDialog.DoCanClose(CanClose);
if CanClose then
begin
Result := S_OK;
end
else
begin
FDialog.UserChoice := mrNone; // <---- ADDED
Result := S_FALSE;
end;
end;
end;
[EDIT]
Filed a bug report for documentation (
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40297), and committed above fix to Laz/main.