Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread undefined value from storage
Wed, May 1 2013 2:30 AMPermanent Link

Christian Kaufmann

I try to read a string from local storage. If it's not defined, ADefault should be returned. How do I have to check the Result on undefined value?

function BSGetLocalString(const AName: String; const ADefault: String = ''): String;
begin
 Result := window.localStorage.items[AName];
 if Result = 'undefined'
   then Result := ADefault;
end;

cu Christian
Wed, May 1 2013 5:09 AMPermanent Link

Matthew Jones

What I chose to do was have a value that shows if I have initialised the local
storage (saved anything).

szInitialiseCheck := Window.LocalStorage.GetItem('store_initialised');
if szInitialiseCheck = '1' then
begin
       // read the rest
end;

Given that the value won't be '1' if I didn't save it, then this works for me. It
would be good to have a better solution though. I think Tim said he was going to
enhance this at some point, not sure if it is for next update.

/Matthew Jones/
Fri, May 3 2013 9:46 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Christian,

<< I try to read a string from local storage. If it's not defined, ADefault
should be returned. How do I have to check the Result on undefined value? >>

Compare against nil:

var
  TempValue: String;
begin
  TempValue := window.localStorage.items['Test'];
  if (TempValue=nil) then
     ShowMessage('Not defined')
  else
     ShowMessage('Defined');
end;

Tim Young
Elevate Software
www.elevatesoft.com


Image