mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-30 04:30:13 +02:00
Docked-form-designer: fix access after free / use SrcEditIntf events instead of hacking into IDE hooks. Should fix issue #39741
This commit is contained in:
parent
55dcbec511
commit
e037015ad6
@ -423,6 +423,7 @@ var
|
|||||||
LPageCtrl: TSourcePageControl;
|
LPageCtrl: TSourcePageControl;
|
||||||
LSourceWindowIntf: TSourceEditorWindowInterface;
|
LSourceWindowIntf: TSourceEditorWindowInterface;
|
||||||
LDesignForm: TDesignForm;
|
LDesignForm: TDesignForm;
|
||||||
|
w: TSourceWindow;
|
||||||
begin
|
begin
|
||||||
if Sender is TSourceEditorInterface then
|
if Sender is TSourceEditorInterface then
|
||||||
begin
|
begin
|
||||||
@ -494,6 +495,10 @@ begin
|
|||||||
LDesignForm.HideWindow;
|
LDesignForm.HideWindow;
|
||||||
LPageCtrl.InitPage;
|
LPageCtrl.InitPage;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
w := SourceWindows.SourceWindow[LSourceWindowIntf];
|
||||||
|
if w <> nil then
|
||||||
|
w.NoteBookPageChanged(nil);
|
||||||
end else begin
|
end else begin
|
||||||
{$IFDEF DEBUGDOCKEDFORMEDITOR} DebugLn('TDockedMainIDE.EditorActivated [' + DbgSName(Sender) + '] - not a Source Editor!');{$ENDIF}
|
{$IFDEF DEBUGDOCKEDFORMEDITOR} DebugLn('TDockedMainIDE.EditorActivated [' + DbgSName(Sender) + '] - not a Source Editor!');{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
@ -42,15 +42,12 @@ type
|
|||||||
TSourceWindow = class
|
TSourceWindow = class
|
||||||
private
|
private
|
||||||
FActiveDesignForm: TDesignForm;
|
FActiveDesignForm: TDesignForm;
|
||||||
FDefaultNotebookPageChanged: TNotifyEvent;
|
|
||||||
FLastActiveSourceEditor: TSourceEditorInterface;
|
FLastActiveSourceEditor: TSourceEditorInterface;
|
||||||
FLastTopParent: TControl;
|
FLastTopParent: TControl;
|
||||||
FNotebook: TExtendedNotebook;
|
FNotebook: TExtendedNotebook;
|
||||||
FPageControlList: TSourcePageControls;
|
FPageControlList: TSourcePageControls;
|
||||||
FSourceWindowIntf: TSourceEditorWindowInterface;
|
FSourceWindowIntf: TSourceEditorWindowInterface;
|
||||||
function GetActiveEditor: TSourceEditorInterface;
|
function GetActiveEditor: TSourceEditorInterface;
|
||||||
procedure HookIntoOnPageChanged;
|
|
||||||
procedure NoteBookPageChanged(Sender: TObject);
|
|
||||||
procedure SetActiveDesignForm(const AValue: TDesignForm);
|
procedure SetActiveDesignForm(const AValue: TDesignForm);
|
||||||
procedure UpdateEditorPageCaption(Sender: TObject);
|
procedure UpdateEditorPageCaption(Sender: TObject);
|
||||||
public
|
public
|
||||||
@ -58,6 +55,7 @@ type
|
|||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure AddPageCtrl(APageControl: TSourcePageControl);
|
procedure AddPageCtrl(APageControl: TSourcePageControl);
|
||||||
procedure AdjustPageControl;
|
procedure AdjustPageControl;
|
||||||
|
procedure NoteBookPageChanged(Sender: TObject);
|
||||||
function FindPageControl(ASourceEditor: TSourceEditorInterface): TSourcePageControl;
|
function FindPageControl(ASourceEditor: TSourceEditorInterface): TSourcePageControl;
|
||||||
procedure RemoveActiveDesignForm;
|
procedure RemoveActiveDesignForm;
|
||||||
procedure RemovePageCtrl(ASourceEditor: TSourceEditorInterface);
|
procedure RemovePageCtrl(ASourceEditor: TSourceEditorInterface);
|
||||||
@ -109,27 +107,11 @@ implementation
|
|||||||
|
|
||||||
{ TSourceWindow }
|
{ TSourceWindow }
|
||||||
|
|
||||||
procedure TSourceWindow.HookIntoOnPageChanged;
|
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
begin
|
|
||||||
for i := 0 to FSourceWindowIntf.ControlCount - 1 do
|
|
||||||
if FSourceWindowIntf.Controls[i] is TExtendedNotebook then
|
|
||||||
begin
|
|
||||||
FNotebook := TExtendedNotebook(FSourceWindowIntf.Controls[i]);
|
|
||||||
Break;
|
|
||||||
end;
|
|
||||||
if not Assigned(FNotebook) then Exit;
|
|
||||||
FDefaultNotebookPageChanged := FNotebook.OnChange;
|
|
||||||
FNotebook.OnChange := @NoteBookPageChanged;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TSourceWindow.NoteBookPageChanged(Sender: TObject);
|
procedure TSourceWindow.NoteBookPageChanged(Sender: TObject);
|
||||||
var
|
var
|
||||||
LPageCtrl: TSourcePageControl;
|
LPageCtrl: TSourcePageControl;
|
||||||
begin
|
begin
|
||||||
{$IFDEF DEBUGDOCKEDFORMEDITOR} DebugLn('TSourceWindow.NoteBookPageChanged SourceWindow[' + FSourceWindowIntf.Caption + ']'); {$ENDIF}
|
{$IFDEF DEBUGDOCKEDFORMEDITOR} DebugLn('TSourceWindow.NoteBookPageChanged SourceWindow[' + FSourceWindowIntf.Caption + ']'); {$ENDIF}
|
||||||
FDefaultNotebookPageChanged(Sender);
|
|
||||||
LPageCtrl := FindPageControl(ActiveEditor);
|
LPageCtrl := FindPageControl(ActiveEditor);
|
||||||
if not Assigned(LPageCtrl) then Exit;
|
if not Assigned(LPageCtrl) then Exit;
|
||||||
if LPageCtrl.DesignerPageActive then
|
if LPageCtrl.DesignerPageActive then
|
||||||
@ -193,15 +175,11 @@ begin
|
|||||||
FLastActiveSourceEditor := nil;
|
FLastActiveSourceEditor := nil;
|
||||||
FSourceWindowIntf := ASourceWindowIntf;
|
FSourceWindowIntf := ASourceWindowIntf;
|
||||||
FPageControlList := TSourcePageControls.Create;
|
FPageControlList := TSourcePageControls.Create;
|
||||||
FNotebook := nil;
|
|
||||||
HookIntoOnPageChanged;
|
|
||||||
FSourceWindowIntf.AddUpdateEditorPageCaptionHandler(@UpdateEditorPageCaption);
|
FSourceWindowIntf.AddUpdateEditorPageCaptionHandler(@UpdateEditorPageCaption);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TSourceWindow.Destroy;
|
destructor TSourceWindow.Destroy;
|
||||||
begin
|
begin
|
||||||
if Assigned(FNotebook) then
|
|
||||||
FNotebook.OnChange := FDefaultNotebookPageChanged;
|
|
||||||
FPageControlList.Free;
|
FPageControlList.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user