Search code examples
delphidelphi-7delphi-xe2delphi-xe

if else statement not executing right


I have a very funny behaviour of my if else statement. At start the memo is empty and attempted deletion triggers the message. Then if I write something in memo and try to delete, again the right message comes up. But then, after last deletion (memo is now empty) if I click once again to delete I get the second message and not the first (nothing to delete. Am I messing if else statements ?? What is the right way here ?

procedure TForm1.AdvGlowButton2Click(Sender: TObject);
begin
   if advmemo1.IsEmpty then
      ShowMessage('Nothing to delete !')
   else  
   begin
     if MessageDlg('Delete everything?',
                     mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
       advmemo1.Lines.Clear;
       advmemo1.Lines.SaveToFile(ExtractFilePath(Application.ExeName)+ '\memo.txt');
     end;
   end;
end;

Solution

  • after saving you must call

    advmemo1.RefreshMemo;