在执行过程中,使用如下:
在按钮点击事件中,
procedure TForm1.Button1Click(Sender: TObject);
var
aa:TProductTypeClass;
begin
try
aa:=TProductTypeClass.Create;
finally
FreeAndNil(aa);
end;
end;
问题来了,调用Create它不显示信息'Create',也就是我在类的Create方法加入断点,根本不进去,释放时也不执行Destory事件,请大侠帮帮我!!谢谢,完了马上结贴!!!-----------------------------
源码如下:
unit ProductTypeClass;interfaceuses
SysUtils, Classes, RzTreeVw,DB, DBTables, Forms, ExtCtrls, Windows, Dialogs, ADODB;type
TProductTypeClass=Class
private protected
FConnection : TADOConnection;
FQuery: TADOQuery;
constructor Create;
destructor Destroy;
public
{public method declare}
published
property Query:TADOQuery read FQuery;
property Connection:TADOConnection read FConnection write FConnection;
end;
implementation{ TProductTypeClass}constructor TProductTypeClass.Create;
begin
ShowMessage('Create');
FQuery:=TADOQuery.Create(nil);
FConnection:=TADOConnection.Create(nil);
FQuery.Connection:=FConnection;
end;destructor TProductTypeClass.Destroy;
begin
ShowMessage('Destory');
FConnection.Close;
FQuery.Close;
FConnection.Free;
FQuery.Free;
end;
end.
在按钮点击事件中,
procedure TForm1.Button1Click(Sender: TObject);
var
aa:TProductTypeClass;
begin
try
aa:=TProductTypeClass.Create;
finally
FreeAndNil(aa);
end;
end;
问题来了,调用Create它不显示信息'Create',也就是我在类的Create方法加入断点,根本不进去,释放时也不执行Destory事件,请大侠帮帮我!!谢谢,完了马上结贴!!!-----------------------------
源码如下:
unit ProductTypeClass;interfaceuses
SysUtils, Classes, RzTreeVw,DB, DBTables, Forms, ExtCtrls, Windows, Dialogs, ADODB;type
TProductTypeClass=Class
private protected
FConnection : TADOConnection;
FQuery: TADOQuery;
constructor Create;
destructor Destroy;
public
{public method declare}
published
property Query:TADOQuery read FQuery;
property Connection:TADOConnection read FConnection write FConnection;
end;
implementation{ TProductTypeClass}constructor TProductTypeClass.Create;
begin
ShowMessage('Create');
FQuery:=TADOQuery.Create(nil);
FConnection:=TADOConnection.Create(nil);
FQuery.Connection:=FConnection;
end;destructor TProductTypeClass.Destroy;
begin
ShowMessage('Destory');
FConnection.Close;
FQuery.Close;
FConnection.Free;
FQuery.Free;
end;
end.
SysUtils, Classes, RzTreeVw,DB, DBTables, Forms, ExtCtrls, Windows, Dialogs, ADODB;type
TProductTypeClass=Class
private protected
FConnection : TADOConnection;
FQuery: TADOQuery;
public
{public method declare}
constructor Create; //要这样修改
Destructor Destroy;override; //要这样修改
published
property Query:TADOQuery read FQuery;
property Connection:TADOConnection read FConnection write FConnection;
end;
implementation{ TProductTypeClass}constructor TProductTypeClass.Create;
begin
ShowMessage('Create');
FQuery:=TADOQuery.Create(nil);
FConnection:=TADOConnection.Create(nil);
FQuery.Connection:=FConnection;
end;destructor TProductTypeClass.Destroy;
begin
ShowMessage('Destory');
FConnection.Close;
FQuery.Close;
FConnection.Free;
FQuery.Free;
end;
end.另外要在 Form1中 uses ProductTypeClass;
看来楼主是个初学者,多看些书.
谢谢了!!