Jump to content
COMFIED

Save Content Dialog

Recommended Posts

hmmm, not sure if SMS has FileSystem procedures yet......besides that could be a mess if you are developing for multiple device platforms

Dont you just want to save the memo contents to local storage?

if so,  then you have a few options - since you only then have to worry about the name and not the location

You could build your own dialog using TW3Dialog from SmartCL.Dialogs unit

or use the following function from the SmartCL.System unit

function w3_Prompt(aText: String; aDefault: String = ''): String;

e.g.

 DataName:= w3_Prompt(DataName', 'Uknown');

 

LocalStorage.setKeyStr('Data', DataName);

Share this post


Link to post
Share on other sites

Hi IElite

I have built a reporting app using SMS, running on Microsoft Windows 10, and the idea is to save the report as a external file into a Windows folder (with human selection of filename and destination).

Is this possible?

Share this post


Link to post
Share on other sites

Edited

If you're running a project in the browser, it is not possible to save files to the local harddrive.

The easiest work-arounds :

- use local storage. This is a browser function which lets you store key-value pairs, and it is persistent. Caveats of course are that storage capacity is limited, storage is specific to the protocol of the page, data stored when in stealth mode will be deleted after exiting from stealth mode  (and is maybe even browser vendor specific ?) and data gets formatted as strings.

Might be ok for your purposes though ...

procedure TForm1.W3Button2Click(Sender: TObject);
begin
  // Retrieve
  Memo1.Text := browserapi.window.localStorage.getItem("lastname");
end;

procedure TForm1.W3Button1Click(Sender: TObject);
begin
  // Store
  browserapi.window.localStorage.setItem("lastname", "Smith");
end;

- use session storage instead of local storage if you don't want to hang on to data longer than current session

- use cookies. An old feature to basically do something like local storage.

- use a server. Uploading files to a php or node server is pretty straight forward. You'll need access to a server though

- exit the browser and produce a native app

 

Share this post


Link to post
Share on other sites

sorry, code example local storage was not quite right

procedure TForm1.W3Button2Click(Sender: TObject);
begin
  // Retrieve
  Memo1.Text := browserapi.window.localStorage.getItem("lastname");
end;

procedure TForm1.W3Button1Click(Sender: TObject);
begin
  // Store
  browserapi.window.localStorage.setItem("lastname", "Smith");
end;

this works better.

Or the slightly longer version using SmartCL.Storage.Local

unit Form1;

interface

uses 
  System.Types,
  System.Types.Convert,
  System.Objects,
  System.Time,
  SmartCL.System,
  SmartCL.Time,
  SmartCL.Graphics,
  SmartCL.Components,
  SmartCL.FileUtils,
  SmartCL.Forms,
  SmartCL.Fonts,
  SmartCL.Theme,
  SmartCL.Borders,
  SmartCL.Application,
  SmartCL.Storage.Local, SmartCL.Controls.Memo, SmartCL.Controls.Button;

type
  TForm1 = class(TW3Form)
    procedure W3Button2Click(Sender: TObject);
    procedure W3Button1Click(Sender: TObject);
  private
    {$I 'Form1:intf'}
  protected
    procedure InitializeForm; override;
    procedure InitializeObject; override;
    procedure Resize; override;
    LocalStorage : TW3LocalStorage;
  end;

implementation

{ TForm1 }

procedure TForm1.W3Button2Click(Sender: TObject);
begin
  LocalStorage.Open('aaa');
  W3Memo1.Text := LocalStorage.GetKeyStr('businessname','unknown');
  LocalStorage.Close;
end;

procedure TForm1.W3Button1Click(Sender: TObject);
begin
  LocalStorage.Open('aaa');
  LocalStorage.SetKeyStr('businessname','lynkfs');
  LocalStorage.Close;
end;

procedure TForm1.InitializeObject;
begin
  inherited;
  {$I 'Form1:impl'}
  LocalStorage := TW3LocalStorage.Create;
end;


 

 

 

Share this post


Link to post
Share on other sites

The node filesystem is wrapped. But right now im implementing filesystem classes, meaning that we will have a unified solution for this.
Since storage is so different between node, browser, phonegap and various embedded hardware - it makes sense to create some "driver" like classes that expose a common interface.

As for the filesystem units. The System.Filesystem.pas file is presently used by node.js only, but it will be absorbed by the drivers soon.

The Filesystem.Memory unit is a fully working filesystem for a "ram disk". That you can also save to the cache. It gives you things like chdir, mkdir, dir, paths etc. etc. for a in-memory device. Then you can save the data to the cache. So this is the "driver" for the browser so to speak.

A identical class is being written for nodejs. Both will be async (!) So heads up on that!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×