//什么叫重载Edit的Text属性
type
  TMyEdit=class(TCustomEdit)
  private  public  published
    //这里可屏蔽Text属性
  end;

解决方案 »

  1.   


    看看这个或许有好处:http://www.csdn.net/expert/topic/129/129319.shtm
      

  2.   

    简单地说,我从TEdit继承下来一个新的类,这样这个类就在Object Inspector中有所有原
    TEdit的属性。我如何能使之变成自己的属性,或只是不让他们出来?taxt能否给个例子,难道我需要在published中一一写遍所有的Property?如果我只是不想让他们出来,我又该如何做?
      

  3.   

    将原来的publish 改为public,另外写一个publish,在那下面列出你要显示的属性。
      

  4.   

    type
      TNumberEdit=class(TCustomEdit)
      private
        FValue: integer;
        procedure SetValue(Value: integer);
        .....
        .....
      protected
        procedure KeyPress(var Key: Char);override;
      public
        constructor Create(AOwner: TComponent);override;
      published
        property Value: integer read FValue write SetValue;
        //把其它属性共布出来,但不要公布Text属性
        property Action;
        ......
        ......
        ......
      end;
    procedure TNumberEdit.SetValue(Value: integer);
    begin
      if Value <> FValue then
      begin
        Text := IntToStr(Value);
        FValue := Value;
      end;
    end;constructor TNumberEdit.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      FValue := 1;
      SetValue(0);
    end;procedure TNumberEdit.KeyPress(var Key: Char);
    begin
      inherited;
      if (not (key in ['0'..'9'])) and (Key <> #8) then
        Key := #0
      else
        SetValue(StrToInt(Text)):
    end;
      

  5.   

    >>难道我需要在published中一一写遍所有的Property?
    我想这样做是必须的
    你用Copy-Past就好了,又不麻烦
      

  6.   

    事实是,我如果不在Published里写,属性仍会自己出来。我不想让他出来该怎么办?
    而且taxi兄是用的Value来代替Text,而不是覆盖原有的Text。不妨看看编译后的组件,
    Text属性仍在Object Inspector中,这不是我想要的。大家有没有试过覆盖原有
    的属性,那样编译成组件后我的Delphi6+SP1就会立即退出,什么提示也没有!What shall I do?
      

  7.   

    从TCustomEdit派生一个控件,属性缺省是保护的,把想要的公开就行了
      

  8.   

    我试了一个,Text属性决不会显示出来。以下是源程序。你自己再试一试人,说不是你的是从TEdit继承下来的。
    unit NumberEdit;interfaceuses
      Windows, Messages, SysUtils, Classes, Controls, StdCtrls;type
      TNumberEdit = class(TCustomEdit)
      private
        { Private declarations }
        FValue: integer;
        procedure SetValue(Value: integer);
      protected
        { Protected declarations }
        procedure KeyPress(Var Key: Char);override;
      public
        { Public declarations }
        constructor Create(AOwner: TComponent);override;
      published
        { Published declarations }
        property Value: integer read FValue write SetValue;
        property Anchors;
        property AutoSelect;
        property AutoSize;
        property BevelEdges;
        property BevelInner;
        property BevelKind default bkNone;
        property BevelOuter;
        property BiDiMode;
        property BorderStyle;
        property CharCase;
        property Color;
        property Constraints;
        property Ctl3D;
        property DragCursor;
        property DragKind;
        property DragMode;
        property Enabled;
        property Font;
        property HideSelection;
        property ImeMode;
        property ImeName;
        property MaxLength;
        property OEMConvert;
        property ParentBiDiMode;
        property ParentColor;
        property ParentCtl3D;
        property ParentFont;
        property ParentShowHint;
        property PasswordChar;
        property PopupMenu;
        property ReadOnly;
        property ShowHint;
        property TabOrder;
        property TabStop;
        property Visible;
        property OnChange;
        property OnClick;
        property OnContextPopup;
        property OnDblClick;
        property OnDragDrop;
        property OnDragOver;
        property OnEndDock;
        property OnEndDrag;
        property OnEnter;
        property OnExit;
        property OnKeyDown;
        property OnKeyPress;
        property OnKeyUp;
        property OnMouseDown;
        property OnMouseMove;
        property OnMouseUp;
        property OnStartDock;
        property OnStartDrag;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('rainbowsoft', [TNumberEdit]);
    end;{ TNumberEdit }constructor TNumberEdit.Create(AOwner: TComponent);
    begin
      inherited;
      FValue := 1;
    end;procedure TNumberEdit.KeyPress(var Key: Char);
    begin
      inherited;
      if (not (Key in ['0'..'9'])) and (Key <> #8) then
        Key := #0
      else
        SetValue(StrToInt(Text));
    end;procedure TNumberEdit.SetValue(Value: integer);
    begin
      if Value <> FValue then
      begin
        FValue := Value;
        Text := IntToStr(Value);
      end;
    end;end.
      

  9.   

    举TEdit只是一个例子,其实我是从DBLookupCombobox继承下来的。
    有些Property对我根本无意义,我又屏蔽不了。想重载某些Property,又不得要领。对不起公司上不了OICQ。能给留个mail吧!我再加分!
      

  10.   

    从TCustomEdit派生,不要在published下写property Text;即可
      

  11.   

    TDBLookupComboBox确定不好弄,因为没有TCustomDBLookupComboBox。有一个小办法:你覆盖掉不要用的属性后,让新属性没有用处就是了。如:
    TMyDBLookupComboBox = class(TDBLookupComboBox)
    published
      property SameProperty: datatype read FSameProperty write FSameProperty;
    end;在程序中不用它,甚至可以用SetSameProperty,然后在里面出异常:“这个属性已经没有用了。”呵呵
      

  12.   

    从TDBLookupControl中继承一个,你可以看一个TDBLookupCombobox的源代码,不需要的属性不要公布出来,其它的Copy/Paste了。当然,如果你自己增加了属性,就要写代码了。
      

  13.   

    阿贵试过能覆盖吗?我怎么覆盖后编译时就出致命错?TMyDBLookupComboBox = Class(TDBLookupComboBox)
    Published
      Property Text : String Read GetText write SetText;
    ...如此这般,将编译好的组件放到面板上Delphi立即Down掉,推理可能是因为重载了Text(我不知这能不能叫做重载),而把Property Text 改成Property theText就没有问题!
      

  14.   

    属性不能重载是吗,就是说我只能用value代替Text,而不能有我自己的Text罗?
      

  15.   

    要用你自己的Text,就从TDBLookupControl继承一个,然后把TDBLookupCombobox的代码copy过来.要如何操作你的Text属性就要自已写代码了。
      

  16.   

    bisc_sunny(中子):对不起,你结了贴子我才来看的,我试过了,没有出现你说的错误,完全好用。我用的是D5