Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

TElMouseHint - incorrect size

Hi,

Subj is one line higher, though its AutoSize property is true. I create the control in runtime.
I'm doing something like this:

constructor TGContainer.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
.................
  FHint := TElMouseHint.Create(Self);
  FHint.AutoSize := true;
  FHint.Location := hlRightTop;
  FHint.AutoAdjustLocation := true;
  FHint.BoundingControl := Self;
  FHint.Active := false;
.................

procedure TGContainer.ActivateHint(Sender : TObject);
begin
......................
    FHint.Caption := FMouseControl.Hint;
    FHint.Active := true;
......................
end;

procedure TFMain.ElPopupButton1Click(Sender: TObject);
var
  ctl  : TGControl;
......................
begin
  ctl := TGRomb.Create(FContainer);
  ctl.Hint := Format('Hint:'#13#10'%.8x', [int64(ctl)]);

And I'm getting the screenshot attached.

Thank you.
Без имени-1.jpg
150 x 142 - 17K

Comments

  • 6 Comments sorted by Votes Date Added
  • Please send example project to mail @ lmdteam.com. Mention IDE and OS.
    Just tried s.th. similar in Delphi XE7 / Windows 8.1 and no probs avail.
  • Rafael, ashamed!
    Looks like you require to build a special sample for every sneeze :) I just would like to remind that your customers are not paid betatesters, they've paid already everything they should. Really it took around five minutes of my time TO FIX THIS BUG! Haven't your developers even five minutes to look into the code? I assume they know the code better me. Anyway, here is the fix:

     procedure TElMouseHint.BuildHint;
    var R : TRect;
    ...........................
        //<abb2014>
        s : TLMDString;
        //</abb2014>
    begin
    .........................
      if AutoSize then
      begin
        //<abb2014>
        s := Caption;
        if (length(s) > 1) and
           (Copy(s, length(s) - 1, 2) = #13#10) then
          s := Copy(s, 1, length(s) - 2);
        if WordWrap then
        {$ifdef LMD_UNICODE}
          R := FHintWindow.CalcHintRectW(Width, s, nil)
        {$else}
          R := FHintWindow.CalcHintRect(Width, s, nil)
        {$endif}
        else
        begin
        {$ifdef LMD_UNICODE}
          R := FHintWindow.CalcHintRectW(Screen.Width, s, nil);
        {$else}
          R := FHintWindow.CalcHintRect(Screen.Width, s, nil);
        {$endif}
          if R.Right - R.Left > FHintWindow.MaxWidth then
            FHintWindow.MaxWidth := R.Right - R.Left;
        end;
        //</abb2014>
      end
      else
    ....................................

    ...and please think yourself about what to do if AutoSize is False, as I have no opinion for this case.

    The problem source is covered in TLMDStrings.SetText, which appends any input by extra CRLF. I didn't investigate what it was done for and what will happen if we'll remove that code from TLMDStrings. I've just fixed this particular problem.

    Best regards in coding!    ;;)

  • Hi,

    as long as we can not reproduce an issue, we can only provide blind fixes (which can not correctly tested as well - a very dissatisfying situation).
    No offense - but your fix does solve a particular sympton, but not the origin of a possible problem (as I mentioned before, I don't see such a problem here). TLMDStrings.SetText does not add on my side additional CRLFs. 
    Thus knowing the exact way how issue can be reproduced would be really helpful.

  • >>> Thus knowing the exact way how issue can be reproduced would be really helpful. <<<

    The "exact way" is to use the Delphi version I'm using. It's XE5 update 2.

    Take a look here:

    function TStrings.GetTextStr: string;
    var
      I, L, Size, Count: Integer;
      P: PChar;
      S, LB: string;
    begin
      Count := GetCount;
      Size := 0;
      LB := LineBreak;
      for I := 0 to Count - 1 do Inc(Size, Length(Get(I)) + Length(LB));
      SetString(Result, nil, Size);
      P := Pointer(Result);
      for I := 0 to Count - 1 do
      begin
        S := Get(I);
        L := Length(S);
        if L <> 0 then
        begin
          System.Move(Pointer(S)^, P^, L * SizeOf(Char));
          Inc(P, L);
        end;
    //////////////////////////////////////////////////////////////////////////////////
        L := Length(LB);
        if L <> 0 then
        begin
          System.Move(Pointer(LB)^, P^, L * SizeOf(Char));
          Inc(P, L);
        end;
    ///////////////////////////////////////////////////////////////////////////////////
      end;
    end;

    The selected code portion is obviously buggy. Really they should check if there is more lines, and insert CRLF only if this is not the last line. But they don't.

    I never investigated other versions of XE, but you're the who should do it, as long as you claim your library supports all these versions. Or simply override this function in your TLMDStrings.

    One way or another, but the solution would become to be evident immediately as you'll pay attention to it.

    Bye.

  • Posts: 0 Accepted Answer Vote Up0Vote Down
    Hi,

    Fixed.
Sign In or Register to comment.