Bart <[email protected]> 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
-- _______________________________________________ Lazarus mailing list [email protected] http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
