Issue #1936: simplify code in TfrmTextEditor.FormClose

This commit is contained in:
Ansgar Becker
2024-04-29 16:28:11 +02:00
parent 45b9010e2b
commit 538cd1efc1
2 changed files with 12 additions and 19 deletions

View File

@@ -1204,7 +1204,7 @@ begin
Editor.SetMaxLength(FMaxLength);
Editor.TableColumn := FTableColumn;
Editor.MemoText.ReadOnly := not FAllowEdit;
if Editor.ShowModal = mrOk then begin
if Editor.ShowModal = mrYes then begin
FEdit.Text := Editor.GetText;
DoEndEdit(Sender);
end

View File

@@ -86,8 +86,8 @@ type
private
{ Private declarations }
FModified: Boolean;
FStopping: Boolean;
FClosingByApplyButton: Boolean;
FClosingByCancelButton: Boolean;
FDetectedLineBreaks,
FSelectedLineBreaks: TLineBreaks;
FMaxLength: Integer;
@@ -430,11 +430,9 @@ end;
procedure TfrmTextEditor.btnCancelClick(Sender: TObject);
var
Action: TCloseAction;
begin
Action := caNone;
FormClose(Self, Action);
FClosingByCancelButton := True;
Close;
end;
@@ -501,20 +499,15 @@ end;
procedure TfrmTextEditor.FormClose(Sender: TObject; var Action: TCloseAction);
var
DoPost: Boolean;
begin
if FStopping then
Exit;
FStopping := True;
if Modified and FClosingByApplyButton then
DoPost := True
else if Modified then
DoPost := MessageDialog(_('Apply modifications?'), mtConfirmation, [mbYes, mbNo]) = mrYes
else
DoPost := False;
if DoPost then
ModalResult := mrOk
if Modified then begin
if FClosingByCancelButton then
ModalResult := mrCancel
else if FClosingByApplyButton then
ModalResult := mrYes
else
ModalResult := MessageDialog(_('Apply modifications?'), mtConfirmation, [mbYes, mbNo]);
end
else
ModalResult := mrCancel;
end;