我的代码如下:
TParaHandels = class(TGraphicsObject)
private
FIDHandel: Integer;
FNameHandel: String;
//设置ID
procedure SetIDHandel(const sValue: Integer);
//设置Name
procedure SetNameHandel(const sValue: String);
protected
public
published
property IDHandel: Integer Read FIDHandel Write SetIDHandel;
property NameHandel: String Read FNameHandel Write SetNameHandel;
end; TWjqLabel = class(TCustomLabel)
private
{ Private declarations }
FParaHandels: TParaHandels;
//设置参数
procedure SetParaHandels(const sValue: TParaHandels);
published
{ Published declarations }
property ParaHandel:TParaHandels Read FParaHandels Write SetParaHandels;
end;//构造函数
constructor TWjqLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner); FParaHandels := TParaHandels.Create;
end;
为什么我的ParaHandel属性点击加号没有下拉的两个IDHandel和NameHandel属性呢?
还有第二个问题:
怎样子在我的ParaHandel属性有一个按钮出现呢?就是点击那个属性会出现一个三个点的按钮,
然后怎样点击那个按钮触发我写的一个过程或函数呢?
TParaHandels = class(TGraphicsObject)
private
FIDHandel: Integer;
FNameHandel: String;
//设置ID
procedure SetIDHandel(const sValue: Integer);
//设置Name
procedure SetNameHandel(const sValue: String);
protected
public
published
property IDHandel: Integer Read FIDHandel Write SetIDHandel;
property NameHandel: String Read FNameHandel Write SetNameHandel;
end; TWjqLabel = class(TCustomLabel)
private
{ Private declarations }
FParaHandels: TParaHandels;
//设置参数
procedure SetParaHandels(const sValue: TParaHandels);
published
{ Published declarations }
property ParaHandel:TParaHandels Read FParaHandels Write SetParaHandels;
end;//构造函数
constructor TWjqLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner); FParaHandels := TParaHandels.Create;
end;
为什么我的ParaHandel属性点击加号没有下拉的两个IDHandel和NameHandel属性呢?
还有第二个问题:
怎样子在我的ParaHandel属性有一个按钮出现呢?就是点击那个属性会出现一个三个点的按钮,
然后怎样点击那个按钮触发我写的一个过程或函数呢?
解决方案 »
- delphi小秘密:about窗口同时按alt+team,实现这个功能的代码
- 日期类型。数据为空时怎么办?
- web service 中用web dataModule的问题
- 要怎样用DecisionGrid实现交叉表的功能呢
- 还是trichedit的中文双引号问题!
- 急!在线等待............由于安装了第三方控件(FormulaOne,即F1Book6.1)!程序不打包,想直接使用!在新系统环境中则不能运行!报"没有注册类
- 为什么我在用AdoDataset进行数据刷新时,会提示错误信息?
- 怎麼辦啊!
- 在dll中如何使用TServerSocket 编写服务器程序?
- 关于CreateThread多线程的内存管理
- FRM_MAIN显示以后,再SHOWMODAL FRM_LOGIN,LOGIN成功后,才可以在FRM_MAIN上操作,这样可以实现吗?
- 求一条SQL语句,相同记录的查找与删除。
SetParaHandels//内部一般要用对象复复制Assign实现,而不用对象引用第二个问题,你的意思应该是说事件的实现,其实事件实现起来很简单。主要理解了事件其实是指针,是由外部调用的给它付值。看看DELPH里面现在的控件都有源码,参考一下是如何实现得
还有一个问题帮看看能不能解决,就是在设计期的时候我改变属性的值,我那个属性是Integer类型的,为什么在属性编辑器里的那个属性的值不会变化呢,但是我在程序里用ShowMessage出来的值已经变了,在属性编辑器中的值就是不会变,怎么回事呢?是不是还要做一些什么处理?
private
FIDHandel: Integer;
FNameHandel: String;
//设置ID
procedure SetIDHandel(const sValue: Integer);
//设置Name
procedure SetNameHandel(const sValue: String);
protected
public
//覆盖这个方法,主要实现对象复制时,把FIDHandel,FNameHandel值也要复制上
procedure Assign(Source: TPersistent); override;
published
property IDHandel: Integer Read FIDHandel Write SetIDHandel;
property NameHandel: String Read FNameHandel Write SetNameHandel;
end;
我现在改成这样子:
TWjqLabel = class(TLabel)
private
//获取ID
FIDHandel: Integer;
//设置ID
procedure SetIDHandel(const sValue: Integer);
public
//覆盖这个方法,主要实现对象复制时,把FIDHandel,FNameHandel值也要复制上
procedure Assign(Source: TPersistent); override;实现代码:
//覆盖这个方法,主要实现对象复制时,把FIDHandel,FNameHandel值也要复制上
procedure TWjqLabel.Assign(Source: TPersistent);
begin
FIDHandel := Source.XXX;//这个Source不是我那个TWjqLabel类,所以没有FIDHandel属性
这样又怎么办呢?
end;//另一个类里面改变属性值
procedure TCE.Edit;
begin
try
pWjqLabel := TWjqLabel.Create(pWjqLabel);
if(Assigned(pWjqLabel))then
pWjqLabel.CreateMyForm;
pWjqLabel.IDHandel := 11;
pWjqLabel.Assign(pWjqLabel);
finally
FreeAndNil(pWjqLabel);
end;
end;
//覆盖这个方法,主要实现对象复制时,把FIDHandel,FNameHandel值也要复制上
procedure TWjqLabel.Assign(Source: TPersistent);
begin
FIDHandel := Source.XXX;//这个Source不是我那个TWjqLabel类,所以没有FIDHandel属性
这样又怎么办呢?
end;改为:
实现代码:
//覆盖这个方法,主要实现对象复制时,把FIDHandel,FNameHandel值也要复制上
procedure TWjqLabel.Assign(Source: TPersistent);
begin
inherited Assign(Source);
end;但是这句pWjqLabel.Assign(pWjqLabel);肯定是有问题了,怎么改呢,帮个忙,我很菜的了.
怎么换成TWjqLabel = class(TLabel)了。
你不要乱用Assign
对象Assign方法主要于内含对象这种情况,就是说对象中,还有对象。例如:
ComboBox1中内含有Items
ComboBox1.Items.Assign(AStringList);内含对象一般不是可视化控件。至于Source: TPersistent是抽象类型,后代的有些属性不能直接用,一般这样处理
if Source is TSomeObject then
begin
FValue1:=TSomeObject(Source).Value1;
FValue2:=TSomeObject(Source).Value2;
inherited Assign(Source);
end;
还是搞不定,晕!!!!
我的代码如下,你看看有什么问题:
TParaHandels = class(TGraphicsObject)
private
FIDHandel: Integer;
FNameHandel: String;
//设置ID
procedure SetIDHandel(const sValue: Integer);
//设置Name
procedure SetNameHandel(const sValue: String);
protected
public
constructor Create;
destructor Destroy; override;
//覆盖这个方法,主要实现对象复制时,把FIDHandel,FNameHandel值也要复制上
procedure Assign(Source: TPersistent); override;
published
//ID
property IDHandel: Integer Read FIDHandel Write SetIDHandel;
//Name
property NameHandel: String Read FNameHandel Write SetNameHandel;
end;TWjqLabel = class(TLabel)
private
FParaHandels: TParaHandels;
//设置ID、Name值
procedure SetParaHandels(const aValue: TParaHandels);
published
{ Published declarations }
property IDHandel: TParaHandels Read FParaHandels Write SetParaHandels;实现代码:
TParaHandels类:
//设置ID
procedure TParaHandels.SetIDHandel(const sValue: Integer);
begin
if(sValue <> FIDHandel)then
FIDHandel := sValue;
end;//设置Name
procedure TParaHandels.SetNameHandel(const sValue: String);
begin
if(sValue <> FNameHandel)then
FNameHandel := sValue;
end;//覆盖这个方法,主要实现对象复制时,把FIDHandel,FNameHandel值也要复制上
procedure TParaHandels.Assign(Source: TPersistent);
begin
inherited Assign(Source);
end;TWjqLabel类:
//设置ID、Name值
procedure TWjqLabel.SetParaHandels(const aValue: TParaHandels);
begin
FParaHandels.Assign(aValue);
end;
procedure TParaHandels.Assign(Source: TPersistent);
begin
if Source is TParaHandels then
begin
FIDHandel:=TParaHandels(Source).IDHandel;
FNameHandel:=TParaHandels(Source).NameHandel
inherited Assign(Source);
end;
end;
有错误的“Cannot assign a TParahandels to a TParaHandels“我的属性赋值代码是这样子:FParaHandels: TParaHandels;
property IDHandel: TParaHandels Read FParaHandels Write SetParaHandels;if(Trim(pComboBox1.Text) <> '')then
begin
FParaHandels.FIDHandel := StrToInt(Trim(pCombobox1.Text));
FParaHandels.FNameHandel := 'NameHadnel';
Self.IDHandel := FParaHandels;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DesignEditors;type
TParaHandels = class(TGraphicsObject)
private
FIDHandel: Integer;
FNameHandel: string;
//设置ID
procedure SetIDHandel(const sValue: Integer);
//设置Name
procedure SetNameHandel(const sValue: string);
protected
public
//覆盖这个方法,主要实现对象复制时,把FIDHandel,FNameHandel值也要复制上
procedure Assign(Source: TPersistent); override;
published
property IDHandel: Integer read FIDHandel write SetIDHandel;
property NameHandel: string read FNameHandel write SetNameHandel;
end; TWjqLabel = class(TCustomLabel)
private
{ Private declarations }
FParaHandels: TParaHandels;
//设置参数
procedure SetParaHandels(const sValue: TParaHandels);
function GetParaHandels: TParaHandels;
published
{ Published declarations }
property ParaHandel: TParaHandels read GetParaHandels write SetParaHandels;
end;
{要想编辑对象属性,如果没有兼容的属性编辑器,则需要自己去实现
TParaHandelsEdit=class(TClassProperty)
...
...
end; }procedure Register;
implementation{ TParaHandels }procedure TParaHandels.Assign(Source: TPersistent);
begin
if Source is TParaHandels then
begin
FIDHandel := TParaHandels(Source).IDHandel;
FNameHandel := TParaHandels(Source).NameHandel;
inherited Assign(Source);
end;end;procedure TParaHandels.SetIDHandel(const sValue: Integer);
begin
if FIDHandel <> sValue then
FIDHandel := sValue;
end;procedure TParaHandels.SetNameHandel(const sValue: string);
begin
if FNameHandel <> sValue then
FNameHandel := sValue;
end;{ TWjqLabel }function TWjqLabel.GetParaHandels: TParaHandels;
begin
Result := FParaHandels;
end;procedure TWjqLabel.SetParaHandels(const sValue: TParaHandels);
begin
FParaHandels.Assign(sValue);
end;procedure Register;
begin
RegisterComponents('Samples', [TWjqLabel]);
end;end.
还是有错误的“Cannot assign a TParahandels to a TParaHandels“
代码和你的一模一样,我都对过两次了。