delphi 读取网上的文本文件


第一步: 先把文本文件虚拟成一个 XML 文件, 譬如:
<?xml version="1.0" encoding="gb2312"?>
<txt>
这是文本内容
</txt>


--------------------------------------------------------------------------------

第二步: 传到网上, 譬如我是放在: http://www.3464.com/down/test.txt
--------------------------------------------------------------------------------

第三步: 用 TXMLDocument 控件读取, 只需要两行代码:
--------------------------------------------------------------------------------

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, ExtCtrls;

type
TForm1 = class(TForm)
XMLDocument1: TXMLDocument;
procedure FormCreate(Sender: TObject);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
XMLDocument1.LoadFromFile('http://www.132435.com/down/test.txt');
ShowMessage(XMLDocument1.DocumentElement.ChildNodes[0].Text);
end;

end.


联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678