[Lazarus] TSynEdit bug in destructor?
Mattias Gaertner
nc-gaertnma at netcologne.de
Tue Nov 8 18:18:31 CET 2011
Bart <bartjunk64 at gmail.com> hat am 8. November 2011 um 17:49 geschrieben:
>[...]
> function TEditorPageControl.ClosePage(Index: Integer): Boolean;
> var
> Cancel: Boolean;
> Pg: TTabSheet;
> Ed: TEditor;
> begin
> Result := False;
> if (Index > PageCount - 1) then Exit;
> Pg := Pages[Index]; //<-- Pg owns the SynEdit
> Cancel := False;
> if Assigned(FOnBeforeCloseEditor) then FOnBeforeCloseEditor(Pg, Cancel);
> if Not Cancel then
> begin
>
> //newly added code
> Ed := EditorAtPage(Pg); //<- returns the SynEdit in question
> Application.ReleaseComponent(Ed);
> Application.ProcessMessages;
ProcessMessages only processes the next messages in the event queue.
You are still processing the current message. Processing means calling a
function and waiting for it to return.
> //end newly added code
>
> Pg.PageControl := nil;
> Pg.Free;
> Result := True;
> if PageCount = 0 then InternalEditorStatusChange(nil, scAll);
> end;
> Debugln('TEditorPageControl.ClosePage End.');
> end;
>
> This did not work, so I changed it into
>
> function TEditorPageControl.ClosePage(Index: Integer): Boolean;
> var
> Cancel: Boolean;
> Pg: TTabSheet;
> Ed: TEditor;
> begin
> Result := False;
> if (Index > PageCount - 1) then Exit;
> Pg := Pages[Index]; //<-- Pg owns the SynEdit
> Cancel := False;
> if Assigned(FOnBeforeCloseEditor) then FOnBeforeCloseEditor(Pg, Cancel);
> if Not Cancel then
> begin
>
> Ed := EditorAtPage(Pg); //<- returns the SynEdit in question
> Application.ReleaseComponent(Ed);
> Application.ProcessMessages;
>
> Pg.PageControl := nil;
> Application.ReleaseComponent(Pg);
> Application.ProcessMessages;
>
> Result := True;
> if PageCount = 0 then InternalEditorStatusChange(nil, scAll);
> end;
> end;
>
> I had to use Application.ReleaseComponent on both the SynEdit and the
> TabSheet in order to get it to work.
>
> Does this look OK?
>
>
> >> Feauture or bug?
> > By design. You should not free something that is in use.
>
> That depends on the meaning of "in use" ;-)
> I did not know it (the SynEdit) was actually doing something at all.
See the call stack in View / Debug Windows / Call Stack.
> This code worked perfectly in Delphi 3.
The winapi works differently than other widgetsets. Other widgetsets work more
object oriented. The LCL was designed to work with various widgetsets.
> It also works fine if the SynEdit is replaced by a Memo.
Mattias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20111108/c1a46af4/attachment-0003.html>
More information about the Lazarus
mailing list