[求救]谁能解释一下TListItem.SetCaption这一动作过程(100分)

  • 主题发起人 主题发起人 Rocklee
  • 开始时间 开始时间
R

Rocklee

Unregistered / Unconfirmed
GUEST, unregistred user!
以下是D6的TListView中的TListItem.SetCaption代码:<br>procedure TListItem.SetCaption(const Value: string);<br>begin<br> &nbsp;if Value &lt;&gt; Caption then<br> &nbsp;begin<br> &nbsp; &nbsp;FCaption := Value;<br> &nbsp; &nbsp;if not Owner.Owner.OwnerData then<br> &nbsp; &nbsp; &nbsp;ListView_SetItemText(Handle, Index, 0, LPSTR_TEXTCALLBACK);<br> &nbsp; &nbsp;if ListView.ColumnsShowing and<br> &nbsp; &nbsp; &nbsp;(ListView.Columns.Count &gt; 0) and<br> &nbsp; &nbsp; &nbsp;(ListView.Column[0].WidthType &lt;= ColumnTextWidth) then<br> &nbsp; &nbsp; &nbsp;ListView.UpdateColumns;<br> &nbsp; &nbsp;if ListView.SortType in [stBoth, stText] then ListView.AlphaSort;<br> &nbsp;end;<br>end;<br><br>这一行重要:ListView_SetItemText(Handle, Index, 0, LPSTR_TEXTCALLBACK);<br><br>而ListView_SetItemText是个Macro,Delphi里的代码为:<br>function ListView_SetItemText(hwndLV: HWND; i, iSubItem: Integer;<br> &nbsp;pszText: PChar): Bool;<br>var<br> &nbsp;Item: TLVItem;<br>begin<br> &nbsp;Item.iSubItem := iSubItem;<br> &nbsp;Item.pszText := pszText;<br> &nbsp;Result := Bool( SendMessage(hwndLV, LVM_SETITEMTEXT, i, Longint(@Item)) );<br>end;<br>跟ListView_SetItemTextA是相同的代码(天杀的,一如既往不支持Unicode!),<br><br>pszText=LPSTR_TEXTCALLBACK, Item.pszText := pszText, ===&gt;Item.pszText=LPSTR_TEXTCALLBACK,查MS api Help,LV_ITEM的pszText为LPSTR_TEXTCALLBACK时此Item为CallBack Item,叫我们不要将ListView设有LVS_SORTASCENDING 或 LVS_SORTDESCENDING 样式,仅此而已,那么为CallBack Item又如何处理呢?到这里Microsoft就故作神秘了。<br><br><br>而又有一处,当执行item.subitems.Add('.... ')后更新Subitems内容的:<br>procedure TSubItems.RefreshItem(Index: Integer);<br>begin<br> &nbsp;ListView_SetItemText(Handle, Owner.Index, Index, LPSTR_TEXTCALLBACK);<br> &nbsp;SetColumnWidth(Index);<br>end;<br>也是调用ListView_SetItemText,也是用LPSTR_TEXTCALLBACK。<br><br>跟踪到这里傻了眼,Delphi的VCL是如何将ListItem的Caption、Subitems的各节内容显示出来的呢,查了半天查不出个究竟。<br><br>各位高手,出来说说。
 
搞定了。
 
后退
顶部