What unit should I add when using localStorage?

TWebLocalStorage;
TLocalStorage;
TCookies;

efer to 329page Example:

uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, Vcl.Controls, Vcl.StdCtrls, WEBLib.StdCtrls;

procedure TForm1.WebButton1Click(Sender: TObject);
var
LLocalStorage: TWebLocalStorage;
begin
LLocalStorage := TWebLocalStorage.Create;
LLocalStorage.Values['mykeyname'] := 'myvalue';
LLocalStorage.Free;
//
end;

procedure TForm1.WebButton2Click(Sender: TObject);
var
ls: TLocalStorage;
begin
ls := TLocalStorage.Create;
ls.Values[PersistTokens.Key] := 'YourAccessToken';
ls.Free;
end;

procedure TForm1.WebButton3Click(Sender: TObject);
var
cookies: TCookies;
v: string;
begin
cookies := TCookies.Create;
cookies.Add(Name, Value);
v := cookies.Find(Name).Value;
cookies.Free;begin
end;

What's missing?

WEBLib.Storage and WEBLib.Cookies should do...

EdB

Mr.Ed Blanchard

Thank you, but it didn't work

It would be helpful if I had a simple sample code.

Please define "it didn't work"

Mr.Bruno Fierens TMS Support
Thank you
Yes i will do so

Create a new TMS Web Application "Project1"

Drop one TWebEdit and three TWebButtons on the form (btnLoad, btnSave and btnClear).

unit Unit2;

interface

uses
  System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
  WEBLib.Forms, WEBLib.Dialogs, Vcl.StdCtrls, WEBLib.StdCtrls, Vcl.Controls, 
  WEBLIB.Storage;


  CONST
     STANDARD_KEY = 'MYKEY';


type
  TForm2 = class(TWebForm)
    WebEdit1: TWebEdit;
    btnLoad: TWebButton;
    btnSave: TWebButton;
    btnClear: TWebButton;
    procedure btnLoadClick(Sender: TObject);
    procedure btnSaveClick(Sender: TObject);
    procedure btnClearClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}
procedure ClearMyToken;
var
  ls: TLocalStorage;
begin
  ls := TLocalStorage.Create;
  try
    ls.RemoveKey(STANDARD_KEY);
  finally
    ls.free;
  end;
end;

function GetMyToken: string;
var
  ls: TLocalStorage;
begin
  result:='';
  ls := TLocalStorage.Create;
  try
    result:=ls.GetValue(STANDARD_KEY);
  finally
    ls.free;
  end;
end;

procedure SetMyToken(const value: string);
var
  ls: TLocalStorage;
begin
//  ClearMyToken; // clear it first - not strictly necessary
  ls := TLocalStorage.Create;
  try
    ls.SetValue(STANDARD_KEY, Value);
  finally
    ls.free;
  end;
end;

procedure TForm2.btnClearClick(Sender: TObject);
begin
  ClearMyToken;
end;

procedure TForm2.btnLoadClick(Sender: TObject);
begin
  WebEdit1.Text:=GetMyToken;
end;

procedure TForm2.btnSaveClick(Sender: TObject);
begin
  SetMyToken(webEdit1.Text);
end;

end.

Things to try:

Run the project in a browser - say, FireFox:

  • click on "load" - no results
  • enter a value in the webEdit and click save
  • close browser, reopen browser and click load - your value appears in webEdit.

Open a different browser -say, Chrome - and copy url from first browser to run project

Click load - note that webEdit does NOT contain your original value

That's something I missed first time around: TLocalStorage is specific to the browser that saves the data.

HTH

Mr. Ed Blanchard
Thank you
It worked


At the end of, there is now an empty frame
Can I post this code here if you like?

I'm sorry - I'm not sure if you are asking to post code so we can look to solve a problem, or if you are offering to show the forum the code in case anyone would like to see it.

If you need help with a problem, we need to understand what the issue is first.

Mr. Ed Blanchard
Thank you
I'm sorry I'm lacking in English
Thank you very much for the sample code
If the number of WebCORE users increases in Japan and a little,


I wrote it in.

We are looking forward to hearing from you