如何在 Delphi Chromium Embedded(再次)中按名称获取元素?
How to get elements by name in Delphi Chromium Embedded (again)?
我看了前两个问题,即。 How to get elements by name in Delphi Chromium Embedded and Delphi Embedded Chrome。这些问题及其答案足够清楚,易于复制和粘贴,但它们不起作用。方法 visit() 从未被调用。
这是否仍然是执行此操作的正确方法,或者它不应该在 DCEF3 中工作?还是这里有其他问题?
我正在使用 XE2 平台 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.
DCEF3 中似乎存在版本问题。我刚从 http://delphichromiumembedded.googlecode.com/svn/trunk/ 那里得到一份新副本,现在我的代码 被调用 。我不确定要报告哪些相关版本号。对于 LibCef.dll:
new: libcef.dll 有版本 1.1364.1123.0
old: libcef.dll 的版本是 3.2171.1979.0
奇怪的数字,但日期显示较低版本的数字是更新的编译。
我看了前两个问题,即。 How to get elements by name in Delphi Chromium Embedded and Delphi Embedded Chrome。这些问题及其答案足够清楚,易于复制和粘贴,但它们不起作用。方法 visit() 从未被调用。
这是否仍然是执行此操作的正确方法,或者它不应该在 DCEF3 中工作?还是这里有其他问题?
我正在使用 XE2 平台 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.
DCEF3 中似乎存在版本问题。我刚从 http://delphichromiumembedded.googlecode.com/svn/trunk/ 那里得到一份新副本,现在我的代码 被调用 。我不确定要报告哪些相关版本号。对于 LibCef.dll:
new: libcef.dll 有版本 1.1364.1123.0
old: libcef.dll 的版本是 3.2171.1979.0
奇怪的数字,但日期显示较低版本的数字是更新的编译。