TImage with OSX lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- kelnihat · 2013-04-01 18:52 Dear Folks; I perused all the pages of the Graphics forum, but could not find anything relevant to our problem; I also did searches on the internet using the error message plaguing us and found nothing relevant--so I am posting here thinking it must be a platform-specific issue. Here is a simple program (initially, my son came across the problem while writing a more complicated program.  We excised various portions of the code hoping to exorcise the demon that was causing the error, until we ended with the barebones version below.  Alas, the beast still abideth.): Code: [Select]unit iskender; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,   StdCtrls; type   { TForm1 }   TForm1 = class(TForm)     Dugme: TButton;     Cerceve: TImage;     procedure DugmeClick(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.DugmeClick(Sender: TObject); begin   Cerceve.Picture.LoadFromFile('Pictures/Assos.jpg'); end; end. This program runs from within the Lazarus IDE, but after it is compiled, running it by double clicking the application produces a run-time error (please see snapshots I attached). To avoid various blind alleys, let me mention a few things: (a) the compiler is set to compile for Darwin/i386; (b) tried taking the images out of the "Pictures" folder so they are at the same level with the application; (c) tried other file formats (bmp, png) with the same results; (d)  tried changing the suffix of the string in the procedure call to "jpeg", trying to add the suffix with "concat" or "+", getting rid of the suffix altogether (with corresponding changes in the image  name) ; (e) tried different pictures; (f) tried to start everything fresh by trashing everything, and starting a new project; We will be grateful for any suggestions, but please keep in mind that we are not programmers, merely wannabes --hence a suggestion like "avoid TImage and use TSomething in conjunction with TSomething_else" is tantamount to shooting me between the eyes (the kid is having fun, I'm the one about to burst into a million pieces) Info: fpcsrc-2.6.0.intel-macosx fpc-2.6.0.intel-macosx lazarus-1.0.4-20121130-i386-macosx on MacOSX 10.6.8 on an Intel core i5 w/ XCode 3.2.6 (1761) and GPC XCode Kit 1.1 (installed for XCode 2.1) My son's computer is running 10.7, with XCode 4.3.2; FPC /Lazarus specs are the same Thanks and regards ---------------------------------------------------------------------- jwdietrich · 2013-04-01 19:42 I cannot reproduce your problem, see attached screenshot. I use Lazarus 1.0.8 with Free Pascal 2.6.2 and Xcode 3.1.2 on a PPC- based Mac (PowerMac G5, Mac OS X 10.5 Leopard). ---------------------------------------------------------------------- jwdietrich · 2013-04-01 20:13 I just saw that it worked only, when the program was run from the Lazarus IDE. Clicking on the executable in Finder reproduced the same error that you described. Obviously, the path to the executable is only correctly represented within the IDE. The following code does the trick (you might need to adapt the variable names): Code: [Select]procedure TForm1.Button1Click(Sender: TObject); const   tripleUp = '../../../'; {compensates for the location of the executable in ./appname/Contents/MacOS } var   thePath: String; begin   thePath := application.Location;   Form1.Image1.Picture.LoadFromFile(thePath + tripleUp + 'Pictures/test.jpg'); end; ---------------------------------------------------------------------- kelnihat · 2013-04-02 07:40 Thank you, jwdietrich.  A suitable adaptation of your code solved the problem.  We are grateful to you and to the other friends who have so graciously helped us in the past. If you will allow me some follow-up questions so I can learn better: When I check the value returned by the application.Location procedure, I get:         /Users/My_User_Name/Desktop/Some_Folder_Name/project1.app/Cont ents/MacOS/ So the concatenation in the subsequent procedure call yields the string: /Users/My_User_Name/Desktop/Some_Folder_Name/project1.app/Contents/Mac OS/../../../Pictures/test.jpg This, together with your choice of name for the constant tripleUp, leads me to surmise that '../../../' instructs the program to "rollback" three levels in the file hierarchy while looking for "test.jpg".  Is this correct--and more importantly, where would I have learned this (which wiki or document among the laz/FPC documentation)? Finally, is this (Lazarus not retaining the correct representation of the executable while compiling) a bug?  If it is, I would be more than happy, by reporting it, to contribute our grain of sand to the magnificent project you guys are constructing... Thanks and regards ---------------------------------------------------------------------- jwdietrich · 2013-04-02 08:41 Quote from: kelnihat on April 02, 2013, 09:40:52 amThis, together with your choice of name for the constant tripleUp, leads me to surmise that '../../../' instructs the program to "rollback" three levels in the file hierarchy while looking for "test.jpg".  Is this correct--and more importantly, where would I have learned this (which wiki or document among the laz/FPC documentation)? Yes, this is correct. "../" is a standard in Unix path representations meaning one step upwards in the hierarchy. Quote from: kelnihat on April 02, 2013, 09:40:52 amFinally, is this (Lazarus not retaining the correct representation of the executable while compiling) a bug?  If it is, I would be more than happy to contribute our grain of sand to the magnificent project you guys are constructing by reporting it... This is not a bug. It is a consequence of the structure of application files in Mac OS X, where the program executable is stored together with additional resources in a special folder structure called bundle. Normally (e.g. in standard Finder operations), a bundle behaves like a single file, however by right clicking the icon you can get access to its contents. application.Location delivers the path to the executable inside the bundle, therefore it is necessary to move three steps upwards in order to get the folder that contains the bundle. You can learn these things by reading the (very extensive) Mac OS documentation at http://developer.apple.com. ---------------------------------------------------------------------- kelnihat · 2013-04-03 13:18 Thanks very much, jwdietrich. Regards