以下是本人自己写的一个组件,运行的时候功能都正常,但当程序退出时出现错误。
Access violation at address 000AC345 in module 'dbrtl60.bpl'.read of address 0000032C.
而且退出DELPHI的时候都会出现类似错误!经多日来反复的排查,发现问题出在  FDataLink.OnDataChange := DataChange;这一句,如果注释掉这句程序运行正常,或通过其它方式执行DataChange过程也不会出现问题。这是怎么回事呢?是FDataLink的定义有问题,还是对OnDataChange事件的定义有错误?偶已经折腾一星期了。再不解决今年的程序就要泡汤了。那小弟也要下岗了,请各位朋友帮帮忙啊!组件完整原代码,保存后可以直接运行使用:http://community.csdn.net/Expert/topic/4460/4460953.xml?temp=.9647333以下是本组件部分的代码:unit exDBLookupComboBox;interfaceuses
  SysUtils, Classes, Controls, StdCtrls, Forms, DB, ADODB, ComCtrls, Windows, Grids,
  DBGrids, DBCtrls, Dialogs, exDBComboBox, Messages;type{TexDBLookupComboBox}  TexDBLookupComboBox = class(TexDBComboBox)  private    FDataLink: TFieldDataLink;
    function GetDataSource: TDataSource;
    procedure SetDataSource(Value: TDataSource);
    function GetFieldText: string;
    function GetDataField: string;
    procedure SetDataField(const Value: string);
    procedure CMGetDataLink(var Message: TMessage); message CM_GETDATALINK;  protected    procedure Loaded; override;
    procedure Notification(AComponent: TComponent;
      Operation: TOperation); override;
    procedure SetAutoSize(Value: Boolean); override;
  public
    constructor Create(AOwner : TComponent); override;
    destructor Destory;  published    procedure DataChange(Sender: TObject);
    property DataField: string read GetDataField write SetDataField;
    property DataSource: TDataSource read GetDataSource write SetDataSource;    property ListGridShowHead;
    property ListGridWidth;
    property ListGridHeight;
    property ListGridConnection;
    property ListGridSQL;
    property TextValue;
    property ListGridAutoSize;
    property Enabled;
    property Color;
    property Ctl3D;
    property BevelEdges;
    property BevelInner;
    property BevelKind default bkNone;
    property BevelOuter;
    property Font;
    property Text;
    property Visible;
    property OnChange;
    property OnClick;
    property OnCloseUp;
    property OnContextPopup;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnDrawItem;
    property OnDropDown;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMeasureItem;
    property OnSelect;
    property OnStartDock;
    property OnStartDrag;  end;procedure Register;implementationprocedure Register;
begin
  RegisterComponents('svSoft', [TexDBLookupComboBox]);
end;{TexDBLookupComboBox}constructor TexDBLookupComboBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FDataLink:=TFieldDataLink.Create;
  FDataLink.Control := Self;
  FDataLink.OnDataChange := DataChange;  //问题出在这里end;destructor TexDBLookupComboBox.Destory;
begin
  FDataLink.Free;
  FDataLink := nil;
  inherited Destory;
end;procedure TexDBLookupComboBox.Loaded;
begin
  inherited Loaded;
  if (csDesigning in ComponentState) then DataChange(Self);
end;function TexDBLookupComboBox.GetDataField: string;
begin
  Result := FDataLink.FieldName;
end;procedure TexDBLookupComboBox.SetDataField(const Value: string);
begin
  FDataLink.FieldName := Value;
end;function TexDBLookupComboBox.GetDataSource: TDataSource;
begin
  Result := FDataLink.DataSource;
end;procedure TexDBLookupComboBox.SetDataSource(Value: TDataSource);
begin
  if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
    FDataLink.DataSource := Value;
  if Value <> nil then Value.FreeNotification(Self);
end;function TexDBLookupComboBox.GetFieldText: string;
begin
  if FDataLink.Field <> nil then
    Result := FDataLink.Field.DisplayText
  else
    if csDesigning in ComponentState then Result := Name else Result := '';
end;procedure TexDBLookupComboBox.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and (FDataLink <> nil) and
    (AComponent = DataSource) then DataSource := nil;
end;procedure TexDBLookupComboBox.SetAutoSize(Value: Boolean);
begin
  if AutoSize <> Value then
  begin
    if Value and FDataLink.DataSourceFixed then DatabaseError('数据源指定错误!');
    inherited SetAutoSize(Value);
  end;
end;procedure TexDBLookupComboBox.CMGetDataLink(var Message: TMessage);
begin
  Message.Result := Integer(FDataLink);
end;procedure TexDBLookupComboBox.DataChange(Sender: TObject);
begin
  TextValue := GetFieldText;
  //showmessage(FDataLink.Field.DisplayText) ;
end;end.

解决方案 »

  1.   

    //小问题,估计是写代码时的笔误,照以下修改后就没有你说的问题了,我已经测试OK TexDBComboBox = class(TCustomComboBox)
    ....
    public
     //destructor Destory; //错误的地方 
     destructor  Destroy;override;//改为,同步修改一下对应的函数体
    ....
    end;TexDBLookupComboBox = class(TexDBComboBox)
      //destructor Destory; //错误的地方 
     destructor  Destroy;override;//改为,同步修改一下对应的函数体end;
      

  2.   

    感谢Q287413288(歼10) ,按您的方法修改后编译组件出现错误:
    [Error] exDBLookupComboBox.pas(103):Undeclared identifier:'Destory'
    [Error] exDBLookupComboBox.pas(105):Undeclared identifier:'FDataLink'
    [Error] exDBLookupComboBox.pas(107):This form of method call only allowed in methods of derived types
    103 destructor TexDBLookupComboBox.Destory;
    104 begin
    105  FDataLink.Free;
    106  FDataLink := nil;
    107  inherited Destory;
    108 end;对TexDBComboBox也做了相应的修改了。
      

  3.   


     我的Mail [email protected] 发邮件给我,发给你完整的代码给你
      

  4.   

    FDataLink.OnDataChange := DataChange;
    DataChange 是 private的,会不会因为这个?
      

  5.   

    //destructor Destory; //错误的地方
    destructor Destroy;override;//改为,同步修改一下对应的函数体
    .....