From 358bee628c2080d034ba7bf357425adbad55b95c Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Mon, 29 Apr 2024 16:04:34 +0200 Subject: [PATCH] Issue #1936: Attempt to fix EAbstractError when closing text editor --- source/grideditlinks.pas | 31 ++++++++++++++++++------------- source/texteditor.pas | 14 +++++++++----- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/source/grideditlinks.pas b/source/grideditlinks.pas index 2b3058d1..29fdb91f 100644 --- a/source/grideditlinks.pas +++ b/source/grideditlinks.pas @@ -1147,10 +1147,14 @@ end; destructor TInplaceEditorLink.Destroy; begin - if Assigned(FTextEditor) then - FTextEditor.Release; - if not ((csDestroying in FPanel.ComponentState) or (csCreating in FPanel.ControlState)) then + if Assigned(FTextEditor) then begin + FTextEditor.Free; + end; + if not ((csDestroying in FPanel.ComponentState) or (csCreating in FPanel.ControlState)) then begin + FEdit.Free; + FButton.Free; FPanel.Free; + end; inherited; end; @@ -1173,8 +1177,9 @@ function TInplaceEditorLink.CancelEdit: Boolean; begin Result := inherited CancelEdit; if Result then begin - if Assigned(FTextEditor) then + if Assigned(FTextEditor) then begin FTextEditor.Close; + end; end; end; @@ -1184,14 +1189,8 @@ var begin Result := not FStopping; if FStopping then Exit; - if Assigned(FTextEditor) then begin - NewText := FTextEditor.GetText; - FModified := FTextEditor.Modified; - FTextEditor.Close; - end else begin - NewText := FEdit.Text; - FModified := FEdit.Modified; - end; + NewText := FEdit.Text; + FModified := NewText <> FCellText; Result := EndEditHelper(NewText); end; @@ -1218,7 +1217,13 @@ begin FTextEditor.SetMaxLength(FMaxLength); FTextEditor.TableColumn := FTableColumn; FTextEditor.MemoText.ReadOnly := not FAllowEdit; - FTextEditor.ShowModal; + if FTextEditor.ShowModal = mrOk then begin + FEdit.Text := FTextEditor.GetText; + DoEndEdit(Sender); + end + else begin + DoCancelEdit(Sender); + end; end; function TInplaceEditorLink.PrepareEdit(Tree: TBaseVirtualTree; diff --git a/source/texteditor.pas b/source/texteditor.pas index 32f1b081..790fcdf2 100644 --- a/source/texteditor.pas +++ b/source/texteditor.pas @@ -87,6 +87,7 @@ type { Private declarations } FModified: Boolean; FStopping: Boolean; + FClosingByApplyButton: Boolean; FDetectedLineBreaks, FSelectedLineBreaks: TLineBreaks; FMaxLength: Integer; @@ -242,6 +243,7 @@ var i: Integer; begin HasSizeGrip := True; + FClosingByApplyButton := False; // Assign linebreak values to their menu item tags, to write less code later menuWindowsLB.Tag := Integer(lbsWindows); menuUnixLB.Tag := Integer(lbsUnix); @@ -505,21 +507,23 @@ begin if FStopping then Exit; FStopping := True; - if Modified then + 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 - TCustomVirtualStringTree(Owner).EndEditNode + ModalResult := mrOk else - TCustomVirtualStringTree(Owner).CancelEditNode; + ModalResult := mrCancel; end; procedure TfrmTextEditor.btnApplyClick(Sender: TObject); begin - FStopping := True; - TCustomVirtualStringTree(Owner).EndEditNode; + FClosingByApplyButton := True; + Close; end;