首页 文章

MediaLibrary Delphi类型转换错误

提问于
浏览
0

我在Delphi上的MediaLibrary有问题 .

我在我的主表单上创建了以下代码:

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 ,并将其设置为SpeedButton的 Action .

我不知道为什么我会收到这个错误 .

1 回答

  • 2

    这是你的Delphi版本中的一个错误 .

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

    另一种解决方法是从SpeedButton中删除 Action 赋值,然后使用按钮的 OnClick 事件来调用操作的 ExecuteTarget() 方法,并将其作为 Target 参数传递给另一个控件 .

相关问题