1、我想实现的功能是,在动态创建RZGroupItem上不添加onclick事件也可以有下划线。
(我创建动态事件后,仍然无下划线,不知道什么原因?非动态创建的Item在Onclick事件后则有)
该怎么实现?或者在指向该Item的时候caption颜色变红之类的可以提示指向该Item 2、在网上找到一贴子,有以下代码
procedure TfrmMain.GrpStylesMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var p:TPoint;
  Index:Integer;
begin
  p.X:= X;
  p.Y:= Y;
  Index:= TRzGroup( Sender ).ItemAtPos( p );
  if Index > 0 then
    showmessage( TRzGroup( Sender ).Items[ Index ].Caption );end;
 但是,我发现第一个TRZGroupItem老没有反应。从第二个开始就有显示message3、
procedure TfrmMain.GrpStylesMouseOverItem(Sender: TObject;
  Item: TRzGroupItem);
begin
   showmessage(item.Caption);
end;
为什么会出现内存读取错误之类的提示?

解决方案 »

  1.   

    1. 参考下面的代码:procedure TForm1.RzGroup1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    var
      Index, i: Integer;
    begin
      Index := TRzGroup(Sender).ItemAtPos(Point(X, Y));
      if Index >= 0 then
      begin
        TRzGroup(Sender).Items[ Index ].FontStyle := TRzGroup( Sender ).Items[ Index ].FontStyle + [fsUnderLine];
        TRzGroup(Sender).Items[ Index ].FontColor := clRed;
      end
      else
      begin
        for i := 0 to TRzGroup(Sender).Items.Count - 1 do
        begin
          TRzGroup(Sender).Items[i].FontStyle := TRzGroup(Sender).Items[i].FontStyle - [fsUnderLine];
          TRzGroup(Sender).Items[i].FontColor := clBlack;
        end;
      end;
    end;
    2. 第一个Item的Index是03. 需要加个判断
       if Item <> nil then ShowMessage(Item.Caption); 
      

  2.   

    非常感谢楼上的认真回答。。
    我想再问下第三个问题,为什么Item会总为nil ? 
    因为加了判断语句后,一直没有反应
      

  3.   

    看了一下控件的源码,发现只有Item加了OnClick事件,而且鼠标要移到Item上面,Item才不会为空。
    procedure TRzGroup.MouseMove( Shift: TShiftState; X, Y: Integer );
    var
      CapState: TRzCaptionState;
      ItemStates: array of TRzCaptionState;
      ItemStatesChanged: Boolean;
      I, OverItem: Integer;
    begin
      inherited;  CapState := csNormal;
      ItemStatesChanged := False;  if FCanClose and PtInRect( CaptionRect, Point( X, Y ) ) then
      begin
        if FClickingCaption then
          CapState := csDown
        else
          CapState := csHot;
      end
      else if ( FItems.Count > 0 ) and not ( csDesigning in ComponentState ) then
      begin
        OverItem := -1;    // Check to see if mouse is over one of the items
        SetLength( ItemStates, FItems.Count );
        for I := FTopItem to FItems.Count - 1 do
          ItemStates[ I ] := csNormal;    for I := FTopItem to FItems.Count - 1 do
        begin

          //这里是判断条件,改变OverItem的值
          if FItems[ I ].Visible and
             ( Assigned( FItems[ I ].OnClick ) or ( FItems[ I ].Action <> nil ) ) and
             ( PtInRect( FItems[ I ].HotCaptionRect, Point( X, Y ) ) or
               PtInRect( FItems[ I ].HotImageRect, Point( X, Y ) ) ) then
          begin
            if FItems[ I ].ClickingCaption then
              ItemStates[ I ] := csDown
            else
              ItemStates[ I ] := csHot;
            OverItem := I;
          end;

        end;    // Did any of the ItemStates change?    for I := FTopItem to FItems.Count - 1 do
        begin
          if FItems[ I ].Visible and ( ItemStates[ I ] <> FItems[ I ].CaptionState ) then
          begin
            ItemStatesChanged := True;
            FItems[ I ].CaptionState := ItemStates[ I ];
            Break;
          end;
        end;

    //这里触发OnMouseOverItem事件
        if OverItem <> -1 then
          MouseOverItem( FItems[ OverItem ] )
        else
          MouseOverItem( nil );
      end;

      if ( CapState <> FCaptionState ) or ItemStatesChanged then
      begin
        FCaptionState := CapState;
        Invalidate;
      end;
    end;
      

  4.   

    TRzGroup(Sender).Items[ Index ].FontStyle
    这句我怎么没法写啊