4

My Delphi application includes a help file that the user can call from anywhere in the application (well... that is, for all the parts I've written so far...)

It also includes the ability for the user to switch from the regular style to another VCL style from a list.

When no style is applied, the help file displays normally like this :

Help file readable

But as soon as a VCL style is active, the Help file does not display correctly anymore, like this :

help file messed-up by the VCL

Is this due to the way I declare the HelpFile on main Form creation like this (path being a global variable pointing to the main exe folder):

Application.HelpFile := path+'Help\D.R.A.M.A. 2.0 Help.chm';

or is this a known problem that can not be solved ?

SIDE NOTE : the help is called on helpContext should that be important to mention and the HtmlHelpViewer is added to the uses clause.

RBA
  • 12,337
  • 16
  • 79
  • 126
Mathmathou
  • 373
  • 4
  • 15
  • One of the horrors I've faced once. If I recall, I solved it using [vcl-styles-utils](https://github.com/RRUZ/vcl-styles-utils) – Jerry Dodge Jun 05 '17 at 23:49
  • There's a (German language) thread about that: http://www.delphipraxis.net/192481-styles-und-hilfe-im-chm-format.html – Uli Gerhardt Jun 06 '17 at 06:41
  • Help file control is in your process and so subject to styling. Nothing to do with paths. Follow Jerry's advice and see if that helps. Wouldn't it just be easier not to use styles? Doesn't it bother you when your users upgrade to new windows versions and your program breaks? – David Heffernan Jun 06 '17 at 06:56
  • Delphi styles are very buggy. Use the VCL styles developed by Rodrigo Ruz https://github.com/RRUZ/vcl-styles-utils. – RBA Jun 06 '17 at 06:58
  • @RBA Same link I posted, but it's not a *replacement* or *alternative*, as your comment suggests. It's an extension which fixes many known issues, as well as introduces new features. – Jerry Dodge Jun 06 '17 at 14:58
  • @JerryDodge - I agree with you. I didn't read all the comments, just wrote a quick comment. – RBA Jun 06 '17 at 15:11
  • @UliGerhardt thanks for the link... my German is far behind but I got most of it. – Mathmathou Jun 08 '17 at 06:46
  • @DavidHeffernan Program breaks on windows version upgrade ? Wow, you're scarring me and I have to admit I don't understand why it would break... Is it because the VCL themes are based on Windows therme capabilities ? – Mathmathou Jun 08 '17 at 06:48
  • @JerryDodge I looked into it but have to admit I don't know how this could solve my problem. I already (did I ?) mentioned that I'm quite a beginner and probably trying to go to far at once. – Mathmathou Jun 08 '17 at 06:49
  • It's because VCL styles is basically a hack that in some parts is based on implementation details. And yes, there have been windows updates that broke existing apps. – David Heffernan Jun 08 '17 at 07:04
  • I suggest finding another solution in the event that you're a beginner. Patching the VCL Styles to work on Windows controls such as this is not a trivial task, even if you know what needs to be done. And as @David said, what happens when Windows releases a new version with a brand new help viewer screen? – Jerry Dodge Jun 08 '17 at 14:37

1 Answers1

2

This answer was taken from https://forums.embarcadero.com/thread.jspa?threadID=227785 and I've confirmed works very well.

Drop a TApplicationEvents component onto the applications main form.

Implement the OnHelp event of that component as this:

function TfmMain.ApplicationEvents1Help(Command: Word; Data: NativeInt; var CallHelp: Boolean): Boolean;
begin
  CloseHelpWnd;

  Result := ShellExecute(0,'open','hh.exe',
                         PWideChar('-mapid '+IntToStr(Data)
                                   +' ms-its:'+Application.HelpFile),
                         nil,SW_SHOW) = 32;

  CallHelp := false;
end;

On the main form, implement the CloseHelpWnd method as this:

procedure TfmMain.CloseHelpWnd;
var
  HlpWind: HWND;
const
  HelpTitle = 'Your help file title';
begin
  HlpWind := FindWindow('HH Parent',HelpTitle);
  if HlpWind <> 0 then PostMessage(HlpWind,WM_Close,0,0);
end;

You would replace 'Your help file title' with the title of your help file. This is the window caption title when you open the help file directly.

In the FormDestroy event for the main form, include a call to

CloseHelpWnd;

So far we've not seen any issues with the above method, and because we are running the help file in a separate process, it is not affected by the VCL Styles problems evident in Delphi 10.2 Tokyo.

NOTE: It does not have to be the applications main form, but it must be a form that is created before the help system is needed and remains instantiated while the application is running. In our case, we did it on a common resources form and then all programs we rebuilt with the new form had the help problem resolved.

NOTE: You still need to set the Application.HelpFile property as normal, but you don't need to include the HtmlHelpViewer unit in the Uses clause.

SiBrit
  • 1,460
  • 12
  • 39