Notice

The forum is in read only mode.

  • Page:
  • 1

TOPIC: SaveState Problem

SaveState Problem 7 years 1 month ago #2113

I am baffled. This worked in XE7 but not in XE8. I put together a quick Android app that simply calls SaveFormState when the user hits the hardware back button and then reloads the state in FormCreate. It doesn't work in the FormSaveState either but this was a quick test. Can someone show me where I have gone wrong? When reading back in the file exists but it always has a size of 0. Thanks.
procedure TForm1.FormCreate(Sender: TObject);
begin
  SaveState.StoragePath := TPath.GetHomePath;
  LoadFormState;
end;

procedure TForm1.SaveFormState;
var
  s: string;
  W: TBinaryWriter;
begin
  s := 'Save state test';
  W := TBinaryWriter.Create(SaveState.Stream);
  try
    W.Write(S);
  finally
    W.Free;
  end;
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
begin
  if Key = vkHardwareBack then
  begin
    SaveFormState;
    MainActivity.finish;
  end;
end;

procedure TForm1.LoadFormState;
var
  s: string;
  R: TBinaryReader;
begin
  s := 'blank';
  if SaveState.Stream.Size > 0 then  //always is zero!
  begin
    R := TBinaryReader.Create(SaveState.Stream);
    try
      s := R.ReadString;
    finally
      R.Free;
    end;
  end;

  memo1.Lines.Add(s);
end;
  • Page:
  • 1
Moderators: April Anne