How to read text files online?

1

I have a project done in Delphi and at a certain time it should read a text file that is hosted on a website, however, I want this reading to be done online through a TMemo without there being any a download of the file being read in question!

I know this is possible as I have seen, the question is: "How?"

I imagine using the TidHTTP component.

Example of how the file is hosted: " www.example.com/file ".

    
asked by anonymous 22.02.2016 / 03:18

1 answer

2

You do not need to use TidHTTP , you can use a simpler component, TWebBrowser .

Create a variable in the Private ( Browser : TWebBrowser; ) and in the Create of your form you load the page with the text file, follow example of loading and creating WebBrowser at run time! / p>

  Browser := TWebBrowser.Create(Self);
  Browser.Navigate('http://websitetips.com/articles/copy/lorem/ipsum.txt');

Note that I created a WebBrowser (browser) of type Self , so it does not have to be visible!

Now just load TMemo with the information:

Memo1.Lines.Add(Browser.OleObject.Document.Body.InnerText);
  

Important: You should not call the OleObject.Document.Body procedure in the same event where the Navigate procedure is, this generates access violation, ie you would be trying to get information that you do not already have was raised! Well, there is a delay, even if small between browsing and downloading the page, enjoy and expand your WebBrowser search, you will find an event called DocumentComplete that will greatly help your futurus projects with this component!

    
24.02.2016 / 12:27