Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-02

Exception when re-opening a modal dialogue

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Timothy Groves

So when I call TfrmNewChapter.ShowModal, it works the first time. But when I call it the second time, I get an exception. The form is closed with the OK or Cancel buttons; their methods are given below. What am I doing wrong?

procedure TfrmNewChapter.btnCancelClick(Sender: TObject);
begin
   txtChapterTitle.Text := '';
   frmNewChapter.Hide;
end;
procedure TfrmNewChapter.btnOKClick(Sender: TObject);
var
   s : string;
begin
   if (txtChapterTitle.Text  '') then begin
     NewChapter (txtChapterTitle.Text);
     txtChapterTitle.Text := '';
     str (ChapterCount, s);
     while (length (s) < 4) do
         s := '0' + s;
     Chapter^.Filename := Story^.ShortName + s;
     PopulateChapterList;
     frmNewChapter.Hide;
     MarkChapterListDirty;
   end;
end;

Reply by email

Mattias Gaertner
to Timothy Groves
Show quoted text 10 lines
So when I call TfrmNewChapter.ShowModal, it works the first time. But when I call it the second time, I get an exception. The form is closed with the OK or Cancel buttons; their methods are given below. What am I doing wrong? procedure TfrmNewChapter.btnCancelClick(Sender: TObject); begin txtChapterTitle.Text := ''; frmNewChapter.Hide;

Do not hide the form yourself. That's done by ShowModal. Set the ModalResult.

ModalResult:=mrCancel;
Show quoted text 15 lines
end; procedure TfrmNewChapter.btnOKClick(Sender: TObject); var s : string; begin if (txtChapterTitle.Text '') then begin NewChapter (txtChapterTitle.Text); txtChapterTitle.Text := ''; str (ChapterCount, s); while (length (s) < 4) do s := '0' + s; Chapter^.Filename := Story^.ShortName + s; PopulateChapterList; frmNewChapter.Hide;
ModalResult:=mrOk;
MarkChapterListDirty; end; end;

Mattias

Reply by email