Using TCefFastDomVisitor3

Post Reply
jc4golf
Posts: 9
Joined: Wed Jun 23, 2021 12:33 am

Using TCefFastDomVisitor3

Post by jc4golf »

I'm trying to use TCefFastDomVisitor3 to pass a value to search for in the browser, but in Delphi 10.2.3 I get "Incompatible types: 'TCefDomVisitorProc3' and 'Procedure'".
User avatar
salvadordf
Posts: 3067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Using TCefFastDomVisitor3

Post by salvadordf »

Hi,

I just did a quick test and it works correctly on the latest Delphi 10.4

Perhaps the procedure used in TCefFastDomVisitor3.Create doesn't have the right parameters. It should be like this :

Code: Select all

procedure MyProcedure(const browser : ICefBrowser; const frame: ICefFrame; const document: ICefDomDocument; const aValue : ustring);
Compared to the procedure used by TCefFastDomVisitor2 this one has an extra "aValue" parameter at the end.
jc4golf
Posts: 9
Joined: Wed Jun 23, 2021 12:33 am

Re: Using TCefFastDomVisitor3

Post by jc4golf »

Here's my code using TCefFastDomVisitor2 and TCefFastDomVisitor3 (TempVisitor2 works, but TempVisitor3 doesn't):

procedure DOMVisitor_OnDocAvailable(const browser: ICefBrowser;
const frame: ICefFrame; const document: ICefDomDocument);
var
x, y, w, h: Integer;
t: String;
TempMessage: ICefProcessMessage;
begin
x := 0;
y := 0;
w := 0;
h := 0;
t := '';
SimpleDOMIteration(document,
'css-dvua67-singleValue react-select__single-value', x, y, w, h, t);
try
TempMessage := TCefProcessMessageRef.New(MSGNAME_SEND_COORDINATES);
TempMessage.ArgumentList.SetString(0, IntToStr(x));
TempMessage.ArgumentList.SetString(1, IntToStr(y));
TempMessage.ArgumentList.SetString(2, IntToStr(w));
TempMessage.ArgumentList.SetString(3, IntToStr(h));
TempMessage.ArgumentList.SetString(4, t);
if (frame <> nil) and frame.IsValid then
frame.SendProcessMessage(PID_BROWSER, TempMessage);
finally
TempMessage := nil;
end;
end;

procedure DOMVisitor_OnDocAvailable2(const browser: ICefBrowser;
const frame: ICefFrame; const document: ICefDomDocument;
const CourseForPost: String);
var
x: Integer;
TempMessage: ICefProcessMessage;
begin
x := -1;
SimpleDOMIteration2(document, 'item__name', CourseForPost, x);
try
TempMessage := TCefProcessMessageRef.New(MSGNAME_SEND_POSTING_COURSES);
TempMessage.ArgumentList.SetString(0, IntToStr(x));
if (frame <> nil) and frame.IsValid then
frame.SendProcessMessage(PID_BROWSER, TempMessage);
finally
TempMessage := nil;
end;
end;

procedure GlobalCEFApp_OnProcessMessageReceived(const browser: ICefBrowser;
const frame: ICefFrame; sourceProcess: TCefProcessId;
const message: ICefProcessMessage; var aHandled: Boolean);
var
TempVisitor2: TCefFastDomVisitor2;
TempVisitor3: TCefFastDomVisitor3;
CourseForPost: ustring;
begin
if (message = nil) or (message.ArgumentList = nil) then
Exit;
aHandled := false;
if browser <> nil then
begin
if message.Name = MSGNAME_GET_USGA_COORDINATES then
begin
if (frame <> nil) and frame.IsValid then
begin
TempVisitor2 := TCefFastDomVisitor2.Create(browser, frame,
DOMVisitor_OnDocAvailable);
frame.VisitDom(TempVisitor2);
end
else
UpdatingCurrentIndexes := false;
aHandled := true;
end
else if message.Name = MSGNAME_GET_POSTING_COURSE then
begin
if (frame <> nil) and frame.IsValid then
begin
CourseForPost := message.ArgumentList.GetString(0);
TempVisitor3 := TCefFastDomVisitor3.Create(browser, frame,
DOMVisitor_OnDocAvailable2, CourseForPost);
frame.VisitDom(TempVisitor3);
end
else
UpdatingCurrentIndexes := false;
aHandled := true;
end;
end;
end;
User avatar
salvadordf
Posts: 3067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Using TCefFastDomVisitor3

Post by salvadordf »

The CourseForPost parameter in DOMVisitor_OnDocAvailable2 needs to be a ustring instead of a string.
jc4golf
Posts: 9
Joined: Wed Jun 23, 2021 12:33 am

Re: Using TCefFastDomVisitor3

Post by jc4golf »

Thank you Salvador, never would have thought that would be the cause, but it works now. On to the next problem.
Post Reply