代码如下:
procedure TDBNavPlus.SetCaptions(Value: TStrings);
var
  t: TNavigateBtn;
begin
  if Value <> FCaptions then FCaptions.Assign(Value);
  for t:= low(TNavigateBtn) to high(TNavigateBtn) 
    //这个low和high是什么操作?怎么翻译为BCB代码?
  do begin
    if ord(t) < Value.Count
    then Buttons[t].caption := Value[ord(t)]//这个ord又是什么操作?
    else Buttons[t].caption := DefaultCaption[ord(t)];
  end;
  Invalidate;
end; {of setCaptions}

解决方案 »

  1.   

    还有那个Buttons在CB中对应哪个数组呢?
      

  2.   

    这个low[最低值]和high[最高值]是什么操作?怎么翻译为BCB代码?
    你是在看别人代码吗?如果可以的话共享一下吧。[email protected]
      

  3.   

    共享吗?没问题呀!我贴出来吧。这是个实用的组件!没见过的包大家喜欢,但是还是请大家帮我看怎么转BCB代码。
    unit DBNavPlus;
    interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls, DBCtrls, Buttons;const
    DBNavPlusVersion = '1.2';type
      TDBNavPlus = class(TDBNavigator)
      private
        { Private declarations }
        DoCaptions: boolean;
    FCaptions: TStrings;
        FLayout: TButtonLayout;
        FSpacing: Integer;
        FMargin: Integer;
      protected
        { Protected declarations }
        procedure SetLayout(value: TButtonLayout);
        procedure SetSpacing(value: integer);
        procedure SetMargin(value: integer);
    procedure SetCaptions(value: TStrings);
      public
        { Public declarations }
        constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
      published
        { Published declarations }
    property Captions: TStrings read FCaptions write SetCaptions;
    property Layout: TButtonLayout read FLayout write SetLayout default blGlyphTop;
    property Spacing: Integer read FSpacing write SetSpacing default 2;
        {if we dont set default, the SetMargin is called}
        {this will allow us to put the SetCaptions in as it is not called!}
    property Margin: Integer read FMargin write SetMargin;
    property Font;
      end;procedure Register;implementationconst
    DefaultCaption: array[0..9] of string =
       ('First','Prior','Next','Last','Insert',
         'Delete','Edit','Accept','Undo','Refresh');{******************************************************************************}
    constructor TDBNavPlus.Create(AOwner: TComponent);
    var
    x: integer;
    begin
    inherited create(AOwner);
      {initialize values}
    FCaptions := TStringList.create;
      DoCaptions := True;
      FSpacing := 0;
      SetSpacing(2);
      FMargin := 0;
      SetMargin(-1);
      FLayout := blGlyphBottom;
      SetLayout(blGlyphTop);
      FCaptions.Clear;
      for x := 0 to 9 do FCaptions.Add(DefaultCaption[x]);
      SetCaptions(FCaptions);
    end; {of Create}{******************************************************************************}
    destructor TDBNavPlus.Destroy;
    begin
    FCaptions.Free;
    inherited Destroy;
    end; {of destroy}{******************************************************************************}
    procedure TDBNavPlus.SetCaptions(Value: TStrings);
    var
      t: TNavigateBtn;
    begin
    {set captions or default if not assigned}
    if Value <> FCaptions
      then FCaptions.Assign(Value);
    for t:= low(TNavigateBtn) to high(TNavigateBtn) do begin
    if ord(t) < Value.Count
        then Buttons[t].caption := Value[ord(t)]
        else Buttons[t].caption := DefaultCaption[ord(t)];
      end;
      Invalidate;
    end; {of setCaptions}{******************************************************************************}
    procedure TDBNavPlus.SetLayout(value: TButtonLayout);
    var
      t: TNavigateBtn;
    begin
    if (value = Flayout) and  not (csLoading in ComponentState) then exit;
    FLayout := value;
    for t:= low(TNavigateBtn) to high(TNavigateBtn)
      do Buttons[t].Layout := value;
      Invalidate;
    end; {of SetLayout}{******************************************************************************}
    procedure TDBNavPlus.SetSpacing(value: integer);
    var
      t: TNavigateBtn;
    begin
    if (value = FSpacing) and not (csLoading in ComponentState) then exit;
    FSpacing := value;
    for t:= low(TNavigateBtn) to high(TNavigateBtn)
      do Buttons[t].Spacing := value;
      Invalidate;
    end; {of SetSpacing}{******************************************************************************}
    procedure TDBNavPlus.SetMargin(value: integer);
    var
      t: TNavigateBtn;
    begin
    if (value = FMargin) and not (csLoading in ComponentState) then exit;
      if (csLoading in ComponentState) then SetCaptions(FCaptions);
    FMargin := value;
    for t:= low(TNavigateBtn) to high(TNavigateBtn)
      do Buttons[t].margin := value;
      Invalidate;
    end; {of SetMargin}
    {******************************************************************************}
    procedure Register;
    begin
      RegisterComponents('Fitco', [TDBNavPlus]);
    end; {of Register}end. {of uniut}
      

  4.   

    大家要是要用到TDBNavigator的话,就用这个TDBNavPlus 代替吧!
      

  5.   

    maoxc(默春) :
    兄弟是说我不诚心吗?不诚心我自个在这里顶什么呢?再说了,这个TDBNavPlus怎么样都算个比较有价值的代码吧。
      

  6.   

    测试了吗?和TDBNavigator控件作比较有哪些优点呀?关于转换代码到CB上我可能解决不了。但我会关注一下的。我好久没有用过CB了,我一直都用的是Delphi!
      

  7.   

    当然测试通过了,它的优点在于给TDBNavigator加上了Captions属性,使TDBNavigator不再单调呀。另外还可以修改TDBNavigator的图片。我想做的是在BCB下重写它,并给它加入image属性修改显示图片。可是改的时候发现low和high操作不太明白,要是大家都没办法,我只好用DELPHI写了。
      

  8.   

    procedure TDBNavPlus.SetCaptions(Value: TStrings);
      for t:= low(TNavigateBtn) to high(TNavigateBtn) 
        //这个low和high是什么操作?怎么翻译为BCB代码?
     for(TNavigateBtn nb = nbFirst; nb < nbRefresh; nb++)    then Buttons[t].caption := Value[ord(t)]//这个ord又是什么操作?
        else Buttons[t].caption := DefaultCaption[ord(t)];
    ord 是返回枚举类型 值的序号
    鉴于是TNavigateBtn从0开始的,可以直接用t来代替enum TNavigateBtn { nbFirst, nbPrior, nbNext, nbLast, nbInsert, nbDelete, nbEdit, nbPost, nbCancel, nbRefresh };
      

  9.   

    这儿改一下,应该是<=
    for(TNavigateBtn nb = nbFirst; nb <= nbRefresh; nb++)
      

  10.   

    那low和high应该是取数组的上、下标吧。
    在C++里面好象是用Ubound和Lbound吧
      

  11.   

    谢谢“太上皇”和“杂草”的回复,总算有人帮我了,真高兴!
    To jingrunx(太上皇):
        好象for(TNavigateBtn nb = nbFirst; nb <= nbRefresh; nb++)不能编译呢。下面是我的代码和错误:
    void __fastcall  TDbnavigatorMyself::SetCaptions(TStrings *Value)
    {
            if(Value!=FCaptions)FCaptions->Assign(Value);
            for(TNavigateBtn nb = nbFirst; nb <=nbRefresh; nb++)
    {
              if (nb < Value->Count)
                Buttons[nb]->Caption = Value[nb] ;
              else Buttons[nb]->Caption = DefaultCaptions[nb];
            }
            Invalidate();
    }//函数就对应前面delphi的SetCaptions(TStrings *Value)函数。
    错误:
    [C++ Error] DbnavigatorMyself.cpp(49): E2277 Lvalue required
    [C++ Error] DbnavigatorMyself.cpp(52): E2034 Cannot convert 'TStrings' to 'AnsiString'这错误还有救吗?to zleeway(杂草) :
    帮助中好象找不到Ubound和Lbound的用法呢。
      

  12.   

    哦,Buttons[nb]->Caption = Value[nb] 写错了,应该是Buttons[nb]->Caption = (*Value)[nb] ;
    老是那个“Lvalue required”不懂!
      

  13.   

    算了,用for(int i=0;i<=9;i++)算了。
    分都加给太上皇。