Hi,
from this site. I have learned a lot:
Reading and Writing form elements
There is a function called getformfieldnames, which I seem to understand fine, but I don't understand why it doesn't work for every website.
for example the hotmail.com site.
When I use this function and try to place it in a memo box, I get nothing.
Can anyone explain to me why it does not work, and how I should proceed about finding a way that it will work?
thank you!
3 replies to this topic
#1
Posted 11 March 2011 - 08:03 AM
|
|
|
#2
Posted 12 March 2011 - 06:34 AM
Show us the code you are using to use the function. I see that it returns the field names through a self-created TStrings. This is not a good practice due to higher possibility of memory leak, since it's not clear who is responsible to destroy the returned TStrings.
#3
Posted 12 March 2011 - 07:16 AM
This is the code I'm using:
i:=-1 repeat begin inc(i); theForm := GetFormByNumber(webbrowser1.document as IHTMLDocument2, i); fields := GetFormFieldNames(theForm); num := fields.IndexOf(theid); theform1 := i; end;until (num <> -1);
#4
Posted 12 March 2011 - 12:17 PM
I assume you are trying to add a list of field names to a memo box. I didn't understand your code since I have no idea what the variables were declared as nor what the function/procedure is expected to do.
The functions on the website worked fine for me. GetFormByNumber and GetFormFieldNames are the only ones needed. Drop a Webbrowser, a Memo box and a Button on a form. Add MSHTML to your uses clause. Add those two functions just after implementation. In the form's create procedure add, WebBrowser1.Navigate('http://www.hotmail.com'); For the Button1 onClick event add ...
Make sure you wait until the page is loaded first since there is little error handling. Make sure to add it if your'e going to use your code.
That code works for me at Hotmail.com. If you can explain what is happening and post more code maybe I could help.
BTW, LuthfiHakim's advise about using StringLists as results is good advise. It can be done but special attention should be made for destruction if there is no way around using a stringlist. For example, If all the function does is add strings from the StringList to a memo box one could change it to a procedure and do away with the result.
The functions on the website worked fine for me. GetFormByNumber and GetFormFieldNames are the only ones needed. Drop a Webbrowser, a Memo box and a Button on a form. Add MSHTML to your uses clause. Add those two functions just after implementation. In the form's create procedure add, WebBrowser1.Navigate('http://www.hotmail.com'); For the Button1 onClick event add ...
procedure TForm1.Button1Click(Sender: TObject);
var
document: IHTMLDocument2;
theForm: IHTMLFormElement;
index: integer;
fields: TStringList;
begin
document := WebBrowser.Document as IHTMLDocument2;
theForm := GetFormByNumber(WebBrowser.Document as IHTMLDocument2,0);
fields := GetFormFieldNames(theForm);
for index := 0 to fields.count-1 do
memo1.Lines.add('Field ' + IntToStr(index) + ' called ' + fields[index]);
fields.Destroy;
end;
Make sure you wait until the page is loaded first since there is little error handling. Make sure to add it if your'e going to use your code.
That code works for me at Hotmail.com. If you can explain what is happening and post more code maybe I could help.
BTW, LuthfiHakim's advise about using StringLists as results is good advise. It can be done but special attention should be made for destruction if there is no way around using a stringlist. For example, If all the function does is add strings from the StringList to a memo box one could change it to a procedure and do away with the result.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









