代码拉取完成,页面将自动刷新
unit unChromeMessage;
interface
uses
Contnrs, uCEFChromium, Classes, utils_strings, SysUtils, Generics.Collections,
Windows, utils_dvalue, unConfig, Dialogs;
type
TWatchSubject = class(TObject)
public
listChome: TList<TChromium>;
// 注册消息监听
procedure attach(observer: TChromium);
procedure unAttach(observer: TChromium);
// 通知所有监听
procedure notifyAll(aMsg, aFrameName: string);
constructor Create; overload;
destructor Destroy; override;
end;
var
subject: TWatchSubject;
implementation
{ TSubject }
procedure TWatchSubject.attach(observer: TChromium);
var
iIndex: Integer;
begin
iIndex := listChome.IndexOf(observer);
if iIndex = -1 then
listChome.Add(observer);
end;
constructor TWatchSubject.Create;
begin
inherited;
listChome := TList<TChromium>.Create;
end;
destructor TWatchSubject.Destroy;
begin
listChome.Free;
inherited;
end;
procedure TWatchSubject.notifyAll(aMsg, aFrameName: string);
var
i: Integer;
observer: TChromium;
strFunc: string;
begin
aMsg := StringReplace(aMsg, '"', '\"', [rfReplaceAll]);
strFunc := 'if(window.onMsg) window.onMsg("' + aMsg + '")';
for i := 0 to listChome.Count - 1 do
begin
observer := listChome.Items[i];
observer.ExecuteJavaScript(strFunc,
observer.DocumentURL, aFrameName);
end;
end;
procedure TWatchSubject.unAttach(observer: TChromium);
var
iIndex: Integer;
begin
iIndex := listChome.IndexOf(observer);
if iIndex > -1 then
listChome.Delete(iIndex);
end;
initialization
subject := TWatchSubject.Create;
finalization
subject.Free;
end.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。