How to read text files online?

Asked

Viewed 688 times

1

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

I know this is possible because I’ve seen, the question is, "How?"

I imagine the component is used TidHTTP.

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

1 answer

2


You don’t need to use the TidHTTP, you can use a simpler component, the TWebBrowser.

Create a Private Variable (Browser : TWebBrowser;) and in the Create of your form you load the page with the text file, follow example of loading and creation of Webbrowser at runtime!

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

Note that I created a Webbrowser (Browser) of the type Self, so he doesn’t need to be visible!

Now just charge the TMemo with the information:

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

Important: You should not call the procedure Oleobject.Document.Body in the same event where this Navigate procedure, this generates access violation, ie, you would be trying to get information that has not yet been created! Because, there is a delay, even if small between browsing and downloading the page, take advantage and expand your search on the Webbrowser, had found an event called Documentcomplete that had greatly helped in his future projects with this component!

  • Thank you, give me a shot on my question!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.