If there is a circular reference between the query object and the datasource that should be caught, perhaps at design time, shouldn't it? I'm trying to imagine how that could be a feature, especially in this case when the original query takes no parameters.
It is for TSQLQuery impossible to detect if the datasource component is for results or for paramater values.
It is possible for TSQLQuery to detect a circular reference. TDataset has an 'IsLinkedTo' method. If it returns true there is a circular reference and an error should be thrown. An example of how this is done can be found in IBX2:
procedure TIBCustomDataSet.SetDataSource(Value: TDataSource);
begin
if IsLinkedTo(Value) then
IBError(ibxeCircularReference, [nil]);
if FDataLink <> nil then
FDataLink.DataSource := Value;
end;
TSQLQuery tries to detect the circular reference, but seems to fail:
procedure TCustomSQLQuery.SetDataSource(AValue: TDataSource);
Var
DS : TDataSource;
begin
DS:=DataSource;
If (AValue<>DS) then
begin
If Assigned(AValue) and (AValue.Dataset=Self) then
DatabaseError(SErrCircularDataSourceReferenceNotAllowed,Self);
If Assigned(DS) then
DS.RemoveFreeNotification(Self);
FStatement.DataSource:=AValue;
end;
end;
Paul, I've a made and attached a small example, as simple and educative as I could think of, on how to use TSQLQuery.DataSource.
I've managed to code all settings instead of using Object Inspector.
If you still believe you have found a bug, please attach another small sample with it.