0
votes

I trying to use the camera in a small app but getting this error:

Error: Invalid Class Typecast

What I did is:

  • New multi device application
  • Action list Component
  • TakePhotoFromCameraAction1 added to Actionlist
  • one button with action connected to TakePhotoFromCameraAction1

Run 64 bit IOS9 Ipad Error

Run 32 bit IOS9 Ipad Error

It looks like the error is coming in this function FMX.MediaLibrary.Actions().

procedure TTakePhotoFromCameraAction.ExecuteTarget(Target: TObject);
begin
  if IsSupportedInterface then // This line create the error
    FCameraService.TakePhoto(Target as TControl, GetParamsPhotoQuery);
end;

Any idea?

2

2 Answers

1
votes

I send it to Embacadero support as a case , and it is a bug.

Answear and hotfix below


The invalid typecast looks to stem from the fact that you are using a TSpeedButton. The TakePhotoFromLibraryAction will work if you use a TButton. The problem happens in TTakePhotoFromLibraryAction.ExecuteTarget where the Target is passed as a TObject. The debugger therefore doesn't give any clue as to what class the target is but it presumbably is not a descendent of TControl which is what it needs to be if the cast is to succeed.

I shall log a bug for this but in the meantime, I suggest that you use a TButton to call this action.

-1
votes
  • My TSpeedButton sits on on TListbox item.
  • I encountered the Invalid Class Typecast error
  • I changed TSpeedButton to TButton type. But the error still returns if you accidentally click on the list item and not the TButton.
  • Eventually i switched my code from ActionList to this approach:

http://docwiki.embarcadero.com/RADStudio/XE8/en/Taking_Pictures_Using_FireMonkey_Interfaces

  • Worked for me, yet still using TSpeedbutton.