Subject Re: [IBO] IB_Transaction.DatasetCount
Author Helen Borrie
At 04:05 PM 19/10/2005 +1000, you wrote:
>I can use this sort of code on FormClose:
> for i:=0 to IB_Transaction1.DatasetCount-1 do begin
> with IB_Transaction1.Datasets[i] do begin
> if State in[dssEdit, dssInsert] then begin
> Post;
> end;
> Close;
> end;
> end;
> IB_Transaction1.Commit;
> IB_Transaction1.Close;
>
>I get the result the code depicts.
>
>But on FormCreate I cannot use similar code e.g.
> for i:=0 to IB_Transaction1.DatasetCount-1 do begin
> with IB_Transaction1.Datasets[i] do begin
> Open;
> end;
> end;
>
>Since IBO is creating 3 queries for every live dataset, these other (IBO
>datasets) can't be opend like this.

They shouldn't be opened like that.

>How do I tell which ones of the DatasetCount list of datasaets are actually
>the ones I have created and set up via components, and not ones IBO wants to
>create at runtime?

Don't refer to the Transaction or the Connection but to the owner (the form
or datamodule).

Here's a (Delphi) snippet from a procedure called from typical
DatamoduleCreate where I want to open some datasets but not others:

procedure TdmFFoundation.OpenDatasets (Creating: Boolean);
var
qName: string;
ii: integer;
begin
for ii := 0 to ComponentCount -1 do
begin
if Components[ii] is TIB_BDataset then
begin
qName := Components[ii].Name;
if Creating then
begin
if ((qName <> 'qrBanks')
and (qName <> 'qrPerson_Role')
and (qName <> 'qrDocs')
and (qName <> 'qrBankUpdateLog')) then
if (TIB_BDataset(Components[ii]).SQL.Count > 0) then
begin
TIB_BDataset(Components[ii]).Open;
ActiveQueries.Add(qName);
end;
end
else
if ActiveQueries.IndexOf(qName) >= 0 then
with TIB_BDataset(Components[ii]) do
begin
if not Active then
Open;
//
end;
end;
end;
end;

Helen