Saving and Loading a Memo's Text

This demonstration has a memo with a vertical scrollbar that shows when necessary. The first time you run it in a browser it saves a little text which you can replace with your own text to save. The next time you run the program in the same browser you will see your stored text in the memo. If the program does not work in your current browser, try another such as Chrome, Firefox, Safari or Opera.

The Smart Pascal code of the main unit and the XML code of the form follow the demonstration. If you see no display at school, the security system might have blocked it. You can try instead this direct link to the program running on its own page.

Demonstration

MemoDemo.html

Smart Pascal Code of Main Unit

unit Form1;

interface

uses 
  SmartCL.System, SmartCL.Graphics, SmartCL.Components, SmartCL.Forms, 
  SmartCL.Fonts, SmartCL.Borders, SmartCL.Application, SmartCL.Controls.Memo,
  SmartCL.Storage, SmartCL.Controls.Button;

type
  TForm1 = class(TW3Form)
    procedure btnSaveClick(Sender: TObject);
  private
    {$I 'Form1:intf'}
    FStorage: TW3LocalStorage;
    memoText := 'Type here and press the save button when finished.';
  protected
    procedure InitializeForm; override;
    procedure InitializeObject; override;
  end;

implementation

procedure TForm1.btnSaveClick(Sender: TObject);
begin
  FStorage.setKeyStr('MemoStr', W3Memo1.text);
end;

procedure TForm1.InitializeForm;
begin
  inherited;
  FStorage := TW3LocalStorage.Create;
  FStorage.Open('MemoDemo');
  W3Memo1.Text := memoText;
  var s := FStorage.getKeyStr('MemoStr', 'error');
  if s = 'error' then
    begin
      FStorage.setKeyStr('MemoStr', memoText);
    end
  else
    begin
      W3Memo1.Text := s;
    end;
end;

procedure TForm1.InitializeObject;
begin
  inherited;
  {$I 'Form1:impl'}
  W3Memo1.ScrollH := soNone;
  W3Memo1.ScrollV := soAuto;
end;
 
initialization
  Forms.RegisterForm({$I %FILE%}, TForm1);
end.

XML Code of Form

<SMART>
  <Form version="2" subversion="1">
    <Created>2014-10-26T15:05:18.471</Created>
    <Modified>2014-10-26T16:23:21.034</Modified>
    <object type="TW3Form">
      <Caption>W3Form</Caption>
      <Name>Form1</Name>
      <object type="TW3Memo">
        <Text>W3Memo</Text>
        <Width>232</Width>
        <Top>16</Top>
        <Left>8</Left>
        <Height>64</Height>
        <Name>W3Memo1</Name>
      </object>
      <object type="TW3Button">
        <Caption>Save</Caption>
        <Width>128</Width>
        <Top>88</Top>
        <Left>56</Left>
        <Height>32</Height>
        <Name>btnSave</Name>
        <OnClick>btnSaveClick</OnClick>
      </object>
    </object>
  </Form>
</SMART>
Programming - a skill for life!

How to use a range of visual components such as edit boxes, combo boxes, grids and charts on one or multiple forms (including a modal form)