如何在Delphi Chromium Embedded中按名称获取元素(再次)



我看了前面的两个问题,即如何在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:ProjectsChromiumtest.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

奇怪的数字,但日期显示,较低版本的nulber是最近的汇编。

最新更新