代码有错请解决(20分)

  • 主题发起人 主题发起人 阿张
  • 开始时间 开始时间

阿张

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TepCustomComboBox.CNDrawItem(var Message: TWMDrawItem);
var
State: TOwnerDrawState;
begin
with Message.DrawItemStruct^ do
begin
//下面一行报错:invalid typecast,该怎么处理好呢?
State := TOwnerDrawState(WordRec(LongRec(itemState).Lo).Lo);
Canvas.Handle := hDC;
Canvas.Font := Font;
Canvas.Brush := Brush;
if (Integer(itemID) >= 0) and (odSelected in State) then
begin
Canvas.Brush.Color := FSelectColor;
Canvas.Font.Color := FSelectTextColor;
end;
if Integer(itemID) >= 0 then
DrawItem(itemID, rcItem, State);
if odFocused in State
then
if FUseFocusFrame
then
Frm3D(Canvas,rcItem, FInnerFocusColor, FOuterFocusColor,1)
else
begin
Canvas.Brush.Style := bsSolid;
Canvas.DrawFocusRect(rcItem);
end;
Canvas.Handle := 0;
end;
end;
 
faint!在delphi的强制转换中,一定要两个类别的长度一样,才可以相互转换。
在你的代码中,TOwnerDrawState长度是2,而WordRec(LongRec(itemState).Lo).Lo长度是
1
所以,编译报错误!!!
 
接受答案了.
 

Similar threads

后退
顶部