Optimize TWebBrowser coloring to reduce overall CPU usage

I have a form that has a component TWebBrowerthat loads an HTML document. The data in the HTML document is updated every few seconds, sometimes several times per second, and I update the value in Delphi using:

DOMDocument.getElementById(elementID).innerHTML := someValue;

The problem is that I want to block the / webbrowser window so that it does not draw / refresh until all my updates are complete. Is there any way to do this? There would be a challenge

SendMessage(WebBrowser.Handle,WM_SETREDRAW,0,0);

I would like to help optimize this code so that my overall CPU usage is not constantly high.

+5
source share
2 answers

- , . , HTML, , .

, , . FUpdatePeriod - . , UpdateChanges, innerHTML ( ) , 1000 .

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.
+4

; - TWebBrowser, , Google Chrome (DCEF), .

, "" TWebBrowser , , Internet Explorer. Internet Explorer JavaScript, - , HTML (100% javascript free = no flicker), Internet Explorer, , , TWebbrowser.

-, , - TWebBrowser Delphi javascript. , , TWebBrowser, javascript delphi. , ( ), .

+1

All Articles