0

I'm quite a novice in the Android world

and I ran to the next situation

I create this code

//function
procedure LoadPictureFromResource(const ResName: string; out aImage: TImage);
var
  aResource: TResourceStream;
begin
  aResource := TResourceStream.Create(HInstance, ResName, RT_RCDATA);
  try
    aImage.Bitmap.LoadFromStream(aResource);
  finally
    aResource.DisposeOf;
  end;
end;
....
//call function
  FImage := TImage.Create(Self);
  FImage.Parent := Self;
  FImage.Align := TAlignLayout.Left;
  FImage.Margins.Left := 6;
  FImage.Margins.Top := 3;
  FImage.Margins.Bottom := 3;
  FImage.Margins.Right := 3;
  FImage.Width := 64;
  LoadPictureFromResource(resPicturesError, FImage);

obviously with a mistake in the declaration parameter for procedure

used out instead var or const or empty

works with Windows but is still syntax / logic wrong

Android debug mode - Delphi reports an error (the device does not answer anything and operating normally) Segmentation fault (11)

Work mode - Delphi and the device does not report anything

Android does not report anything (error is dangerous) - why?

ceha
  • 50
  • 3
  • The call to DisposeOf is pointless. The out parameter is wrong, should be a plain pass by value. – David Heffernan Apr 02 '17 at 07:20
  • no it is not same code use for windows version and i know out is wrong, question is different – ceha Apr 02 '17 at 07:21
  • 1
    How tedious to have to code for both ARC and non ARC. I had not realised that. Anyway, the out is wrong. Remove it. You pass in a reference to an existing instance. – David Heffernan Apr 02 '17 at 07:22

1 Answers1

0

Resource files are only supported for desktop platforms, please see the details in the docs: http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Resource_Files_Support

If you want to add the file to the mobile project in Delphi, follow the instructions provided in blog: https://community.embarcadero.com/article/articles-tutorials/151-ui/927-deploying-and-accessing-local-files-on-ios-and-android

Please note, that paths for iOS and Android are different - you can enter them in Deployment window, which has separate settings for every platform.

zdzichs
  • 205
  • 2
  • 6
  • It is not true, you can use resource if is RT_RCDATA type. – ceha Apr 02 '17 at 11:55
  • Well... I've pointed the official documentation with special section for Mobile devices (blog entry repeats the same solution). There is a multiplatform version of FindResource implemented in system.pas, but documentation clearly suggests to avoid it. – zdzichs Apr 02 '17 at 13:49
  • i found this solution here http://stackoverflow.com/questions/21291706/delphi-firemonkey-store-data-inside-application – ceha Apr 02 '17 at 15:57
  • I found this one also... But why don't you just use the method which works for sure (i.e. thru Deployment)? The path is different for iOS and Android, but you can setup it once and use exactly the same code for both platforms. If docs say that something does not work, forcing to use such method becomes a little hack, and you can find it useless in the next version of RAD Studio. – zdzichs Apr 02 '17 at 21:07
  • cannot understand :( can you elaborate what do you mean? – zdzichs Apr 03 '17 at 13:48
  • I wrote the wrong text. Try correction (15 characters minimum). 5 minutes elapsed. Pressing the enter key result is that text. – ceha Apr 03 '17 at 17:22