I looked at two previous questions, viz. How to get elements by name in Delphi Chromium Embedded and Delphi Embedded Chrome. These questions and their answers are clear enough and easy to copy and paste, yet they do not work. The method visit() is never called.
Is this still the proper way to do this, or isn't it supposed to work in DCEF3? Or is it something else that can go awry here?
I am working with XE2 platform windows32.
unit Unit1;
interface
uses ceflib, cefvcl, Vcl.Forms, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Controls,
System.Classes;
type
TForm1 = class(TForm)
Chromium1: TChromium;
Panel1: TPanel;
Button1: TButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
public
end;
type
TElementNameVisitor = class(TCefDomVisitorOwn)
private
FName: string;
protected
procedure visit(const document: ICefDomDocument); override;
public
constructor Create(const AName: string); reintroduce;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Dialogs;
constructor TElementNameVisitor.Create(const AName: string);
begin
inherited Create;
FName := AName;
end;
procedure TElementNameVisitor.visit(const document: ICefDomDocument);
procedure ProcessNode(ANode: ICefDomNode);
var Node: ICefDomNode;
begin
if Assigned(ANode) then
begin
Node := ANode.FirstChild;
while Assigned(Node) do
begin
if Node.GetElementAttribute('name') = FName then
ShowMessage(Node.GetElementAttribute('value'));
ProcessNode(Node);
Node := Node.NextSibling;
end {while}
end {if};
end;
begin
ProcessNode(document.Body);
end;
procedure TForm1.Button1Click(Sender: TObject);
var visitor: TElementNameVisitor;
begin
visitor := TElementNameVisitor.Create('EuroB');
Chromium1.Browser.MainFrame.VisitDom(visitor);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Chromium1.Load('D:\Projects\Chromium\test.html');
end;
end.