Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Why Does Database.LoadRows Return 0 Records?
Tue, Jul 4 2017 11:16 AMPermanent Link

Frederick Chin

I see that EWB 2.06b2 now have the TDatabase component and it avoids having TDatasets cluttering the forms.

However, I am a loss as to what I am doing wrong to get no records for the following steps:-

1.   In the Database Manager, create the database (connection is OK) and the dataset (query: select * from table and preview OK)
2.   Dragged the database into the Project Manager to create a TDatabase unit. Named the database dbaData.
3.   The database unit is auto-created for the project.
4.   In the OnClick event of a button placed in a form, typed the following code:-

procedure TfrmMain.Button1Click(Sender: TObject);
var
  oQry : TDataset;
begin                  
  oQry:=dbaData.qMnpsmain;
  dbaData.Loadrows(oQry);
  lblStatus.Caption:='Rows: '+IntToStr(oQry.RowCount);
end;

5.    The oQry.Rowcount always returns 0.

What am I missing?

--
Frederick
Tue, Jul 4 2017 12:14 PMPermanent Link

Uli Becker

Frederick,

> procedure TfrmMain.Button1Click(Sender: TObject);
> var
>    oQry : TDataset;
> begin
>    oQry:=dbaData.qMnpsmain;
>    dbaData.Loadrows(oQry);
>    lblStatus.Caption:='Rows: '+IntToStr(oQry.RowCount);
> end;
>
> 5.    The oQry.Rowcount always returns 0.
>
> What am I missing?

Due to the asynchronous behavior of JS the lblStatus.Caption line will
be executed *before* the data has been loaded.

That's why you have to place this line:

lblStatus.Caption:='Rows: '+IntToStr(oQry.RowCount);

in the AfterLoad event of dbaData and you'll see the correct RowCount.

Uli

Wed, Jul 5 2017 12:55 AMPermanent Link

Frederick Chin

Uli,

/*
Due to the asynchronous behavior of JS the lblStatus.Caption line will
be executed *before* the data has been loaded.

That's why you have to place this line:

lblStatus.Caption:='Rows: '+IntToStr(oQry.RowCount);

in the AfterLoad event of dbaData and you'll see the correct RowCount.
*/

Thanks. I am obviously not using EWB enough to remember this. Smile

--
Frederick
Image