⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 136.htm

📁 水木清华的BBS文章
💻 HTM
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://bbs.tsinghua.edu.cn"><font face="黑体"><big><big>水木清华★</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center">         Delphi编程                            (BM: strayli FlyingBoy)          </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p   align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="454"> <p align="center">[<a href="index.htm">回到开始</a>][<a href="6.htm">上一层</a>][<a href="137.htm">下一篇</a>]
<hr><p align="left"><small>发信人: redforks (Forks), 信区: Delphi <br>

标  题: Dephi Bug - Action与Hint(2 Bug) <br>

发信站: BBS 水木清华站 (Fri Nov 27 21:41:38 1998) WWW-POST <br>

  <br>

1. 若在Action的Hint属性及OnHint方法中若指定Long Hint(一般显示在状态行中长提示 <br>

信息,比如:'打开|打开一个已经存在的文件',长短提示是用'|'隔开的)。这时若将这 <br>

个Action赋给一个Control(比如Button),当鼠标在这个Control上停留一会,应该显 <br>

示短提示时,却把整个提示字符串都显示出来了。    分析Delphi Hint 系统的源码得 <br>

知Delphi的Hint系统有两部分,一部分处理鼠标的短提示,即鼠标停留在控制 <br>

(Tcontrol)上一段时间后,弹出的短提示信息,一部分是当鼠标在控制上或控制和菜单 <br>

获得焦点时,发生的Applicaiton.onShowHint事件。最后都调用Application.ActivateH <br>

int方法,而在ActivateHint方法中,在处理了与该控制相连的Action的Hint字符串之后 <br>

,并没有将Action返回的Hint字符串的短提示取出来。所以会把整个Hint字符串显示出 <br>

来。修改后的函数如下,(修改用注释给出,方法很长只给出部分)是:procedure <br>

TApplication.ActivateHint(CursorPos: TPoint); <br>

... <br>

... <br>

begin <br>

  FHintActive := False; <br>

  if FShowHint and (FHintControl <> nil) and ForegroundTask and <br>

    (FHintControl = GetHintControl(FindDragTarget(CursorPos, True))) then <br>

  begin <br>

    HintInfo.HintControl := FHintControl; <br>



    HintInfo.HintPos := CursorPos; <br>

    Inc(HintInfo.HintPos.Y, GetCursorHeightMargin); <br>

    HintInfo.HintMaxWidth := Screen.Width; <br>

    HintInfo.HintColor := FHintColor; <br>

    HintInfo.CursorRect := FHintControl.BoundsRect; <br>

    ClientOrigin := FHintControl.ClientOrigin; <br>

    ParentOrigin.X := 0; <br>

    ParentOrigin.Y := 0; <br>

    if FHintControl.Parent <> nil then <br>

      ParentOrigin := FHintControl.Parent.ClientOrigin <br>

    else if (FHintControl is TWinControl) and <br>

      (TWinControl(FHintControl).ParentWindow <> 0) then <br>

      Windows.ClientToScreen(TWinControl(FHintControl).ParentWindow, <br>

ParentOrigin); <br>

    OffsetRect(HintInfo.CursorRect, ParentOrigin.X - ClientOrigin.X, <br>

      ParentOrigin.Y - ClientOrigin.Y); <br>

    HintInfo.CursorPos := FHintControl.ScreenToClient(CursorPos); <br>

    HintInfo.HintStr := GetShortHint(GetHint(FHintControl)); <br>

    HintInfo.ReshowTimeout := 0; <br>

    HintInfo.HideTimeout := FHintHidePause; <br>

    HintInfo.HintWindowClass := HintWindowClass; <br>

    HintInfo.HintData := nil; <br>

    HintInfo.HintData := nil; <br>

    CanShow := FHintControl.Perform(CM_HINTSHOW, 0, Longint(@HintInfo)) = 0; <br>

// Add By Red Forks <br>

    HintInfo.HintStr := GetShortHint(HintInfo.HintStr); <br>

// Add End <br>

    if CanShow and Assigned(FOnShowHint) then <br>

      FOnShowHint(HintInfo.HintStr, CanShow, HintInfo); <br>

    FHintActive := CanShow; <br>

    if FHintActive and (HintInfo.HintStr <> '') then <br>

    begin <br>

      ValidateHintWindow(HintInfo.HintWindowClass); <br>

      { make the hint have the same BiDiMode as the activating control } <br>

      FHintWindow.BiDiMode := FHintControl.BiDiMode; <br>

      { calculate the width of the hint based on HintStr and MaxWidth } <br>

      with HintInfo do <br>

        HintWinRect := FHintWindow.CalcHintRect(HintMaxWidth, HintStr, <br>

HintData); <br>

      OffsetRect(HintWinRect, HintInfo.HintPos.X, HintInfo.HintPos.Y); <br>

      if FHintWindow.UseRightToLeftAlignment then <br>

        with HintWinRect do <br>

        begin <br>

          Dec(Left, FHintWindow.Canvas.TextWidth(HintInfo.HintStr) + 5); <br>

          Dec(Right, FHintWindow.Canvas.TextWidth(HintInfo.HintStr) + 5); <br>



        end; <br>

.... <br>

.... <br>

end; <br>

2. 当控制或菜单的Hint属性是空字符串时,不管与之相连的Action是否提供Hint属性, <br>

都不会发生Application的onShowHint方法。   分析:Hint系统首先取出Hint字符串, <br>

若Hint时空串,则不会发生Application.onShowHint,但是,Delphi的取Hint字符串的 <br>

方法忽略了Control的与之相连的Action的Hint,所以产生这个Bug,解决(修改用注释给 <br>

出):$(Delphi)\source\vcl\forms.pas <br>

function GetHint(Control: TControl): string; <br>

begin <br>

  while Control <> nil do <br>

    if Control.Hint = '' then <br>

      Control := Control.Parent <br>

    else <br>

    begin <br>

      Result := Control.Hint; <br>

// Add by Red Forks <br>

      if Assigned(Control.Action) and (Control.Action is TCustomAction) then <br>

        TCustomAction(Control.Action).DoHint(result); <br>

// Add end <br>

      Exit; <br>

Action(Control.Action).DoHint(result); <br>

// Add end <br>

      Exit; <br>

    end; <br>

  Result := ''; <br>

end; <br>

  <br>

-- <br>

※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 202.119.199.100] <br>

</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="6.htm">上一层</a>][<a href="137.htm">下一篇</a>]
<p align="center"><a href="http://cterm.163.net">欢迎访问Cterm主页</a></p>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -