After weeks of no coding, I'm back on my feet again, doing some coding again... My quest this time: To loop through all the frames in a TWebBrowser.
Here's how to get the code below to find all the frames (regardless of level of nesting) in a TWebBrowser: FindFrame(WebBrowser1.Document);
procedure FindFrame(ADocument: IHTMLDocument2);var LDocument: IHTMLDocument2; LContainer: IOleContainer; LEnumerator: IEnumUnknown; LUnknown: IUnknown; LFetched: Longint; LBrowser: IWebBrowser2; LResult: HRESULT;begin if not Supports(ADocument, IOleContainer, LContainer) then exit; if not Succeeded(LContainer.EnumObjects(OLECONTF_EMBEDDINGS, LEnumerator)) then exit; while LEnumerator.Next(1, LUnknown, @LFetched)=S_OK do begin if Supports(LUnknown, IID_IWebBrowser2, LBrowser) then begin // Is a frame if Supports(LBrowser.Document, IID_IHTMLDocument2, LDocument) then begin Memo1.Lines.Add(LDocument.title); FindFrame(LDocument); LDocument := nil; end; LBrowser := nil; end; LUnknown := nil; end; LEnumerator := nil; LContainer := nil;end;
In 2017, with the release of Delphi 10.2 Tokyo, Embarcadero introduced a specialized implementation of the Observer pattern into the System.Classes unit. While it has been in the wild for 9 years, it remains a "hidden" architecture for many, primarily because it serves as the invisible engine behind LiveBindings. Other than live bindings, you can also use the Observer pattern as a way to update component settings to the Windows registry, an .ini file, or persist it elsewhere.
System.Classes