A
acheng_wh
Unregistered / Unconfirmed
GUEST, unregistred user!
请各位帮我看一下,为什么Properties子属性在设计模式下面没有???
没写过控件,所以找不出问题所在
我想要做的是:
在原TcxDBTextEdit控件的Properties属性下添加扩展
DecimalPlaces: Integer
DisplayFormat: string
MaxValue: Double
property MinValue: Double 等属性
并且在原OnKeyPress事件里加上默认的控制事件代码
--------------------------------------------------------------------------
unit cxDBNumericEdit;
interface
uses
SysUtils, Classes, Controls, cxControls, cxContainer, cxEdit, cxTextEdit,
cxDBEdit;
type
TcxNumericEditProperties = class(TcxTextEditProperties)
private
FDecimalPlaces: Integer;
FDisplayFormat: string;
FMaxValue: Double;
FMinValue: Double;
FNullString: string;
protected
public
published
property DecimalPlaces: Integer read FDecimalPlaces write FDecimalPlaces;
property DisplayFormat: string read FDisplayFormat write FDisplayFormat;
property MaxValue: Double read FMaxValue write FMaxValue;
property MinValue: Double read FMinValue write FMinValue;
property NullString: string read FNullString write FNullString;
end;
type
TcxDBNumericEdit = class(TcxDBTextEdit)
private
FOnKeyPress: TKeyPressEvent;
FProperties: TcxNumericEditProperties;
procedure DoKeyPress(Sender: TObject; var Key: Char);
{ Private declarations }
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ Public declarations }
published
property Properties: TcxNumericEditProperties read FProperties write
FProperties;
property OnKeyPress: TKeyPressEvent read FOnKeyPress write FOnKeyPress;
{ Published declarations }
end;
procedure Register;
implementation
constructor TcxDBNumericEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Self.OnKeyPress := Self.DoKeyPress;
end;
destructor TcxDBNumericEdit.Destroy;
begin
inherited Destroy;
end;
procedure TcxDBNumericEdit.DoKeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', '.', #8]) then
Key := #0;
//控制整数位数
if Pos('.', TcxDBNumericEdit(Sender).Text) = 0 then
if ((Key in ['0'..'9']) and (Length(TcxDBNumericEdit(Sender).Text) >= 6))
then
key := #0;
//如果已经存在小数点了
if ((key = '.') and (Pos('.', TcxDBNumericEdit(Sender).Text) > 0)) then
Key := #0;
//控制小数点位数
if Pos('.', TcxDBNumericEdit(Sender).Text) > 0 then
begin
if ((Key in ['0'..'9']) and ((Length(TcxDBNumericEdit(Sender).Text) -
Pos('.', TcxDBNumericEdit(Sender).Text)) >=
TcxDBNumericEdit(Sender).Properties.DecimalPlaces)) then
Key := #0;
end;
if Assigned(FOnKeyPress) then
FOnKeyPress(Self, Key);
end;
procedure Register;
begin
RegisterComponents('Express DBEditors 4', [TcxDBNumericEdit]);
end;
end.
-------------------------------------------------------------------------
谢谢!
没写过控件,所以找不出问题所在
我想要做的是:
在原TcxDBTextEdit控件的Properties属性下添加扩展
DecimalPlaces: Integer
DisplayFormat: string
MaxValue: Double
property MinValue: Double 等属性
并且在原OnKeyPress事件里加上默认的控制事件代码
--------------------------------------------------------------------------
unit cxDBNumericEdit;
interface
uses
SysUtils, Classes, Controls, cxControls, cxContainer, cxEdit, cxTextEdit,
cxDBEdit;
type
TcxNumericEditProperties = class(TcxTextEditProperties)
private
FDecimalPlaces: Integer;
FDisplayFormat: string;
FMaxValue: Double;
FMinValue: Double;
FNullString: string;
protected
public
published
property DecimalPlaces: Integer read FDecimalPlaces write FDecimalPlaces;
property DisplayFormat: string read FDisplayFormat write FDisplayFormat;
property MaxValue: Double read FMaxValue write FMaxValue;
property MinValue: Double read FMinValue write FMinValue;
property NullString: string read FNullString write FNullString;
end;
type
TcxDBNumericEdit = class(TcxDBTextEdit)
private
FOnKeyPress: TKeyPressEvent;
FProperties: TcxNumericEditProperties;
procedure DoKeyPress(Sender: TObject; var Key: Char);
{ Private declarations }
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ Public declarations }
published
property Properties: TcxNumericEditProperties read FProperties write
FProperties;
property OnKeyPress: TKeyPressEvent read FOnKeyPress write FOnKeyPress;
{ Published declarations }
end;
procedure Register;
implementation
constructor TcxDBNumericEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Self.OnKeyPress := Self.DoKeyPress;
end;
destructor TcxDBNumericEdit.Destroy;
begin
inherited Destroy;
end;
procedure TcxDBNumericEdit.DoKeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', '.', #8]) then
Key := #0;
//控制整数位数
if Pos('.', TcxDBNumericEdit(Sender).Text) = 0 then
if ((Key in ['0'..'9']) and (Length(TcxDBNumericEdit(Sender).Text) >= 6))
then
key := #0;
//如果已经存在小数点了
if ((key = '.') and (Pos('.', TcxDBNumericEdit(Sender).Text) > 0)) then
Key := #0;
//控制小数点位数
if Pos('.', TcxDBNumericEdit(Sender).Text) > 0 then
begin
if ((Key in ['0'..'9']) and ((Length(TcxDBNumericEdit(Sender).Text) -
Pos('.', TcxDBNumericEdit(Sender).Text)) >=
TcxDBNumericEdit(Sender).Properties.DecimalPlaces)) then
Key := #0;
end;
if Assigned(FOnKeyPress) then
FOnKeyPress(Self, Key);
end;
procedure Register;
begin
RegisterComponents('Express DBEditors 4', [TcxDBNumericEdit]);
end;
end.
-------------------------------------------------------------------------
谢谢!