A
arraiy
Unregistered / Unconfirmed
GUEST, unregistred user!
自己写的一个控件,它有一个对象属性和其他一些基本属性,为什么对象属性前面有“+”号,但打开没内容呢?
这些属性都可以在对象浏览器里面看到,对象属性前面也有“+”号,但就是点了加号后打不开里面的其他下级属性,本来那个对象是有其他可见属性的,是什么问题啊?
那个对象属性的属性是定义在published里的,下面是代码,大家帮我看看:
1、对象类型
unit CnyParameters;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics;
type
TCnyParameters = class(TPersistent)
private
FDecimalSeparatorColor: TColor; //小数分界线颜色
FDecimalNumber: integer; //小数位数
FDecimalSymbols: string; //小数位标识符号
protected
procedure SetDecimalNumber(const Value: integer);
procedure SetDecimalSymbols(const Value: string);
procedure SetDecimalSeparatorColor(Value: TColor);
public
procedure Assign(Source: TPersistent); override;
published
property DecimalSeparatorColor: TColor read FDecimalSeparatorColor write SetDecimalSeparatorColor default clRed;
property DecimalNumber: integer read FDecimalNumber write SetDecimalNumber default 2;
property DecimalSymbols: string read FDecimalSymbols write SetDecimalSymbols;
end;
implementation
{ TCnyParameters }
procedure TCnyParameters.Assign(Source: TPersistent);
begin
inherited;
if Source is TCnyParameters then
begin
FDecimalSeparatorColor := TCnyParameters(Source).FDecimalSeparatorColor;
FDecimalNumber := TCnyParameters(Source).FDecimalNumber;
FDecimalSymbols := TCnyParameters(Source).FDecimalSymbols;
end
else inherited Assign(Source);
end;
procedure TCnyParameters.SetDecimalNumber(const Value: integer);
begin
FDecimalNumber := Value;
end;
procedure TCnyParameters.SetDecimalSeparatorColor(Value: TColor);
begin
FDecimalSeparatorColor := Value;
end;
procedure TCnyParameters.SetDecimalSymbols(const Value: string);
begin
FDecimalSymbols := Value;
end;
end.
2、控件的代码
unit DBGridEhHw;
interface
uses
windows, Messages, SysUtils, Classes, Controls, Graphics, Grids, DBGridEh, DBGrids, PrnDbgeh,
Dialogs, Menus, ExtCtrls, Forms, DB, adodb, CnyParameters;
type
TColumnHit = record
count: integer; //记录金额栏数
ColumnName: string; //记录Column的标题
end;
TDBGridEhHw = class(TDBGridEh)
private
{ Private declarations }
FShowLineNo: boolean;
FCurrencyOptions: TCnyParameters;
function GetShowLineNo: boolean;
procedure SetShowLineNo(Value: Boolean);
procedure GetCurrencyOptions(const Value: TCnyParameters);
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor destroy; override;
published
property VShowLineNo: boolean read GetShowLineNo write SetShowLineNo default False;
property VCurrencyOptions: TCnyParameters read FCurrencyOptions write FCurrencyOptions;
{ Published declarations }
end;
procedure Register;
implementation
{$R DBGridEhHw.dcr}
procedure TDBGridEhHw.GetCurrencyOptions(const Value: TCnyParameters);
begin
FCurrencyOptions.Assign(Value);
end;
procedure TDBGridEhHw.SetShowLineNo(Value: Boolean);
begin
if Value <> FShowLineNo then
begin
FShowLineNo := Value;
Update;
end;
end;
function TDBGridEhHw.GetShowLineNo: boolean;
begin
Result := FShowLineNo;
end;
constructor TDBGridEhHw.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
SetShowLineNo(False);
end;
procedure TDBGridEhHw.Loaded;
{该事件是当一个组件初始化完成之后触发}
begin
inherited;
//...
end;
destructor TDBGridEhHw.destroy;
begin
//..
inherited destroy;
end;
procedure Register;
begin
RegisterComponents('Test', [TDBGridEhHw]);
end;
end.
上面的代码里面VCurrencyOptions是一个对象,本身它还有三个属性,现在控件可以编译,可以安装,但就是不显示VCurrencyOptions它的下级三个属性,只可以看到那个加号。
这些属性都可以在对象浏览器里面看到,对象属性前面也有“+”号,但就是点了加号后打不开里面的其他下级属性,本来那个对象是有其他可见属性的,是什么问题啊?
那个对象属性的属性是定义在published里的,下面是代码,大家帮我看看:
1、对象类型
unit CnyParameters;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics;
type
TCnyParameters = class(TPersistent)
private
FDecimalSeparatorColor: TColor; //小数分界线颜色
FDecimalNumber: integer; //小数位数
FDecimalSymbols: string; //小数位标识符号
protected
procedure SetDecimalNumber(const Value: integer);
procedure SetDecimalSymbols(const Value: string);
procedure SetDecimalSeparatorColor(Value: TColor);
public
procedure Assign(Source: TPersistent); override;
published
property DecimalSeparatorColor: TColor read FDecimalSeparatorColor write SetDecimalSeparatorColor default clRed;
property DecimalNumber: integer read FDecimalNumber write SetDecimalNumber default 2;
property DecimalSymbols: string read FDecimalSymbols write SetDecimalSymbols;
end;
implementation
{ TCnyParameters }
procedure TCnyParameters.Assign(Source: TPersistent);
begin
inherited;
if Source is TCnyParameters then
begin
FDecimalSeparatorColor := TCnyParameters(Source).FDecimalSeparatorColor;
FDecimalNumber := TCnyParameters(Source).FDecimalNumber;
FDecimalSymbols := TCnyParameters(Source).FDecimalSymbols;
end
else inherited Assign(Source);
end;
procedure TCnyParameters.SetDecimalNumber(const Value: integer);
begin
FDecimalNumber := Value;
end;
procedure TCnyParameters.SetDecimalSeparatorColor(Value: TColor);
begin
FDecimalSeparatorColor := Value;
end;
procedure TCnyParameters.SetDecimalSymbols(const Value: string);
begin
FDecimalSymbols := Value;
end;
end.
2、控件的代码
unit DBGridEhHw;
interface
uses
windows, Messages, SysUtils, Classes, Controls, Graphics, Grids, DBGridEh, DBGrids, PrnDbgeh,
Dialogs, Menus, ExtCtrls, Forms, DB, adodb, CnyParameters;
type
TColumnHit = record
count: integer; //记录金额栏数
ColumnName: string; //记录Column的标题
end;
TDBGridEhHw = class(TDBGridEh)
private
{ Private declarations }
FShowLineNo: boolean;
FCurrencyOptions: TCnyParameters;
function GetShowLineNo: boolean;
procedure SetShowLineNo(Value: Boolean);
procedure GetCurrencyOptions(const Value: TCnyParameters);
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor destroy; override;
published
property VShowLineNo: boolean read GetShowLineNo write SetShowLineNo default False;
property VCurrencyOptions: TCnyParameters read FCurrencyOptions write FCurrencyOptions;
{ Published declarations }
end;
procedure Register;
implementation
{$R DBGridEhHw.dcr}
procedure TDBGridEhHw.GetCurrencyOptions(const Value: TCnyParameters);
begin
FCurrencyOptions.Assign(Value);
end;
procedure TDBGridEhHw.SetShowLineNo(Value: Boolean);
begin
if Value <> FShowLineNo then
begin
FShowLineNo := Value;
Update;
end;
end;
function TDBGridEhHw.GetShowLineNo: boolean;
begin
Result := FShowLineNo;
end;
constructor TDBGridEhHw.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
SetShowLineNo(False);
end;
procedure TDBGridEhHw.Loaded;
{该事件是当一个组件初始化完成之后触发}
begin
inherited;
//...
end;
destructor TDBGridEhHw.destroy;
begin
//..
inherited destroy;
end;
procedure Register;
begin
RegisterComponents('Test', [TDBGridEhHw]);
end;
end.
上面的代码里面VCurrencyOptions是一个对象,本身它还有三个属性,现在控件可以编译,可以安装,但就是不显示VCurrencyOptions它的下级三个属性,只可以看到那个加号。