<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
</head>
<body>
<p style="margin: 0;">
<span>
<span></span>
</span>
</p>
<p style="margin: 0px;"> </p>
<div style="margin: 5px 0px 5px 0px;">
<br/>
Bart <bartjunk64@gmail.com> hat am 8. November 2011 um 17:49 geschrieben:
<br/>
<br/>
>[...]
<br/>
> function TEditorPageControl.ClosePage(Index: Integer): Boolean;
<br/>
> var
<br/>
> Cancel: Boolean;
<br/>
> Pg: TTabSheet;
<br/>
> Ed: TEditor;
<br/>
> begin
<br/>
> Result := False;
<br/>
> if (Index > PageCount - 1) then Exit;
<br/>
> Pg := Pages[Index]; //<-- Pg owns the SynEdit
<br/>
> Cancel := False;
<br/>
> if Assigned(FOnBeforeCloseEditor) then FOnBeforeCloseEditor(Pg, Cancel);
<br/>
> if Not Cancel then
<br/>
> begin
<br/>
>
<br/>
> //newly added code
<br/>
> Ed := EditorAtPage(Pg); //<- returns the SynEdit in question
<br/>
> Application.ReleaseComponent(Ed);
<br/>
> Application.ProcessMessages;
</div>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">ProcessMessages only processes the next messages in the event queue.</p>
<p style="margin: 0px;">You are still processing the current message. Processing means calling a function and waiting for it to return. </p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> </p>
<div style="margin: 5px 0px 5px 0px;">
> //end newly added code
<br/>
>
<br/>
> Pg.PageControl := nil;
<br/>
> Pg.Free;
<br/>
> Result := True;
<br/>
> if PageCount = 0 then InternalEditorStatusChange(nil, scAll);
<br/>
> end;
<br/>
> Debugln('TEditorPageControl.ClosePage End.');
<br/>
> end;
<br/>
>
<br/>
> This did not work, so I changed it into
<br/>
>
<br/>
> function TEditorPageControl.ClosePage(Index: Integer): Boolean;
<br/>
> var
<br/>
> Cancel: Boolean;
<br/>
> Pg: TTabSheet;
<br/>
> Ed: TEditor;
<br/>
> begin
<br/>
> Result := False;
<br/>
> if (Index > PageCount - 1) then Exit;
<br/>
> Pg := Pages[Index]; //<-- Pg owns the SynEdit
<br/>
> Cancel := False;
<br/>
> if Assigned(FOnBeforeCloseEditor) then FOnBeforeCloseEditor(Pg, Cancel);
<br/>
> if Not Cancel then
<br/>
> begin
<br/>
>
<br/>
> Ed := EditorAtPage(Pg); //<- returns the SynEdit in question
<br/>
> Application.ReleaseComponent(Ed);
<br/>
> Application.ProcessMessages;
<br/>
>
<br/>
> Pg.PageControl := nil;
<br/>
> Application.ReleaseComponent(Pg);
<br/>
> Application.ProcessMessages;
<br/>
>
<br/>
> Result := True;
<br/>
> if PageCount = 0 then InternalEditorStatusChange(nil, scAll);
<br/>
> end;
<br/>
> end;
<br/>
>
<br/>
> I had to use Application.ReleaseComponent on both the SynEdit and the
<br/>
> TabSheet in order to get it to work.
<br/>
>
<br/>
> Does this look OK?
<br/>
>
<br/>
>
<br/>
> >> Feauture or bug?
<br/>
> > By design. You should not free something that is in use.
<br/>
>
<br/>
> That depends on the meaning of "in use" ;-)
<br/>
> I did not know it (the SynEdit) was actually doing something at all.
</div>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">See the call stack in View / Debug Windows / Call Stack. </p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> </p>
<div style="margin: 5px 0px 5px 0px;">> This code worked perfectly in Delphi 3.</div>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">The winapi works differently than other widgetsets. Other widgetsets work more object oriented. The LCL was designed to work with various widgetsets. </p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> </p>
<div style="margin: 5px 0px 5px 0px;">> It also works fine if the SynEdit is replaced by a Memo.</div>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">Mattias</p>
<p style="margin: 0px;"> </p>
<div style="margin: 5px 0px 5px 0px;"></div>
</body>
</html>