Einzelnen Beitrag anzeigen

QuickAndDirty

Registriert seit: 13. Jan 2004
Ort: Hamm(Westf)
1.883 Beiträge
 
Delphi 12 Athens
 
#2

AW: Share file via Provider

  Alt 25. Mär 2019, 15:13
OK, das Projekt sieht jetzt so aus:

Ich kann in
FSharingService.Share(TargetControl, TextMessage, Bitmap);
nicht rein debuggen. Hat dazu jemand ne idee?

ActionUnit
Delphi-Quellcode:
unit ShareFileAction;

interface
uses System.Classes, System.Actions, System.Messaging, FMX.Types, FMX.MediaLibrary, FMX.ActnList, FMX.StdActns, FMX.Consts,
     FMX.Graphics, FMX.Controls;

type


{ TShowShareSheetAction }

  TShowShareSheetAction = class(TSysCommonAction)
  strict private
    FSharingService: IFMXShareSheetActionsService;
    FBitmap: TBitmap;
    FMessage: string;
    FOnBeforeExecute: TNotifyEvent;
  private
    procedure SetBitmap(const Value: TBitmap);
  protected
    procedure DoBeforeExecute;
    procedure CustomTextChanged; override;
    function IsSupportedInterface: Boolean; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function HandlesTarget(Target: TObject): Boolean; override;
    procedure ExecuteTarget(Target: TObject); override;
  published
    property Bitmap: TBitmap read FBitmap write SetBitmap;
    property TextMessage: string read FMessage write FMessage;
    property OnBeforeExecute: TNotifyEvent read FOnBeforeExecute write FOnBeforeExecute;
  end;

implementation

uses
  System.SysUtils, FMX.Platform, System.Types;

constructor TShowShareSheetAction.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FMessage := '';
  FBitmap := TBitmap.Create(0, 0);
  TPlatformServices.Current.SupportsPlatformService(IFMXShareSheetActionsService, FSharingService);
end;

procedure TShowShareSheetAction.CustomTextChanged;
begin
  Text := GetDefaultText(SOpenStandartServices);
end;

destructor TShowShareSheetAction.Destroy;
begin
  FSharingService := nil;
  FreeAndNil(FBitmap);
  inherited Destroy;
end;

procedure TShowShareSheetAction.DoBeforeExecute;
begin
  if Assigned(FOnBeforeExecute) then
    FOnBeforeExecute(Self);
end;

procedure TShowShareSheetAction.ExecuteTarget(Target: TObject);
var
  TargetControl: TControl;
begin
  DoBeforeExecute;
  inherited ExecuteTarget(Target);
  if Target is TControl then
    TargetControl := TControl(Target)
  else if ActionComponent is TControl then
    TargetControl := TControl(ActionComponent)
  else
    TargetControl := nil;
  if (Bitmap <> nil) and (FSharingService <> nil) then
    FSharingService.Share(TargetControl, TextMessage, Bitmap);//<<<-------------- ICH WILL WISSEN WAS DA PASSIERT
end;

function TShowShareSheetAction.HandlesTarget(Target: TObject): Boolean;
begin
  Result := Supported;
end;

function TShowShareSheetAction.IsSupportedInterface: Boolean;
begin
  Result := FSharingService <> nil;
end;

procedure TShowShareSheetAction.SetBitmap(const Value: TBitmap);
begin
  FBitmap.Assign(Value);
end;

end.
Formular unit
Delphi-Quellcode:
unit ShareFileForm;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Actions,
  FMX.ActnList, FMX.Controls.Presentation, FMX.StdCtrls,
  FMX.StdActns, ioutils, FMX.MediaLibrary.Actions,ShareFileAction ;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ActionList1: TActionList;
    procedure ShowShareSheetAction1BeforeExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    ShowShareSheetAction1: TShowShareSheetAction;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

Const Loremipsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ultricies sem a feugiat vulputate.'+
                   ' Nam euismod vitae nibh pulvinar ornare. Aliquam in tincidunt eros, eu viverra mi. Proin rutrum '+
                   'faucibus turpis vel pulvinar. Maecenas a mauris ac lectus feugiat dictum. Vestibulum mollis purus'+
                   ' quis massa finibus, non pellentesque lorem porta. Maecenas ullamcorper eleifend justo, et suscipit'+
                   ' ligula consectetur tincidunt. Fusce ut egestas ligula. In malesuada venenatis dui, et aliquet sem'+
                   ' hendrerit in. Nulla metus risus, laoreet vel ornare id, condimentum nec mauris. Vestibulum nibh urna,'+
                   ' pellentesque non semper non, condimentum sed mi. Nunc non justo et ante finibus euismod. Nunc nulla ante,'+
                   ' hendrerit ut pulvinar scelerisque, sollicitudin at tellus. Integer accumsan eu arcu in luctus.'+
                   ' In eros leo, convallis non ullamcorper nec, convallis eu augue.';

procedure TForm1.FormCreate(Sender: TObject);
begin
  ShowShareSheetAction1 := TShowShareSheetAction.Create(self);
  ShowShareSheetAction1.OnBeforeExecute := ShowShareSheetAction1BeforeExecute;
  Button1.Action := ShowShareSheetAction1;
end;

procedure TForm1.ShowShareSheetAction1BeforeExecute(Sender: TObject);
var fLogFile:String;
begin
{$IFDEF ANDROID}
  fLogFile := TPath.Combine(TPath.GetHomePath, 'Testfile.log' );
{$ENDIF}
{$IFDEF IOS}
  fLogFile := TPath.Combine(TPath.GetDocumentsPath, 'Testfile.log' );
{$ENDIF}
{$IFDEF WIN32}
  fLogFile := TPath.Combine(TPath.GetDirectoryName(paramstr(0)), TPATH.GetFileNameWithoutExtension(paramstr(0)) +'.log' );
{$ENDIF}
  TFile.WriteAllText( fLogFile, Loremipsum, TEncoding.UTF8);
  ShowShareSheetAction1.TextMessage := Loremipsum;
end;

end.
Andreas
Monads? Wtf are Monads?
  Mit Zitat antworten Zitat