Local Storage Demo 1

This simple Smart Pascal console demonstration shows you how to use a TW3LocalStorage object (from the SmartCL.Storage unit). Every time the program is run it saves a string which it then loads and outputs.

unit Unit1;

interface

uses 
  System.Types, System.Lists, SmartCL.System, SmartCL.Scroll, SmartCL.Console,
  SmartCL.Components, SmartCL.Application, SmartCL.ConsoleApp, SmartCL.Storage;

type
  TApplication = class(TW3CustomConsoleApplication)
  private
    FStorage: TW3LocalStorage;
  protected
    procedure ApplicationStarting; override;
    procedure PopulateConsole; override;
    procedure ApplicationClosing; override;
  end;

implementation

procedure TApplication.ApplicationStarting;
begin
  FStorage := TW3LocalStorage.Create;
  FStorage.Open('Demo1');
  FStorage.setKeyStr('myText', 'Saved string');
  inherited;
end;

procedure TApplication.PopulateConsole;
var
  s: String;
begin
  s := FStorage.getKeyStr('myText', 'error');
  Console.WriteLn(s);
end;

procedure TApplication.ApplicationClosing;
begin
  FStorage.Close;
  inherited;
end;

end.
    
Programming - a skill for life!

Storage and retrieval of data using local storage, cookies, HTTP and MySQL