Well, this may seem a little like a cheat (it is!), but I had a requirement to interface a barcode reader (via a ComPort) to a database via the network. Developing an html/idc/htx interface to the data was simple enough, but there was no simple way to connect the barcode reader using either Internet Explorer or Netscape.
This page presents several ways to accomplish this
TWebBrowser
WebBrowser1: TWebBrowser; procedure TForm1.Button3Click(Sender: TObject); var URL: WideString; Flags: OleVariant; TargetFrameName: OleVariant; PostData: OleVariant; begin Flags := 12; TargetFrameName := null; PostData := Barcode_UIEdit.Text; URL := 'www.SomePage.com/Script/Items_3.IDC?barcode=' + PostData; WebBrowser1.Navigate (URL, Flags, TargetFrameName, PostData); end;There are numerous problems with this
View Source
procedure TForm1.Button1Click(Sender: TObject); var DOM : variant; begin DOM := WebBrowser1.Document; if Webbrowser1.LocationURL <> '' then begin Memo1.text := DOM.Body.OuterHTML; end else ShowMessage('No page available!'); end;
The problem is that the source is reformatted!
<font face="Verdana" size="2" color="Black">becomes
<FONT face=Verdana color=Black size=2>References:
Posting Data
When a form Gets data, the query parameters are added to the html address (the question mark - ? - marks the beginning of the parameters and the ampersand - & - separates the individual parameters.)
URL := 'www.SomePage.com/Script/Some.IDC?Parm1=Value1&Parm2=Value2';When the data is Posted, the parameters are NOT displayed in the url.
So, other than hiding the parameters, why do we care? Well, it appears that ColdFusion is capable of accepting only Posted parameters and ignoring those attached to the url.
Unfortunately, if you follow the instructions in the Delphi 5 help, the Post fails. A solution is presented in Delphi tips and FAQs. Basically,
var URL: WideString; Flags: OleVariant; TargetFrameName: OleVariant; PostData: OleVariant; Headers: OleVariant; tempStr: string; i: Integer; begin Flags := 12; // Do not use the cache TargetFrameName := ''; // Not '' to open a new browser window URL := 'https://dodaac.wpafb.af.mil/results.cfm?requesttimeout=1000'; tempStr := 'Param1Name=value1&Param2Name=value2'; PostData := VarArrayCreate([0, Length(tempStr) - 1], varByte); { copy the ordinal value of the character into the PostData array} for i := 1 to Length(tempStr) do PostData[i-1] := Ord(tempStr[i]); Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13; WebBrowser1.Navigate (URL, Flags, TargetFrameName, PostData, Headers);I have verified that this works. Of course, none of this is documented in the Delphi help.
Note: When TargetFrameName is a null string, and the target page has a security certificate that you must manually accept, the parameters do not work the first time that the page is called - they work fine after that (ie the second time Navigate is called).
TClientSocket
Assuming that you are expecting data (as opposed to a formatted web page), you will want to include some kind of delimiters to simplify parsing the file. xml is one standard that can be used for that purpose.
Use a TWinSocketStream object to read from the connection when ClientType=ctBlocking.
TCustomWinSocket.ReceiveText works when ClientType=ctNonBlocking.
ReceiveText is not listed as a method of TClientSocket which is derived from TCustomSocket. There are 2 main types of sockets
TObject -> TPersistent -> TComponent -> TAbstractSocket -> TCustomSocket -> TClientSocket TObject -> TCustomWinSocket ->TClientWinSocket
See the CHAT demo for an example of how to use TClientSocket.
TNMHTTP
This code will create a file in the same directory as the exe-file.
procedure TForm1.Button1Click(Sender: TObject); begin NMHTTP1.Body := 'default.html'; NMHTTP1.InputFileMode := true; NMHTTP1.Get('http://www.google.com/'); end;Note: Since FastNet is not bundled with Delphi 7, TNMHTTP is also not available (unless you BUY it - $200). Author: Robert Clemenzi - clemenzi@cpcug.org