function TMyWin.CanClose: boolean;
var
reply : integer;
begin
CanClose := not IsDirty;
if (isDirty) then
begin
Reply := MessageBox(HWindow,'Are you sure','File not saved',mb_YesNo + mb_IconQuestion);
if (Reply = idYes) then
begin
isDirty := false;
CanClose := true;
end;
end;
end;