Để có được một nút DOM cụ thể được nhúng trong tài liệu web hiện tại từ một cá thể TChromium, sử dụng ID của nó, bạn sử dụng ICefDomDocument.getElementById(). Nhưng làm thế nào để bạn tìm thấy các yếu tố của thuộc tính NAME? Javascript có phương thức document.getElementsByName() và TWebBrowser (bao bọc IE) có một cuộc gọi tương tự, nhưng tôi không thể tìm ra cách làm điều này với TChromium. Tôi cần phải tìm một số phần tử DOM có thuộc tính NAME nhưng không có thuộc tính ID. Tôi đã tìm kiếm đơn vị ceflib và không thấy bất kỳ thứ gì có thể thực hiện được.Làm thế nào để có được các yếu tố theo tên trong Delphi Chromium nhúng?
Câu hỏi phụ. Nếu có ai có liên kết đến trang web kiểu "công thức nấu ăn" hoặc tài liệu TChromium thì tôi có thể sử dụng nó.
CẬP NHẬT: Trong khi đợi câu trả lời, tôi đã đưa ra mã sau đây để thực hiện getElementsbyName(). Tôi muốn cái gì đó nhanh hơn quét toàn bộ cây DOM. Nếu bạn nhìn thấy một cái gì đó sai trong các mã cho tôi biết:
type
TDynamicCefDomNodeArray = array of ICefDomNode;
// Given a Chromium document interface reference and a NAME attribute to search for,
// return an array of all DOM nodes whose NAME attribute matches the desired.
function getElementsByName(ADocument: ICefDomDocument; theName: string): TDynamicCefDomNodeArray;
// Get all the elements with a particular NAME attribute value and return
// an array of them.
procedure getElementsByName1(intfParentNode: ICefDomNode; theName: string; var aryResults: TDynamicCefDomNodeArray);
var
oldLen: integer;
intfChildNode: ICefDomNode;
theNameAttr: string;
begin
Result := nil;
intfChildNode := nil;
if Assigned(intfParentNode) then
begin
// Attributes are case insensitive.
theNameAttr := intfParentNode.GetElementAttribute('name');
if AnsiSameText(theNameAttr, theName) then
begin
// Name attribute match. Add it to the results array.
oldLen := Length(aryResults);
SetLength(aryResults, oldLen + 1);
aryResults[oldLen] := intfParentNode;
end; // if AnsiSameText(intfParentNode.Name, theName) then
// Does the parent node have children?
if intfParentNode.HasChildren then
begin
intfChildNode := intfParentNode.FirstChild;
// Scan them.
while Assigned(intfChildNode) do
begin
getElementsByName1(intfChildNode, theName, aryResults);
if Assigned(intfChildNode) then
intfChildNode := intfChildNode.NextSibling;
end;
end; // if intfParentNode.HasChildren then
end; // if Assigned(intfParentNode) then
end;
// ---------------------------------------------------------------
var
intfCefDomNode: ICefDomNode;
begin
intfCefDomNode := nil;
Result := nil;
if Assigned(ADocument) then
begin
// Check the header.
intfCefDomNode := ADocument.Document;
if Assigned(intfCefDomNode) then
begin
// Check the parent.
getElementsByName1(intfCefDomNode, theName, Result);
end; // if Assigned(intfCefDomNode) then
end; // if Assigned(ADocoument) then
end;
// ---------------------------------------------------------------
Tôi không nghĩ rằng nó là khôn ngoan để trộn và kết hợp công nghệ 10 năm với công cụ hiện đại và mong đợi nó trở thành một giải pháp tìm thấy và ổn định. Trong trường hợp cụ thể này, TChromium không hỗ trợ Delph 6. http://code.google.com/p/delphichromiumembedded/ –
@Jeroen, ['TChromium'] (http://code.google.com/p/delphichromiumembedded /) không hỗ trợ Delphi 6 mặc dù (không có gói cho nó), nhưng nó không có nghĩa là nó không thể làm việc ở đó. Tôi có Delphi 2009, mà cũng không được hỗ trợ, nhưng nhìn vào nguồn, không có gì có thể ức chế việc sử dụng có ;-) – TLama
@TLama nếu tâm trí của tôi phục vụ tôi đủ tốt, Delphi 7 giới thiệu khá một vài sửa chữa liên quan đến gói COM stuff. Đó có thể là lý do để không hỗ trợ Delphi 6. Tôi khuyên bạn nên Robert xác minh giả định này với nhóm TChromium. –