Forma bir tane Buton, bir tane de Listbox eklemeyi unutmayın.
Kod: Tümünü seç
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons,Msxml;
type
TForm1 = class(TForm)
BtnHttp: TBitBtn;
lbEmpName: TListBox;
procedure BtnHttpClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnHTTPClick(Sender: TObject);
var
nodeEmployee,
nodeDetail : IXMLDOMNode;
attrEmpName : IXMLDOMNode;
strEmpName : String;
i : integer;
nodeMap : IXMLDOMNamedNodeMap;
xmldoc,g_xmlCBCV : IXMLDOMDocument;
xmlhttp : IXMLHttpRequest;
bStrMethod, bstrUrl, varASync, bStrUser, bStrPassword : OleVariant;
s : String;
begin
bStrMethod := 'POST';
bstrUrl := 'http://localhost/get_cv.asp';
varAsync := false;
bStrUser := '';
bStrPassword :='';
s := '<?xml version="1.0"?>';
s := s + '<Envelope>';
s := s + '<Body>';
s := s + '<get_cv>';
s := s + 'all';
s := s + '</get_cv>';
s := s + '</Body>';
s := s + '</Envelope>';
xmlhttp := CoXMLHTTPRequest.Create;
//CreateObject("Microsoft.XMLHTTP");
// Open a connection and send a request to the server in the form of an XML fragment
xmlhttp.Open(bStrMethod, bstrUrl, varASync, bStrUser, bStrPassword);
xmlhttp.setRequestHeader('MethodName','get_all_cv');
xmlhttp.setRequestHeader('MessageType','Call');
xmlhttp.setRequestHeader('Content-Type','text/xml');
xmldoc:= CoDOMDocument.Create;
xmldoc.async:=false;
xmldoc.loadXML(s);
// Send the XML message to get_cv.asp
xmlhttp.send(xmlDoc.xml);
// Load the http response into g_xmlCBCV
g_xmlCBCV := CoDOMDocument.Create;
g_xmlCBCV.Async:=false;
g_xmlCBCV.loadXML(xmlhttp.responseText);
// Iterate through g_xmlCBCV extracting the employee names...
// ..then stick them in a listbox...
lbEmpName.Clear;
for i:=0 to g_xmlCBCV.documentElement.childNodes.length - 1 do
begin
nodeEmployee := g_xmlCBCV.documentElement.childnodes[i];
nodeMap := nodeEmployee.Attributes;
attrEmpName := nodeMap.getNamedItem('emp_name');
strEmpName := attrEmpName.Text;
nodeDetail := nodeEmployee.childNodes[i];
lbEmpName.Items.Add(strEmpName);
end;
end;
end.