Using TAdvOfficeHint

Is it possible to use the TAdvOfficeHint with a TCheckListEdit? If so, how would I go about doing that?



Andrew

I can see how to add the OfficeHint property to a new custom control but not to TCheckListEdit - without a lot of work to create a new custom TCheckListEdit. Is that correct?


Andrew

You could use the event AdvOfficeHint.OnBeforeShowHint and from there do the settings for a full Office style hint for TCheckListEdit by setting the AHintInfo: TAdvHintInfo parameters of this event.

Thanks Bruno. But I don't understand how the TAdvOfficeHint will recognise the TCheckListEdit without the TCheckListEdit having an OfficeHint property. Is that not a pre-requisite for the TAdvOfficeHint to work? Would you mind elaborating please?

It is not a pre-requisite. 
When TAdvOfficeHint is dropped on the form it replaces the VCL hints. 
It offers Office hints for components that have the OfficeHint property or for those hints where OnBeforeShowHint supplied the OfficeHint information.

'or for those hints where OnBeforeShowHint supplied the OfficeHint information'


Well, here is the OnBeforeShowHint of the TAdvOfficeHint component on the form:

procedure TFormPrefs.AdvOfficeHint1BeforeShowHint(Sender: TObject;
  AControl: TControl; AHintInfo: TAdvHintInfo; var UseOfficeHint: Boolean);
begin
   UseOfficeHint:= True;
   with AHintInfo do begin
      Title:= 'Hidden Fields:';
      //Notes.Add(CheckListEdit1.Text);
      Notes.Add('This is a test');
      ShowHelp:= True;
      end;
end;

With TCheckListEdit.ShowHint := True, no office hint is displayed. My use of this proc is clearly wrong but I can't figure out why. Can you help please?

I tested this with a form with TCheckListEdit and TAdvOfficeHint on the form:


procedure TForm3.AdvOfficeHint1BeforeShowHint(Sender: TObject;
  AControl: TControl; AHintInfo: TAdvHintInfo; var UseOfficeHint: Boolean);
begin
  if acontrol = CheckListEdit1 then
  begin
    AHintInfo.Title := 'title';
    AHintInfo.Notes.Add('notes here');
  end;

end;

procedure TForm3.FormCreate(Sender: TObject);
begin
  CheckListEdit1.Hint := 'CheckListEdit';
  CheckListEdit1.ShowHint := true;
end;

and this works as expected.

Thanks Bruno. Adding 'CheckListEdit1.Hint := 'CheckListEdit';' to the form's FormCreate proc (or any string value) in the component's Hint property) fixed the problem. Without a string in the Hint property, the OfficeHint will not be displayed. Why would you need a redundant value in the Hint property for this to work?  Seems like a bug?

VCL framework will not trigger hints for controls with an empty hint property.

Ah, ok obviously!. Thanks for your help.

Well, i've got it working ok on my app's main form, but on the form I want to use it on, only the CheckListEdit1 Hint items are displayed in a TAdvOfficeHint-like form - but not the Title, Note or Help AHintInfo items. I use the following TAdvOfficeHint AdvOfficeHint1BeforeShowHint proc to create both CheckListEdit1 Hints:


procedure TFormPrefs.AdvOfficeHint1BeforeShowHint(Sender: TObject;       //V7.00
  AControl: TControl; AHintInfo: TAdvHintInfo; var UseOfficeHint: Boolean);
  var
      i: Integer;
begin
   CheckListEdit1.Hint:= '';
   for i:= 0 to 4 do if CheckListEdit1.Checked = True then
    CheckListEdit1.Hint:= CheckListEdit1.Hint + CheckListEdit1.items.DeQuotedString + #13;

    if Acontrol = CheckListEdit1 then begin  //advshowmessage('Here');
        with AHintInfo do begin
          Title:= 'Hidden Fields:';
          Notes.Add('Test Line');
          //Notes.Add(CheckListEdit1.Text);
         ShowHelp:= True;
        end;
    end;
   UseOfficeHint:= True;
end;

This works correctly on the main form but the AHintInfo is ineffective on the FormPrefs. CheckListEdit1.ShowHint = True in both forms' OnCreate methods. 

Using 10.3.3 on W10 Pro with the latest TMSVCLUIPackSetupReg.zip. Any ideas on how to fix this?

Did you drop TAdvOfficeHint on the other form?
If a problem persists, please send a sample source project with which we can reproduce this so we know exactly what you are doing.

Yes, TAdvOfficeHint  was on both forms. I'll make a small project to demo this as soon as I can.

Here is a small demo which illustrates the issue:


https://www.skylogservices.co.uk\Utilities\Hint_Demo.zip

There are several issues in your code.
I cleaned it up.

http://www.tmssoftware.net/public/Hint_Demo.zip 

The reason I coded it that way was to avoid having the dummy CheckListEdit1.Hint value (none - required to trigger AdvOfficeHint1BeforeShowHint) as first item in the Hint. However, the main issue is that I didn't realise that only one TAdvOfficeHint component was required per app - not one per form. Anyway, thank you for your very rapid response to my issue.

I'm getting an AV in your version of the project if I first show the Prefs form and display a hint there and then return to the main form - placing the cursor on its CheckListEdit1 produces an AV. Can you reproduce that?

If you open & destroy the Prefs form, you'll need to check for it being assigned in the hint code.

Good point. Thanks.

All ok now. One minor point for a future update: the bottom of the TAdvOfficeHint's HintHelpText 'Press F1 for more help.' message is too close to the bottom border of the hint when the property 'Rounded' is set to True.


Thanks again.