【发布时间】:2021-04-18 06:21:30
【问题描述】:
您好,我正在尝试使用数据库 (AbsoluteDB) 来填充 HTML div。表字段包括“标题”和“描述”等名称。我的 DBEdit 组件有 2 个额外的属性“Pre”和“Suff”以及一个 var“Full”。在设计时,我会填写额外的属性,例如
“Pre”值为
在运行时,onchange 事件将用“Pre”+Field.Value+“Suff”填充“Full”。
组件(下面的代码)可以编译,但是当我在设计时将组件添加到我的表单时,我会收到此错误消息。我正在使用 Delphi 7:
模块“dbrtl70.bpl”中地址 40341575 的访问冲突。读取地址 000000D2。
unit PrefEdDb;
interface
uses WinTypes, WinProcs, Messages, SysUtils, Classes, Controls,
Forms, Graphics, Dbctrls, Windows, ExtCtrls, StdCtrls, Variants;
type
TPrefEdDb = class(TDBEdit)
private
FPre : String;
FSuff : String;
procedure AutoInitialize;
procedure AutoDestroy;
function GetPre : String;
procedure SetPre(Value : String);
function GetSuff : String;
procedure SetSuff(Value : String);
function DoFull:string;
protected
procedure Change; override;
procedure Click; override;
procedure DoExit; override;
procedure KeyPress(var Key : Char); override;
procedure Loaded; override;
public
Full : String;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property Pre : String read GetPre write SetPre;
property Suff : String read GetSuff write SetSuff;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TPrefEdDb]);
end;
function TPrefEdDb.DoFull:string;
var
s:string;
begin
result:='';
if ((Field.Text<>'') or (Field.Value<>null)) then
begin
s:='';
if FPre<>'' then s:=FPre;
s:=s+field.Text;
if FSuff<>'' then s:=s+FSuff;
Result:=s;
end;
end;
procedure TPrefEdDb.AutoInitialize;
begin
Full := '';
FPre := '';
FSuff := '';
end;
procedure TPrefEdDb.AutoDestroy;
begin
{ No objects from AutoInitialize to free }
end;
function TPrefEdDb.GetPre : String;
begin
Result := FPre;
end;
procedure TPrefEdDb.SetPre(Value : String);
begin
FPre := Value;
end;
function TPrefEdDb.GetSuff : String;
begin
Result := FSuff;
end;
procedure TPrefEdDb.SetSuff(Value : String);
begin
FSuff := Value;
end;
procedure TPrefEdDb.Change;
begin
inherited Change;
if Field.Text<>'' then Full:=DoFull;
end;
procedure TPrefEdDb.Click;
begin
inherited Click;
end;
procedure TPrefEdDb.DoExit;
begin
inherited DoExit;
end;
procedure TPrefEdDb.KeyPress(var Key : Char);
const
TabKey = Char(VK_TAB);
EnterKey = Char(VK_RETURN);
begin
inherited KeyPress(Key);
end;
constructor TPrefEdDb.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
AutoInitialize;
end;
destructor TPrefEdDb.Destroy;
begin
AutoDestroy;
inherited Destroy;
end;
procedure TPrefEdDb.Loaded;
begin
inherited Loaded;
end;
end.
标签: delphi