none
none

Reputation: 4827

ADOQuery closes after constructor

I am using TADOQuery in Delphi 7.
In the constructor, I call ADOQuery.open.

Why is the ADOQuery closed when another function is called from outside the form?

constructor TClass1.Create(AOwner: TComponent;
  MyParam: TProgramParam);
begin
  inherited;
  ADOQuery.Open;
  ADOQuery.Locate('fieldName',Param,[]);  
end;

Upvotes: 0

Views: 615

Answers (2)

user2409130
user2409130

Reputation: 9

constructor TClass1.Create(AOwner: TComponent;
  MyParam: TProgramParam);
begin
  inherited;
  ADOQuery.Open;
  ADOQuery.Locate('fieldName',Param);  
end;

//

constructor TClass1.Create(AOwner: TComponent;
  MyParam: TProgramParam);
begin
  inherited;
  ADOQuery.Open;
  ADOQuery.Locate('fieldName',Param,[]);  
end;

Upvotes: 0

jachguate
jachguate

Reputation: 17203

My advise to find who is closing the DataSet:

Create a new event handler for the BeforeClose event of the AdoQuery, put anything that is compiled and executed just to put a Breakpoint there. For example:

procedure TfrmCreDocCredito.cdsSucursalesBeforeClose(DataSet: TDataSet);
begin
  ShowMessage('Closing!!');
end;

Run your program, perform any user action needed to create your Class instance and when the program stops on the breakpoint, you have the chance to inspect the call stack. It will reveal who, and if you think a bit about it, you will find why the dataset is closing. If your breakpoint doesn't fire, I bet the dataset never really opens.

Best regards.

Upvotes: 4

Related Questions