Reputation: 13
I have the following controls on a form: Memo1, Memo2 and WebBrowser. OnExit procedures of controls Memo1 and Memo2 are to update the WebBrowser content with the content of Memo1.Text and Memo2.Text. I use the following procedures for this:
procedure LoadBlankDoc(WB: TWebBrowser);
begin
WB.Navigate('about:blank', EmptyParam, EmptyParam, EmptyParam, EmptyParam);
while WB.ReadyState = READYSTATE_COMPLETE do
begin
Application.ProcessMessages;
Sleep(0);
end;
end;
procedure CheckDocReady(WB: TWebBrowser);
begin
if not Assigned(WB.Document) then
LoadBlankDoc(WB);
end;
procedure LoadDocFromString(WB: TWebBrowser; const HTMLString: string);
var
v: OleVariant;
HTMLDocument: IHTMLDocument2;
begin
CheckDocReady(WB);
HTMLDocument := WB.Document as IHTMLDocument2;
v := VarArrayCreate([0, 0], varVariant);
v[0] := HTMLString;
HTMLDocument.Write(PSafeArray(TVarData(v).VArray));
HTMLDocument.Close;
end;
The problem is that when the Memo1 control is active and we click in the WebBrowser area and then click in the Memo2 area, then the cursor does not appear or disappears after the first character is entered. Sometimes the application gets lost and you can't enter text into Memo at all. One more thing: when I move between Memo1 and Memo2, everything works as it should. The problem occurs when OnExit occurs by clicking in the WebBrowser area. What could be the reason?
2023-05-09
My further analysis of the topic...
Posting this problem on the forum, I rather suspected some error in the LoadDocFromString procedure. However, further experiments showed:
If we have set the focus on some Memo control, eg. Memo1, then we click on the WebBrowser area, then the focus is removed from Memo1 ... but! the Memo1Exit procedure is not executed.
If we now click on some other control, e.g. Memo2, now Memo1Exit is executed.
And everything works fine...
However, it is enough in the OnExit event of the Memo control put a call to LoadDocFromString ... and the problems begin.
Upvotes: 0
Views: 216