Icon Detecting Local Storage Changes

You can assign an event handler to the TPersistentStorage OnChange event to detect when another session modifies any data saved in local (not per-session) storage. The following example shows how to assign a form method (event handler) to the OnChange event for the global LocalStorage instance of the TPersistentStorage class in order to detect when any other session modifies a user's display preferences in local (not per-session) storage:

uses WebCore, WebComps;

procedure TForm1.StorageChange(Sender: TObject; const Key: String;
                               const NewValue: String; const OldValue: String;
                               const URL: String);
begin
   if (Key='') or (Key='DisplayPrefs') then
      LoadDisplayPrefs;
end;

procedure TForm1.Form1Create(Sender: TObject);
begin
   DisplayPrefs:=TStringList.Create;
   LocalStorage.OnChange:=StorageChange;
end;

procedure TForm1.Form1Destroy(Sender: TObject);
begin
   LocalStorage.OnChange:=nil;
   DisplayPrefs.Free;
   DisplayPrefs:=nil;
end;

procedure TForm1.InitDisplayPrefs;
begin
   with DisplayPrefs do
      begin
      Clear;
      Values['ShowMainMenu']:='True';
      Values['ShowToolBar']:='True';      
      end;
end;

procedure TForm1.SaveDisplayPrefs;
begin
   LocalStorage.Set('DisplayPrefs',DisplayPrefs.Text);
end;

procedure TForm1.LoadDisplayPrefs;
begin
   if LocalStorage.Exists('DisplayPrefs') then
      DisplayPrefs.Text:=LocalStorage['DisplayPrefs']
   else
      InitDisplayPrefs;
end;

Information The above code is not complete and is only a cut-down example to illustrate the specific local storage concepts discussed here.
Image