From 1cefa33866c327eef4169ab7aaba7cb0c364bdbd Mon Sep 17 00:00:00 2001 From: juha Date: Tue, 3 Nov 2015 15:41:19 +0000 Subject: [PATCH] IDE: Prevent AV when trying to record a macro with closed editors. Issue #28947. git-svn-id: trunk@50214 - --- ide/editormacrolistviewer.pas | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/ide/editormacrolistviewer.pas b/ide/editormacrolistviewer.pas index 991941184a..e3b153c6e1 100644 --- a/ide/editormacrolistviewer.pas +++ b/ide/editormacrolistviewer.pas @@ -1037,9 +1037,12 @@ procedure TMacroListView.btnPlayClick(Sender: TObject); var i: Integer; M: TEditorMacro; + se: TSourceEditorInterface; begin if ActiveEditorMacro <> nil then exit; if lbRecordedView.ItemIndex < 0 then exit; + se := SourceEditorManagerIntf.ActiveEditor; + if se = nil then Exit; i := 1; if chkRepeat.Enabled then i := edRepeat.Value; @@ -1049,7 +1052,7 @@ begin M := CurrentEditorMacroList.Macros[lbRecordedView.ItemIndex]; try while i > 0 do begin - M.PlaybackMacro(TCustomSynEdit(SourceEditorManagerIntf.ActiveEditor.EditorControl)); + M.PlaybackMacro(TCustomSynEdit(se.EditorControl)); Application.ProcessMessages; dec(i); if not FIsPlaying then break; @@ -1094,19 +1097,20 @@ begin end; procedure TMacroListView.btnRecordClick(Sender: TObject); +var + se: TSourceEditorInterface; begin - if (ActiveEditorMacro = nil) and (EditorMacroForRecording.State = emStopped) then begin - EditorMacroForRecording.RecordMacro(TCustomSynEdit(SourceEditorManagerIntf.ActiveEditor.EditorControl)); - end + se := SourceEditorManagerIntf.ActiveEditor; + if se = nil then Exit; + if (ActiveEditorMacro = nil) and (EditorMacroForRecording.State = emStopped) then + EditorMacroForRecording.RecordMacro(TCustomSynEdit(se.EditorControl)) else - if EditorMacroForRecording.State = emRecording then begin - EditorMacroForRecording.Pause; - end + if EditorMacroForRecording.State = emRecording then + EditorMacroForRecording.Pause else - if EditorMacroForRecording.State = emRecPaused then begin + if EditorMacroForRecording.State = emRecPaused then EditorMacroForRecording.Resume; - end; - SourceEditorManagerIntf.ActiveEditor.EditorControl.SetFocus; + se.EditorControl.SetFocus; end; procedure TMacroListView.btnRecordStopClick(Sender: TObject); @@ -1342,7 +1346,9 @@ begin chkRepeat.Enabled := IsStopped and (not FIsPlaying); edRepeat.Enabled := IsStopped and (not FIsPlaying); - btnRecord.Enabled := (RecState in [emStopped, emRecPaused, emRecording]) and (not FIsPlaying); + btnRecord.Enabled := Assigned(SourceEditorManagerIntf.ActiveEditor) + and (RecState in [emStopped, emRecPaused, emRecording]) + and (not FIsPlaying); btnRecordStop.Enabled := (not IsStopped) or FIsPlaying; if (RecState = emRecording) then