Unit Initialization

<< Click to Display Table of Contents >>

Navigation:  Appendix > HTTP Interface >

Unit Initialization

To update the status bar we need to create a global method. This method will be called when data is loaded over HTTP connections. It also initializes a timer on the form to update the screen and to clear the status bar.

 

procedure do_wphttp_Notify(code: Integer; text: PAnsiChar); stdcall;

begin

if WPWebBrowser <> nil then

begin

  if code = 1 then //Load HTML

  begin

     WPWebBrowser.StatusBar1.Panels[1].Text := StrPas(text);

    if WPWebBrowser.historypos < WPWebBrowser.history.count then

       WPWebBrowser.history[WPWebBrowser.historypos] := StrPas(text);

  end

  else if code = 2 then // Called Synchronized !

  begin

     WPWebBrowser.StatusBar1.Panels[2].Text := StrPas(text);

     WPWebBrowser.UpdateScreenTimer.Enabled := TRUE;

     WPWebBrowser.pendingload := TRUE;

  end;

end;

end;

 

This is the timer method

 

procedure TWPWebBrowser.UpdateScreenTimerTimer(Sender: TObject);

begin

if not pendingload then

begin

   WPWebBrowser.StatusBar1.Panels[2].Text := '';

   UpdateScreenTimer.Enabled := FALSE;

end;

 WPRichText1.Repaint;

 pendingload := FALSE;

end;

 

 

The method do_wphttpNotify and the 4 methods from unit wphttpget_unit are attached to the WPTools engine using function pointers. The pointers are set in the initialization section of the unit:

 

initialization

 

// HTTP functions

 WPRTEDefs.wphttp_Init := @wphttpget_unit.wphttp_Init;

 WPRTEDefs.wphttp_Exit := @wphttpget_unit.wphttp_Exit;

 WPRTEDefs.wphttp_get := @wphttpget_unit.wphttp_get;

 WPRTEDefs.wphttp_copydata := @wphttpget_unit.wphttp_copydata;

 wphttp_Init_param := 'WPCubed_GmbH_HTTP1';

 

// Also initialize wphttp_Notify

 WPRTEDefs.wphttp_Notify := do_wphttp_Notify;

 

end.