Problem when shutting down program

I'm using AdvStringGrid.

 
When I want to shut down the program, I check whether the stringgrid has been modified.
 
In "OnCloseQuery" I call the following "CheckSave" routine.
 
function Thomeplanform.checksave(fname : string) : tmodalresult;
begin
  result := mryes;  // assume okay
  mbb(sg1.modified);
  mbb(sg1.modified);
  if sg1.Modified then
   begin
     result := MessageDlg('The current plan has been modified.' + #13 +
                       'Do you want to save it?', mtconfirmation, [mbYes, mbNo, mbCancel], 0);
     if result = mrcancel then exit;
     if result = mryes then
        if not dosave(fname) then result := mrCancel;
   end
end;
"mbb" simply displays a messagebox showing "true" or "false".
 
The first call indicates "false" and the second call indicates "true". But nothing has changed!!
 
This really has me stumped.
 

I think I've figured it out.

 
Opening the first dialog automatically finishes the editing session, which had been started, which then sets the grid to "modified".