System Delphi

Title: Confirmation on Windows exit
Use onCloseQuery event of main form. The OnCloseQuery event occurs when the Close method is called or when the user chooses Close from the form's System menu.
So, you may ask confirmation and close form, if user click on Yes button.
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if MessageDlg(
'Are you sure?',
mtConfirmation,
[mbYes, mbNo],
0)=mrNo then
CanClose:=False
else
CanClose:=True;
end;