1
I have the following code:
procedure TMainForm.ValidarAcesso;
var
doc: variant;
element: variant;
begin
doc := coHTMLDocument.Create as IHTMLDocument2;
doc.write(memHtml.Text);
try
element := doc.getElementById('theElementId');
if VarToStr(element) <> '' then
ShowMessage(element.innerText)
else
ShowMessage('Acesso realizado com sucesso!');
except
end;
end;
I create a COM HTML Document and load a page’s HTML source into it and then search for an html element using getElementById.
It Works!
But, how do I add a control to see if the element actually exists/was found on the/html page?
When the element is not found, when hovering over the element variable, Delphi displays the value $00000000
.
I’ve already tested:
VarToStr(element) <> ''
element <> $00000000
VarType(element) ...
element <> null
element <> nil
But none of them worked!
In javascript (in the case of Webview) a null variable is
undefined
, try this or thenull
of Delphi, I think it’sNil
right? (Note: I know practically nothing of Delphi. I’m just trying to help)– Fernando Leal
Okay. It’s just that since it was a new tag I believed you were wrong, because I know every language, the Web component is called Webview. Good to know you solved your problem.
– Fernando Leal
You have tested the method
assigned
?– Guill