* * *

Author Topic: Pressing F1 to open a CHM helpfile in a Lazarus application  (Read 6149 times)

JD

  • Hero Member
  • *****
  • Posts: 573
Pressing F1 to open a CHM helpfile in a Lazarus application
« on: October 05, 2009, 10:51:14 pm »
Hi there everybody.

I have a chm help file that I made for an application that I wrote using Lazarus on Windows. How do I configure my application such that users can call and open the help file by pressing F1?

In addition, how do I make the calls context sensitive?

I'm asking these questions because the Delphi methods for doing this don't seem to work in Lazarus on Windows (I assume because the methods are not cross platform).

Thanks.

andyman

  • Jr. Member
  • **
  • Posts: 55
Re: Pressing F1 to open a CHM helpfile in a Lazarus application
« Reply #1 on: October 06, 2009, 03:09:35 am »
Hi this link should help ( no pun intended ) http://notcolin.wordpress.com/2009/08/10/the-microsoft-html-help-api-commands/

Also I'm not sure if you wrote the code to make the chm yourself using TCHMWriter but if you did you can use
Code: [Select]
procedure TChmWriter.AddContext(AContext: DWord; ATopic: String);

where AContext is the context number you will give the api to lookup ATopic where ATopic us the url in the chm. ('/html/myspecialpage.html') That's helpful if you assign the context ids in the TControl.HelpContext

also the above link gives an example to load a specific url in the chm without adding context numbers in the chm

HTH,

Andrew

JD

  • Hero Member
  • *****
  • Posts: 573
Re: Pressing F1 to open a CHM helpfile in a Lazarus application
« Reply #2 on: October 06, 2009, 07:51:13 am »
Thanks for the tips andyman. I didn't use TChmWriter at all, I used another application to create the help file & it is a detailed help file with graphics, links etc.

