4

On my program I have a function that checks for the current version of the program, which it gets from the url: www.tablemaster.webs.com/versioninfo.txt

As you can see, at the URL is just plain text. I need to load this text from the URL into a string on my program, how will I go about doing this? I've searched around but found nothing..

PS: I need the simplest code possible..

Thanks in advance :)

MPelletier
  • 16,256
  • 15
  • 86
  • 137
James
  • 133
  • 2
  • 3
  • 9
  • 3
    This is almost certainly a duplicate. – Andreas Rejbrand Jun 26 '12 at 16:18
  • It helps if you show how you're getting the text from the URL in the first place, so we know where we're starting; it helps you get where you're going. :-) – Ken White Jun 26 '12 at 17:03
  • 1
    possible duplicate of [delphi 7 http request into string](http://stackoverflow.com/questions/4092209/delphi-7-http-request-into-string) – Warren P Jun 27 '12 at 00:17
  • accepted answer here has function WebGetData that seems apropos: http://stackoverflow.com/questions/2977720/how-to-send-a-http-post-request-in-delphi-2010-using-wininet/2977783#2977783 – Warren P Jun 27 '12 at 00:19

4 Answers4

24

I would use Indy's TIdHTTP with it's easiest GET overload this way:

uses
  IdHTTP;

procedure TForm1.Button1Click(Sender: TObject);
var
  S: string;
  IdHTTP: TIdHTTP;
begin
  IdHTTP := TIdHTTP.Create(nil);
  try
    S := IdHTTP.Get('http://www.tablemaster.webs.com/versioninfo.txt');
    ShowMessage(S);
  finally
    IdHTTP.Free;
  end;
end;
TLama
  • 75,147
  • 17
  • 214
  • 392
2

you can use TIEHTTP component from myfxboard.. to load txt file from url with TIEHTTP:

http.ExecuteURL('www.tablemaster.webs.com/versioninfo.txt');
Memo1.Lines.Add(http.sl.Text);
S.FATEH
  • 451
  • 8
  • 16
1

I would use MSXML2_TLB, especially if I already use XML in the project. MSXML2 is present in Windows since version Internet Explorer 5.5, so chances are real good it's present on the system. You can get MSXML2_TLB.pas using the Import Type Library option from the main menu, and selecting "Microsoft XML, v6.0" (or higher) from the list.

var
  r:XMLHTTP;
begin
  r:=CoXMLHTTP.Create;
  r.open('GET','http://www.tablemaster.webs.com/versioninfo.txt','','');
  r.send(EmptyParam);
  if r.status<>200 then raise Exception.Create(IntToStr(r.status)+' '+r.statusText);
  Result:=r.responseText;
end;
Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67
  • Interesting alternative though, but I've tried to import the type library on Windows 7 with Delphi 2009 and there are only `CoXMLHTTP40` or `CoXMLHTTP60` classes. There's no `CoXMLHTTP`. And also the `XMLHTTP` interface looks quite strange, shouldn't it begin with `I` ? – TLama Jun 26 '12 at 18:26
  • Details like this may indeed change a little between Windows and Delphi versions. 'OLE Class' XMLHTTP doesn't start with I, objects from that class 'expose' the IXMLHTTPRequest interface and perhaps others. It's similar and stems from antique COM/OLE theory, in practice you'll find in the TLB unit that they're equal to eachother and can be used interchangably. – Stijn Sanders Jun 26 '12 at 20:17
0

uses IdHTTP;

procedure TForm1.Button1Click(Sender: TObject); var . .

it seems in this method system cached the txt file so if the file change on web this method denies changes.!

Reza k
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 30 '22 at 20:07