Jump to content
grantful

Send sqlite database file with share sheet on IOS and Android

Recommended Posts

I have a sqlite database file( app.s3db)  in my app i wold like to send with share sheet to back up to email ,etc .

 

I am working on a class to do this but have an error.

 

unit ShareDatabaseFile;

interface

uses
  System.SysUtils, System.Classes, FMX.Types, FMX.Controls,
  FMX.MediaLibrary.Actions, FMX.Dialogs, FMX.ActnList;

type
  TDatabaseFileSharer = class(TComponent)
  private
    FShareSheet: TShowShareSheetAction;
    FActionList: TActionList;
    procedure DoBeforeExecute(Sender: TObject); // Declaration
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure ShareDatabaseFile;
  end;

implementation

uses
  System.IOUtils;

{ TDatabaseFileSharer }

constructor TDatabaseFileSharer.Create(AOwner: TComponent);
begin
  inherited;
  FActionList := TActionList.Create(Self);

  FShareSheet := TShowShareSheetAction.Create(Self);
  FShareSheet.ActionList := FActionList;
  FShareSheet.OnBeforeExecute := DoBeforeExecute;  // Assignment
end;

destructor TDatabaseFileSharer.Destroy;
begin
  FShareSheet.Free;
  FActionList.Free;
  inherited;
end;

procedure TDatabaseFileSharer.DoBeforeExecute(Sender: TObject);  // Implementation
var
  DatabaseFilePath: string;
begin
  DatabaseFilePath := TPath.Combine(TPath.GetDocumentsPath, 'mydatabase.db');
  if TFile.Exists(DatabaseFilePath) then
  begin
    FShareSheet.SharedFileName := DatabaseFilePath;

  end
  else
  begin
    ShowMessage('Database file not found.');
    Abort;
  end;
end;

procedure TDatabaseFileSharer.ShareDatabaseFile;
begin
  FShareSheet.ExecuteTarget(nil);
end;

end.

 I am getting undeclared identifier

 

procedure TDatabaseFileSharer.DoBeforeExecute(Sender: TObject);  // Implementation
var
  DatabaseFilePath: string;
begin
  DatabaseFilePath := TPath.Combine(TPath.GetDocumentsPath, 'mydatabase.db');
  if TFile.Exists(DatabaseFilePath) then
  begin
    FShareSheet.SharedFileName := DatabaseFilePath;

  end
  else
  begin
    ShowMessage('Database file not found.');
    Abort;
  end;
end;

here is the error  FShareSheet.SharedFileName is the undeclared identifier. 

 

so the .sharedFileName is the issue.

 

i am looking in the FMX.MediaLibrary.Actions and can not see anything about the shared file name.

 

 

 

Thanks for any help.

Share this post


Link to post
6 minutes ago, grantful said:

here is the error  FShareSheet.SharedFileName is the undeclared identifier. 

 

so the .sharedFileName is the issue.

 

i am looking in the FMX.MediaLibrary.Actions and can not see anything about the shared file name.

Where did you have the idea that SharedFileName was a property of TShowShareSheetAction? This class supports sharing only images and text.

 

If you want to share a file, you may be interested in this: https://github.com/DelphiWorlds/Kastri/tree/master/Demos/ShareItems

Share this post


Link to post

Dave that works great.

I am wondering about using a 3rd party method(component, pas, class, etc) in the app. I worried about in the future if the Kastri project will be updated to work with newer versions of Delphi .

Thanks for your help

Share this post


Link to post
40 minutes ago, grantful said:

I worried about in the future if the Kastri project will be updated to work with newer versions of Delphi .

I have kept Kastri very much up to date, and I "officially" support the last 2 major updates, i.e. presently 10.4.x and 11.x.  Rest assured that the same will apply to Delphi 12.

  • Like 1

Share this post


Link to post

Hey Dave I compiled the demo and it works great .

 

I am trying to implement the share into my project and i am getting

[DCC Error] Macapi.ObjectiveC.pas(3145): E2003 Undeclared identifier: 'SObjCClassRegistrationFailed'

I have looked at the uses clause in the demo and I have the same  thing in mine.  I am sure i am not including something.

 

Thanks for your help.

Share this post


Link to post
29 minutes ago, grantful said:

I have looked at the uses clause in the demo and I have the same  thing in mine.  I am sure i am not including something.

Your project appears to include a folder in its search path that contains the file Macapi.ObjectiveC.pas, which by default is in the source\rtl\osx folder in the Delphi install, but perhaps you have a copy of the file elsewhere. The fact that it reports: Undeclared identifier: 'SObjCClassRegistrationFailed' means that there's a mismatch between the Macapi.ObjectiveC.pas it finds, and the System.RTL.Consts unit, which contains the missing identifier.

Share this post


Link to post

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

×