Lazarus

Programming => Operating Systems => macOS / Mac OS X => Topic started by: norosz123456 on October 25, 2020, 12:27:36 pm

Title: Can't load or open file macOS Catalina - Lazarus IDE v2.0.10
Post by: norosz123456 on October 25, 2020, 12:27:36 pm
Hello.

I tried to load a picture for my Image object. On Windows it works, but on Mac I get every time this error message:

--- Unable to open file "background.png" ---

I tried .jpg and .bmp too... does not works.
It is a simple code, but it does not works on Mac:

Image1.Picture.LoadFromFile('background.png');

I tried create a new file (.csv file) with SaveDialog and it worked. I just can't open or load - read files.

If somebody can, pls help me. Thank you!
Title: Re: Can't load or open file macOS Catalina - Lazarus IDE v2.0.10
Post by: trev on October 26, 2020, 04:45:53 am
This works for me on Catalina:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Image1.Picture.LoadFromFile('/Users/trev/Documents/Bug_Test/smiley.jpg');
  4. end;

or

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   OpenDialog1.Execute;
  4. end;
  5.  
  6. procedure TForm1.OpenDialog1Close(Sender: TObject);
  7. begin
  8.   Image1.Picture.LoadFromFile(OpenDialog1.FileName);
  9. end;  


Alternatively, if the image is going to be part of the application's resources, see Locating the macOS application resources directory (https://wiki.freepascal.org/Locating_the_macOS_application_resources_directory).
Title: Re: Can't load or open file macOS Catalina - Lazarus IDE v2.0.10
Post by: norosz123456 on October 26, 2020, 02:47:12 pm
It is working now! Thank you very much!  :D :)
TinyPortal © 2005-2018