继承自VCL可视类的新类,如何改变他们的Property,或隐藏一些Property? //什么叫重载Edit的Text属性type TMyEdit=class(TCustomEdit) private public published //这里可屏蔽Text属性 end; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看看这个或许有好处:http://www.csdn.net/expert/topic/129/129319.shtm 简单地说,我从TEdit继承下来一个新的类,这样这个类就在Object Inspector中有所有原TEdit的属性。我如何能使之变成自己的属性,或只是不让他们出来?taxt能否给个例子,难道我需要在published中一一写遍所有的Property?如果我只是不想让他们出来,我又该如何做? 将原来的publish 改为public,另外写一个publish,在那下面列出你要显示的属性。 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; >>难道我需要在published中一一写遍所有的Property?我想这样做是必须的你用Copy-Past就好了,又不麻烦 事实是,我如果不在Published里写,属性仍会自己出来。我不想让他出来该怎么办?而且taxi兄是用的Value来代替Text,而不是覆盖原有的Text。不妨看看编译后的组件,Text属性仍在Object Inspector中,这不是我想要的。大家有没有试过覆盖原有的属性,那样编译成组件后我的Delphi6+SP1就会立即退出,什么提示也没有!What shall I do? 从TCustomEdit派生一个控件,属性缺省是保护的,把想要的公开就行了 我试了一个,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. 举TEdit只是一个例子,其实我是从DBLookupCombobox继承下来的。有些Property对我根本无意义,我又屏蔽不了。想重载某些Property,又不得要领。对不起公司上不了OICQ。能给留个mail吧!我再加分! 从TCustomEdit派生,不要在published下写property Text;即可 TDBLookupComboBox确定不好弄,因为没有TCustomDBLookupComboBox。有一个小办法:你覆盖掉不要用的属性后,让新属性没有用处就是了。如:TMyDBLookupComboBox = class(TDBLookupComboBox)published property SameProperty: datatype read FSameProperty write FSameProperty;end;在程序中不用它,甚至可以用SetSameProperty,然后在里面出异常:“这个属性已经没有用了。”呵呵 从TDBLookupControl中继承一个,你可以看一个TDBLookupCombobox的源代码,不需要的属性不要公布出来,其它的Copy/Paste了。当然,如果你自己增加了属性,就要写代码了。 阿贵试过能覆盖吗?我怎么覆盖后编译时就出致命错?TMyDBLookupComboBox = Class(TDBLookupComboBox)Published Property Text : String Read GetText write SetText;...如此这般,将编译好的组件放到面板上Delphi立即Down掉,推理可能是因为重载了Text(我不知这能不能叫做重载),而把Property Text 改成Property theText就没有问题! 属性不能重载是吗,就是说我只能用value代替Text,而不能有我自己的Text罗? 要用你自己的Text,就从TDBLookupControl继承一个,然后把TDBLookupCombobox的代码copy过来.要如何操作你的Text属性就要自已写代码了。 bisc_sunny(中子):对不起,你结了贴子我才来看的,我试过了,没有出现你说的错误,完全好用。我用的是D5 delphi操作ie收藏夹? 如何在保存数据的时候,依然能够操作界面? 求火星文转换器源代码(或火星文字库)! 到度是谁的错?92*2.17=199.63!! 高分求教,如何实现这样的功能? 新手求助超级简单问题(form弹出问题) 请问怎么改变delphi自动完成功能的快捷键? 那里有d6的补丁下载,一定要下载才行啊。 "Invalid floating point operation"怎么回事? 各位,请帮我解决这个问题,不然我整个系统没法进行. 怎样让dbcgrids控件背景透明? 这样是否可行?
看看这个或许有好处:http://www.csdn.net/expert/topic/129/129319.shtm
TEdit的属性。我如何能使之变成自己的属性,或只是不让他们出来?taxt能否给个例子,难道我需要在published中一一写遍所有的Property?如果我只是不想让他们出来,我又该如何做?
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;
我想这样做是必须的
你用Copy-Past就好了,又不麻烦
而且taxi兄是用的Value来代替Text,而不是覆盖原有的Text。不妨看看编译后的组件,
Text属性仍在Object Inspector中,这不是我想要的。大家有没有试过覆盖原有
的属性,那样编译成组件后我的Delphi6+SP1就会立即退出,什么提示也没有!What shall I do?
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.
有些Property对我根本无意义,我又屏蔽不了。想重载某些Property,又不得要领。对不起公司上不了OICQ。能给留个mail吧!我再加分!
TMyDBLookupComboBox = class(TDBLookupComboBox)
published
property SameProperty: datatype read FSameProperty write FSameProperty;
end;在程序中不用它,甚至可以用SetSameProperty,然后在里面出异常:“这个属性已经没有用了。”呵呵
Published
Property Text : String Read GetText write SetText;
...如此这般,将编译好的组件放到面板上Delphi立即Down掉,推理可能是因为重载了Text(我不知这能不能叫做重载),而把Property Text 改成Property theText就没有问题!