【发布时间】:2015-08-29 21:34:03
【问题描述】:
我在创建查找组件时遇到问题。
我会再试一次...把图片方便...。
不保存 dfm 中的属性值...为什么,我的属性被分组在一个类中...如果它们“松散”,将执行 setter 方法...
我的疑问是……为什么不跑?
谢谢你...
我的属性类别
TLookupProperties = class(TPersistent)
private
FDataCharCase: TEditCharCase;
FOnLookupBeforeSearch: TNotifyEvent;
FDataSource: TDataSource;
FOnButtonClick: TNotifyEvent;
FDataTabela: string;
FOnExit: TNotifyEvent;
FDataCondicao: string;
FDataFieldDescricao: string;
FDataFieldCodigo: string;
FOnLookupValidate: TNotifyEvent;
FDataFieldID: String;
published
property OnLookupBeforeSearch: TNotifyEvent read FOnLookupBeforeSearch write FOnLookupBeforeSearch;
property OnLookupExit: TNotifyEvent read FOnExit write FOnExit;
property OnLookupButtonClick: TNotifyEvent read FOnButtonClick write FOnButtonClick;
property OnLookupValidate: TNotifyEvent read FOnLookupValidate write FOnLookupValidate;
property DataSource: TDataSource read FDataSource write FDataSource;
property DataFieldID: String read FDataFieldID write FDataFieldID;
property DataFieldCodigo: string read FDataFieldCodigo write FDataFieldCodigo;
property DataFieldDescricao: string read FDataFieldDescricao write FDataFieldDescricao;
property Condicao: string read FDataCondicao write FDataCondicao;
property Tabela: string read FDataTabela write FDataTabela;
property CharCase: TEditCharCase read FDataCharCase write FDataCharCase;
end;
我的组件
TDBLookupFrame = class(TFrame)
PnlTotal: TPanel;
btnButton: TSpeedButton;
edtCodigo: TDBEdit;
lblDescricao: TDBText;
procedure edtCodigoExit(Sender: TObject);
procedure btnButtonClick(Sender: TObject);
procedure edtCodigoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure edtCodigoKeyPress(Sender: TObject; var Key: Char);
strict private
procedure SetarResult(AZerar: Boolean = False);
procedure Validar(Sender: TObject);
private
FLookupView: TLookupView;
FLookupProperties: TLookupProperties;
procedure SetLookupProperties(const Value: TLookupProperties);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property LookupProperties: TLookupProperties read FLookupProperties write SetLookupProperties;
end;
procedure register;
implementation
uses System.SysUtils;
{$R *.dfm}
procedure register;
begin
RegisterComponents('Hebran',[TDBLookupFrame]);
end;
procedure TDBLookupFrame.SetLookupProperties(const Value: TLookupProperties);
begin
FLookupProperties := Value;
edtCodigo.CharCase := FLookupProperties.CharCase;
FLookupView.Tabela := FLookupProperties.Tabela;
FLookupView.CondicaoAdicional := FLookupProperties.Condicao;
if Assigned(FLookupProperties.DataSource) then
begin
edtCodigo.DataSource := FLookupProperties.DataSource;
lblDescricao.DataSource := FLookupProperties.DataSource;
FLookupProperties.DataFieldDescricao := FLookupProperties.DataFieldCodigo;
lblDescricao.DataField := FLookupProperties.DataFieldDescricao;
end;
end;
constructor TDBLookupFrame.Create(AOwner: TComponent);
begin
inherited;
FLookupView := TLookupView.Create(Nil);
FLookupProperties := TLookupProperties.Create;
LookupProperties.Condicao := '';
LookupProperties.CharCase := ecNormal;
end;
【问题讨论】:
-
这显然不是你的全部代码。请将其余代码添加到 q;不要指望读者猜测你遗漏的部分是什么。同时,-1。顺便说一句,我已经删除了不相关的“注册商”标签。
-
感谢您添加更多代码。你也可以显示
TDBLookupFrame和SetLookupProperties的构造函数吗?您也可以删除register,因为它与您的问题完全无关。 -
感谢您的帮助...我已经习惯了这个板...我的英语很糟糕
-
SetLookupProperties应该只是一个简单的单行FLookupProperties.Assign(Value);然后TLookupProperties应该覆盖Assign过程。不过,还不完全确定这是否是您的问题。 -
它的实现方式,数值保存在dfm中,但是,使用组件时关闭Delphi ...重新打开错误..."读取DBLookupFrame.LookupProperties.DataSource时出错不存在”...看来我需要注册 LookupProperties ...一些东西...
标签: delphi