我看了两个先前的问题,即。 How to get elements by name in Delphi Chromium Embedded和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.
答案 0 :(得分:0)
DCEF3中似乎存在版本问题。我刚收到http://delphichromiumembedded.googlecode.com/svn/trunk/的新副本,现在我的代码被调用了。我不确定要报告哪些相关版本号。对于LibCef.dll:
new :libcef.dll的版本为1.1364.1123.0
old :libcef.dll的版本为3.2171.1979.0
奇怪的数字,但日期显示较低版本的nulber是最近的编译。