1

For some reason when i specify "|" symbol inside Hint string for any Delphi control the hint terminates at the first occurred "|" so the tooltip window contains only part of the text till the first "|" encountered...

I've tested that symbol in C++ (both WinApi + MFC) and it shows hints pretty K with "|" symbol, so it looks like it's some Delphi specific bug.

The whole program works fine but this thing with hints just rly bugs me =\

So, any ideas how to fix that?

Markus_13
  • 328
  • 2
  • 14

3 Answers3

3

This is by design, and is documented behavior:

TControl. Hint property

TApplication.Hint property

There are two parts to the Hint string--short and long--separated by the | character. Short hints are used by pop-up tool tips. Long hints are used by the status bar. Use the GetShortHint and GetLongHint global functions from the Controls unit to extract the long and short hints from a hint string.

To "fix" this so you can display | characters, you have to either:

Both are triggered while the pop-up is being prepared, after the Hint text is split and before the pop-up is actually displayed. Both provide access to a THintInfo record that you can customize as desired. It has a HintStr field you can set to whatever text you want, including | characters. And it has a HintControl field that points to the control that is displaying the pop-up.

The simplest solution would be to use the OnShowHint event to set HintStr := HintControl.Hint.

Using TApplication.OnShowHint:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnShowHint := AppShowHint;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Application.OnShowHint := nil;
end;

procedure TForm1.AppShowHint(var HintStr: string; var CanShow: boolean; var HintInfo: THintInfo);
begin
  HintStr := HintInfo.HintControl.Hint;
end;

Using TApplicationEvents.OnShowHint:

procedure TForm1.ApplicationEvents1ShowHint(var HintStr: string; var CanShow: boolean; var HintInfo: THintInfo);
begin
  HintStr := HintInfo.HintControl.Hint;
end;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thanks for info, didn't knew that in years, maybe cuz i don't use StatusBars lol. But is it "fixable"? I really want to show these symbols in popups... I mean - could it be done without manual tooltip system recreation in raw winapi ?? – Markus_13 Oct 26 '17 at 05:25
1

Another tricky solution, based of the font you use, you can alternatively use other vertical-line characters in unicode table like these:

U+01C0: 'ǀ'
U+0964: '।'
U+2223: '∣'
U+2502: '│'
U+2503: '┃'
U+2758: '❘'
U+FF5C: '|'
...

I have not tested them in the Hint texts so you can try them yourself. Hope it helps.

Mahan
  • 135
  • 7
0

Well, the easiest solution i've come up with is just to edit the "Controls.pas":

function GetShortHint(const Hint: string): string;
var
  I: Integer;
begin
{$IFDEF _ONLY_SIMPLE_HINTS_}
  Result:=Hint;
{$ELSE}
  I := AnsiPos('|', Hint);
  if I = 0 then
    Result := Hint else
    Result := Copy(Hint, 1, I - 1);
{$ENDIF}
end;

function GetLongHint(const Hint: string): string;
var
  I: Integer;
begin
{$IFDEF _ONLY_SIMPLE_HINTS_}
  Result:=Hint;
{$ELSE}
  I := AnsiPos('|', Hint);
  if I = 0 then
    Result := Hint else
    Result := Copy(Hint, I + 1, Maxint);
{$ENDIF}
end;

So i've just added "{$DEFINE _ONLY_SIMPLE_HINTS_}" to my project =)

Disclaimer: use TApplication.OnShowHint or CM_HINTSHOW interception as suggested by Remy Lebeau, if you are not that lazy as i am.

Markus_13
  • 328
  • 2
  • 14
  • This is not the easiest solution, or even the best solution. The *correct* solution is to use the hooks that are already provided to officially handle this kind of situation: the `TApplication(Events).OnShowHint` event, or the `CM_HINTSHOW` message. See my answer for details – Remy Lebeau Oct 26 '17 at 05:53
  • Well, i never use this whole multi-hint feature anyways (i happened to know about it only few minutes ago when i've read your answer =), so IT IS easiest solution FOR ME, actually i could just blatantly replace both functions, but for a bit more flexibility i've chosen conditional compilation approach which is absolutely fine as to me. – Markus_13 Oct 26 '17 at 05:54
  • 1
    recompiling vendor-provided units to fix something that can be handled without recompiling at all is just plain wrong. Like I said, there are hooks provided to solve this issue through official channels – Remy Lebeau Oct 26 '17 at 05:59
  • Well, for my dusty Delphi7 it's no problem. These "vendor-provided" units r like 15 years old anyways, if it was some c++ standard module, i'd chosen another way, but with Delphi7 i see no point in keeping it sacramental. Not first time when i edit them. Actually with my conditional compilation flags in different bulky units sometimes i save up to 20% of final binary size after compilation on some projects. – Markus_13 Oct 26 '17 at 06:11