mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-19 11:09:22 +02:00
* Demo for storage
This commit is contained in:
parent
0228a24ce5
commit
17ae93f916
57
packages/wasm-utils/demo/storage/demostorage.lpi
Normal file
57
packages/wasm-utils/demo/storage/demostorage.lpi
Normal file
@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="demostorage"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="demostorage.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<Target>
|
||||
<Filename Value="demostorage.wasm" ApplyConventions="False"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<OtherUnitFiles Value="../../src"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
42
packages/wasm-utils/demo/storage/demostorage.lpr
Normal file
42
packages/wasm-utils/demo/storage/demostorage.lpr
Normal file
@ -0,0 +1,42 @@
|
||||
program demostorage;
|
||||
|
||||
{$mode objfpc}
|
||||
{$h+}
|
||||
|
||||
uses wasm.storage.objects;
|
||||
|
||||
procedure DumpKeys(aStorage : TWasmStorage);
|
||||
|
||||
var
|
||||
I,lCount : Integer;
|
||||
lKey,lValue : UTF8String;
|
||||
|
||||
begin
|
||||
lCount:=aStorage.Count;
|
||||
Writeln('Have ',lCount,' keys');
|
||||
For I:=0 to lCount-1 do
|
||||
begin
|
||||
lKey:=aStorage.Keys[i];
|
||||
lValue:=aStorage.Items[lKey];
|
||||
Writeln('[',I,'] ',lKey,' = "',lValue,'"');
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
lStorage : TWasmLocalStorage;
|
||||
lKey,lValue : UTF8String;
|
||||
|
||||
begin
|
||||
lStorage:=TWasmLocalStorage.Create;
|
||||
Writeln('Existing keys at start: ');
|
||||
DumpKeys(lStorage);
|
||||
Writeln('Setting key "xyz" to value "123"');
|
||||
lStorage.Items['xyz']:='123';
|
||||
Writeln('Retrieving value of key "xyz" : "',lStorage.Items['xyz'],'"');
|
||||
Writeln('Deleting key "xyz"');
|
||||
lStorage.Remove('xyz');
|
||||
Writeln('Retrieving value of key "xyz" (again): "',lStorage.Items['xyz'],'"');
|
||||
Writeln('Existing keys at end: ');
|
||||
DumpKeys(lStorage);
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user