The problem is that LazHelpHTML component DEPENDS upon proper current directory set by the application.
Let's assume the application bundle path is: /Users/user/helphtml/helphtml.app
* When you start the application from the Lazarus. It's current directory is set to the directory of the bundle. (i.e. '/Users/user/helphtml'). So LazHelpHTML is able to resolve the correct path of html files: /Users/user/helphtml/HTML
* When you start the application by Finder (or from the Dock), it's current path is set to "/". What results in incorrect help file selected.
* When you start the application manually from terminal, it's current path is set to "/Users/user/helphtml/helphtml.app/Contents/MacOS" (the directory where the executable is located). It would work correct, but only if you copy the HTML dir into the bundle path. (which is wrong).
To correct things you need to adjust the current path (to the required one) whenever the application is started. For example (htmlhelp1.lpr):
program HTMLHelp1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms
{ add your units here }, Unit1, SysUtils, FileUtil;
procedure AdjustCurrentPath;
{$ifdef DARWIN}
var
i : integer;
path : Ansistring;
begin
path:=ExtractFileDir(Application.ExeName);
for i:=1 to 3 do // remove: watnedpath/Bundle.app/Contents/MacOS/exe - 3 dirs
path:=ExtractFileDir(path);
SetCurrentDirUTF8( path );
end;
{$else}
begin
// do nothing if not OSX
end;
{$endif}
begin
Application.Initialize;
AdjustCurrentPath;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
I'm not HTML help specialist, but I guess, it's possible to avoid "relative" path usage in the component.
MacOSX NOTE:Application resources should NOT be stored out-side of the bundle. Help files should be kept at: bundle.app/Contents/Resources directory.
i.e.
bundle.app/Contents/Resources/HTML/index.html
bundle.app/Contents/Resources/HTML/edit1.html
bundle.app/Contents/Resources/HTML/edit2.html
And so current directory should be set to the bundle's resources instead.
However, the current example doesn't allow to keep HTML inside the bundle, so it's fine to change current directory to the bundle's directory, in this particular case.