Thursday, July 27, 2023

Displaying blog content within my blog manager (2)

In my last blog on this topic, from about five weeks ago, I wrote how I exported blogs that had been sent to me via Outlook to a text file containing HTML statements, and how I 'taught' the blog manager to display those text files within an internal web brower. Of the 1646 blogs to date, I must have connected about 800 files.

After another session of renumbering files the other day, I thought that it might be better if the text of these files were stored within a table inside the blog database. As I wrote then,

I spent a frustrating hour and a half trying to save html text to a new table; my guide was a question on Stack Exchange where someone asked how to save the text displayed within a web browser - not exactly my situation, but close. Big mistake. Eventually I realised that I was knocking my head against a brick wall, so I decided to take the dog for a walk.

Exporting the data from Outlook solved the 'saving html text' problem; a few days ago, I wondered whether I could load the text from these files into a table, then later retrieve that text and display it in a web browser without having to save it to a file then load that file. In a more lucid moment, I searched the web and came across this page with the following code:

uses ActiveX; procedure WB_LoadHTML(WebBrowser: TWebBrowser; HTMLCode: string); var sl: TStringList; ms: TMemoryStream; begin WebBrowser.Navigate('about:blank'); while WebBrowser.ReadyState < READYSTATE_INTERACTIVE do Application.ProcessMessages; if Assigned(WebBrowser.Document) then begin sl := TStringList.Create; try ms := TMemoryStream.Create; try sl.Text := HTMLCode; sl.SaveToStream(ms); ms.Seek(0, 0); (WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms)); finally ms.Free; end; finally sl.Free; end; end; end; procedure TForm1.Button1Click(Sender: TObject); begin WB_LoadHTML(WebBrowser1,'SwissDelphiCenter'); end;
Today I had the time to adapt this code to my blog manager and it worked successfully first time. I then spent some time uploading the 800+ files into a new table. I probably spent more time on the uploading code (checking that no source exists for a given blog, checking that a file exists with the correct number, etc) than I did on adapting the above code.

I made an approximate check as to whether any disk space has been saved: I compared the increase in size of the database file as opposed to the apparent size of the files. The rough answer was the same, but this doesn't take into account the space wasted in saving the files, what is termed the sector size. The database approach should save some room, although whether it works faster is another matter. Actually the speed doesn't really matter as frequently the code has to access the online Internet blog page where the pictures are stored, and this takes time.



This day in history:

Blog # Date Title Tags
185 27/07/2009 MBA MBA
389 27/07/2011 Masochistic programming Programming, Unicode
881 27/07/2015 Vinyl log 22 - 27 July Vinyl log, Fairport Convention, Jackson Browne
1057 27/07/2017 Sing Street Films, Swell Season
1157 27/07/2018 Careless love Literature, DCI Banks
1248 27/07/2019 10 years of post-graduate study DBA

No comments: