Load Method

<< Click to Display Table of Contents >>

Navigation:  Appendix > HTTP Interface >

Load Method

The method load is responsible to load documents and also images. For unsupported file extensions it calls MessageBeep and exits. It does not yet preload the data and check it for errors.

 

procedure TWPWebBrowser.Load(url: string; Update: Boolean);

var s: string;

 obj: TWPOImage;

 load_the_text: Boolean;

begin

 load_the_text := true;

 s := lowercase(ExtractFileExt(url));

if (s = '.rtf') or (s = '.txt') or (s = '.doc') then

begin

  // Standard Mode for Documents

   WPRichText1.AsWebpage := [];

end

else

if (s = '.jpg') or (s = '.gif') or (s = '.png') or (s = '.jpeg') then

begin

    // Mode for images

     obj := TWPOImage.Create(WPRichText1.RTFData);

    if obj.LoadHTTPFromThread(nil, WPRichText1.RTFData, WPRichText1.RTFData.HTTPPrepareURL(url), false) then

    begin

       WPRichText1.AsWebpage := [];

       WPRichText1.Clear;

       WPRichText1.InputObject(obj);

       load_the_text := false;

    end else

    begin

       obj.Free;

       MessageBeep(0);

       exit;

    end;

end

else // Ignore data right away

if (s = '.exe') or (s = '.zip') or (s = '.pdf')

    or (s = '.rar') or (s = '.chm') or (s = '.hlp')

then

begin // Unsupported extensions        

       MessageBeep(0);

       exit;

end

else

begin // Mode for websites        

      // TODO - we should load now preload the data and check if valid

       WPRichText1.AsWebpage := [wpFormatAsWebpage];

end;

// Update Statusbar

 URLEdit.Text := url;

 StatusBar1.Panels[1].Text := url;

  // Update History NOW - otherwise do_wphttp_Notify cannot update the filename correctly

if Update then

begin

  while history.Count > historypos do history.Delete(history.Count - 1);

   historypos := history.Count;

   history.Append(url);

   UpdateButtons;

end;

// Do we need to load text (maybe we loaded images)

if load_the_text then

begin

   WPRichText1.Clear;

   WPRichText1.LoadFromFile(url);

end;

end;

 

Notes:

Most of the work is done in WPRichText.LoadFromFile - here WPTools 8 detects http urls and uses the http functions to load the data.

 

Images are loaded multithreaded - so the page appears quickly.

 

The new TWPObject class implements the method LoadHTTPFromThread (it will not work with threads though, if the last parameter is false).

 

Here we also activate the special HTML formatting mode, or disable it for regular RTF documents.