Since your main problem is update frequency, then you need to decrease it. For this you can simply store the last time you've updated the HTML document and at next data change check if a certain period elapsed since that time.
Here is the code that shows how to do this. The FUpdatePeriod
in the following example is the update period in milliseconds. Then if you call the UpdateChanges
periodically, the innerHTML
(pseudo-code here) will be updated only when at least 1000 ms elapsed since its last change.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MSHTML, OleCtrls, SHDocVw;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
procedure FormCreate(Sender: TObject);
private
FLastUpdate: Cardinal;
FUpdatePeriod: Cardinal;
procedure UpdateChanges(const AData: WideString);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FUpdatePeriod := 1000;
end;
procedure TForm1.UpdateChanges(const AData: WideString);
begin
if (GetTickCount - FLastUpdate > FUpdatePeriod) then
begin
(WebBrowser1.Document as IHTMLDocument2).body.innerHTML := AData;
FLastUpdate := GetTickCount;
end;
end;
// now remains to call the UpdateChanges periodically
end.