Solved

How to read a form field from a website

Posted on 2003-11-09
6
191 Views
Last Modified: 2010-04-05
Dear all,

How can I read a form field value (MyField) from a website (http://www.mysite.com/mypage.htm)?
I'm using Delphi 7 with Indy.

Thanks, Abraham
0
Comment
Question by:abraham_ll
  • 3
6 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9737236
If you just load the source, it won't have a value. Please explain further or give a better example.
0
 

Author Comment

by:abraham_ll
ID: 9738036
Thank you for your reply EddieShipman.

This is a form field which displays the users IP number.  So on load it has a value. Here is the code:

<script language="javascript">
  var ip = '<!--#echo var="REMOTE_ADDR"-->'
  function ipval() {document.myform.ipaddr.value=ip;}
  window.onload=ipval
</script>
<form method="post" action="" name="myform">
  <input type="text" name="ipaddr" readonly>
</form>
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9738951
very easy. I will post a solution in a couple of hours.
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 125 total points
ID: 10499068
So sorry it has taken me so long to do this...

procedure TForm1.ParseURL(AURL: String);
Var
  IDoc:IHTMLDocument2;
  Strm:TSTringStream;
  v:Variant;
  i       : Integer;
  vMeta   : IHTMLMetaElement;
  vAll    : IHTMLElementCollection;
  vElement: IHTMLElement;
begin
  Memo1.Clear;
  Strm:=TSTringStream.create('');
  Idhttp1.Get(AURL,strm);
  Idoc:=CreateComObject(Class_HTMLDocument) as IHTMLDocument2;
  IDoc.designMode:='on';
  while IDoc.readyState<>'complete' do
    Application.ProcessMessages;
  v:=VarArrayCreate([0,0],VarVariant);
  v[0]:= Strm.datastring;
  IDoc.write(PSafeArray(System.TVarData(v).VArray));
  IDoc.designMode:='off';
  while IDoc.readyState<>'complete' do
    Application.ProcessMessages;

  vAll := iDoc.all.tags('INPUT');
  for i:=0 to vAll.Length-1 do
  begin
   vElement:= vAll.item(i, varEmpty);
 
   if (vElement.getAttribute('Name', 0) = 'ipaddr') then
   begin
     Result := vElement.getAttribute('Value', 0);
   end;
  end;
  IDoc := nil;
  Strm.Free;
end;
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now