I took a look at the chmhelppkg component bundled with Lazarus & my first impressions of it are that it is more of a viewer to enable the viewing of CHM files on non-Windows platforms. It renders help files poorly on Windows (garbled text, improper display of graphics, search doesn't work & non-English text is mangled on the table of contents). It would be great on Linux though. It's not what I want because it is a bit like re-inventing the wheel to use such a chm viewer on windows.

I just want to be able to open the help file by pressing F1! Unfortunately the Delphi code I have that does it noes not work in Lazarus. I don't know if TProcess/TProcessUTF8 would work because I've always believed it is used to run executables.

I'll take a closer look at the website you suggested. I hope I find something that will solve this problem there.
« Last Edit: October 06, 2009, 08:00:58 am by JD »

JD

  • Hero Member
  • *****
  • Posts: 573
Re: Pressing F1 to open a CHM helpfile in a Lazarus application
« Reply #3 on: October 15, 2009, 01:32:09 pm »
I've solved the problem. It works perfectly now. I've not fully tested the context-sensitive features of the help commands but I'm fairly satisfied with the way it is working now.

Thanks for the tip.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1022
Re: Pressing F1 to open a CHM helpfile in a Lazarus application
« Reply #4 on: December 04, 2009, 11:01:20 am »

I took a look at the chmhelppkg component bundled with Lazarus & my first impressions of it are that it is more of a viewer to enable the viewing of CHM files on non-Windows platforms. It renders help files poorly on Windows (garbled text, improper display of graphics, search doesn't work & non-English text is mangled on the table of contents). It would be great on Linux though. It's not what I want because it is a bit like re-inventing the wheel to use such a chm viewer on windows.

In the next FPC version, there will be a htmlhelp unit in package winunits-base, which has the (4 or 5) basic prototypes to search windows-internal help.

I however had the feeling the windows api is mostly used for ordinary applications, and doesn't match up to the specific demands of an IDE.  So while generated apps might use windows help directly in the "far" future, I doubt the IDE will

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1022
Re: Pressing F1 to open a CHM helpfile in a Lazarus application
« Reply #5 on: December 08, 2009, 09:42:16 am »
If somebody has an example of a normal application using CHM for help, I'd like to have it.

Either via lazarus' helpsystem or directly via the api

davesimplewear

  • Sr. Member
  • ****
  • Posts: 300
    • Davids Freeware
Re: Pressing F1 to open a CHM helpfile in a Lazarus application
« Reply #6 on: December 09, 2009, 12:57:24 am »
This is not strictly on topic, but does chmWriter wotk in linux?
All things considered insanity seems the best option

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1022
Re: Pressing F1 to open a CHM helpfile in a Lazarus application
« Reply #7 on: December 09, 2009, 09:43:05 am »
This is not strictly on topic, but does chmWriter wotk in linux?

Yes, and on FreeBSD. In fact the FPC/Lazarus chms are generated on Linux or FreeBSD in general (see below URL)  OS X/x86 works fine too.

http://www.stack.nl/~marcov/doc-chm.zip

There have some brief tests to check endian safeness from time to time, so the package should generally be
endiansafe, but there could be occasional endianess bugs.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1022
Re: Pressing F1 to open a CHM helpfile in a Lazarus application
« Reply #8 on: December 30, 2009, 01:30:20 pm »
Last night I tested CHMwriter to test adding context ids, and I found a bug. >:D

Use 2.5.1 of today or later if you want to _generate_ context sensitive help based on IDs.

JD

  • Hero Member
  • *****
  • Posts: 573
Re: Pressing F1 to open a CHM helpfile in a Lazarus application
« Reply #9 on: January 11, 2010, 08:23:43 am »
If somebody has an example of a normal application using CHM for help, I'd like to have it.

Either via lazarus' helpsystem or directly via the api

This is the code I used to implement CHM help for my Lazarus Windows application.

Code: [Select]
(*-----------------------------------------------------------------------------
                 Launch an external application

Adapted from Source: http://wiki.lazarus.freepascal.org/Executing_External_Programs
------------------------------------------------------------------------------*)
procedure LaunchCHMHelp(ProgramName: string);
var
  AProcess: TProcess;
begin
  try
    // Create the TProcess object, and
    // assign it to the var AProcess.
    AProcess := TProcess.Create(nil);

    // Use AProcess to execute the Microsoft HTML Help file in the windows directory
    // The "10" in "-mapid 10 ms-its:" signifies the table of contents
    AProcess.CommandLine := 'hh.exe' + ' ' + '-mapid 10 ms-its:' +
         ExtractFilePath(Application.ExeName) + ProgramName;;

    // Now that AProcess knows what the commandline is
    // we will run it.
    AProcess.Execute;

    // Free AProcess
    AProcess.Free;
  except
    MessageDlg('Le fichier << ' + ProgramName + ' >> est introuvable', mtError, [mbOK], 0);
  end;
end;


The code below opens the CHM helpfile when F1 is pressed or when a toolbar button is clicked

Code: [Select]
procedure TfrmMainform.HelpContents1Execute(Sender: TObject);
begin
  // Display the table of contents of the help file
  LaunchCHMHelp('Helpfile.chm');
end;

"HelpContents1" is a TToolButton on the menu toolbar with its Shortcut property set to F1 i.e HelpContents1.ShortCut := 'F1'.

So pressing F1 or clicking on the TToolButton with open the CHM help file. You can use another shortcut if you wish. There are many other options that you can set at designtime under the Action property of the TToolButton.

Cheers,

JD

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1022
Re: Pressing F1 to open a CHM helpfile in a Lazarus application
« Reply #10 on: January 11, 2010, 03:08:26 pm »
Have a look at the fpc/packages/winunits-base/tests dir, most notably hhex.pp and hhex2.pp


HarryMudd

  • Newbie
  • Posts: 1
Re: Pressing F1 to open a CHM helpfile in a Lazarus application
« Reply #11 on: January 30, 2010, 11:11:41 pm »
Hello, sorry for my bad english :)

You can use htmlhlp.pas and overrides the THelpManager from helpintfs. Then the Application can call *.chm help by keyword like "hh.exe myhelp.chm::/mysite.html#mycontent".
You dont needs TProcess.

The htmlhlp.pas can downloaded by "http://www.koders.com/delphi/fid34DE68AEB65566AA668889D5CFD863201252CBF2.aspx?s=htmlhlp#L14"

This unit is for Delphi and Kylix, but it is easy to portable to fpc.

Bye

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads