MediaLibrary Delphi类型转换错误

MediaLibrary Delphi类型转换错误

问题描述:

我在Delphi上遇到MediaLibrary问题。MediaLibrary Delphi类型转换错误

我让下面这段代码我的主要形式:

unit uPrincipal; 

interface 

uses 
    System.SysUtils, System.Types, System.UITypes, System.Classes, 
    System.Variants,FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, 
    FMX.Dialogs, 
    FMX.Controls.Presentation, FMX.MultiView, FMX.Objects, FMX.Layouts, 
    FMX.StdCtrls, System.Actions, FMX.ActnList, FMX.StdActns, 
    FMX.MediaLibrary.Actions, FMX.MediaLibrary, FMX.Platform, System.Messaging; 

type 
    TfmPrincipal = class(TForm) 
    Layout1: TLayout; 
    mvMenu: TMultiView; 
    rctMenuPrincipal: TRectangle; 
    rctMenuTop: TRectangle; 
    rctMenuBody: TRectangle; 
    rctOpHome: TRectangle; 
    rctBodyPrincipal: TRectangle; 
    tbPrincipal: TToolBar; 
    StyleBook1: TStyleBook; 
    sbMenu: TSpeedButton; 
    sbPhoto: TSpeedButton; 
    ActionList1: TActionList; 
    TakePhotoFromLibraryAction1: TTakePhotoFromLibraryAction; 
    Image1: TImage; 
    TakePhotoFromCameraAction1: TTakePhotoFromCameraAction; 
    procedure TakePhotoFromLibraryAction1DidFinishTaking(Image: TBitmap); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

var 
    fmPrincipal: TfmPrincipal; 

implementation 

{$R *.fmx} 
{$R *.LgXhdpiPh.fmx ANDROID} 
{$R *.NmXhdpiPh.fmx ANDROID} 
{$R *.iPhone.fmx IOS} 

uses uLogin, uTeste; 

procedure TfmPrincipal.TakePhotoFromLibraryAction1DidFinishTaking(
    Image: TBitmap); 
begin 
    Image1.Bitmap.Assign(Image); 
end; 

end. 

当我我的手机上运行此,我点击SpeedButton的,我收到一个“无效类类型转换”的错误消息。

我在TActionList中加入了TakePhotoFromLibraryAction1,并将它设置为速度按钮的Action

我不知道为什么我得到这个错误。

这是您的Delphi版本中的一个错误。

一种解决方法是使用TButton而不是TSpeedButton

另一个解决方法是,以除去从SpeedButton的所述Action分配,然后使用该按钮的OnClick事件来调用该操作的ExecuteTarget()方法,传递不同的控制作为Target参数。