HomeActive Query BuilderProgrammatically delete a table from the Query Building Area.

Programmatically delete a table from the Query Building Area.


Using Delphi 7, AQB VCL edition (1.13.1.0 Standard Edition)

Hello all,

I only want a single table in the Query Building Area at a time. So when the user double clicks on a table in the MetaData Tree, any existing table in the diagram area is deleted, before the new table is added. Is that possible ?

I have tried using the OnBeforeAddDatasource event, but so far I just get an exception. I can set a global variable in the OnBeforeDeleteDatasource and OnAfterAddDatasource events. And then use this to prevent a new table being added like this ...

[AQBBeforeAddDatasource]

AAllow := True;
if Diagrammed = True then
begin
AAllow := False;
MessageDlg('Please delete the existing table from the diagram area first',
mtinformation, [mbOK], 0);
end;

But it would be much neater if I could test if the diagram are contained something and just delete it without getting the user to do it.

I would appreciate any help.

Thanks
Johnny.
Johnny | email
August 14 2009, 08:01 AM
Dear Johnny,

use the following handler in AQBBeforeAddDatasource:

procedure TForm2.qbBeforeAddDatasource(Sender: TacQueryBuilder;
AUnionSubQuery: TacUnionSubQuery; ADatasourceAST: TSQLFromSource;
var AAllow: Boolean; var APos: TPoint);
var l:TObjectList;
i:integer;
begin
l:=TObjectList.Create(false);
try
AUnionSubQuery.FromClause.GetDatasources(l);

AUnionSubQuery.BeginUpdate;
try
for i:=0 to l.Count-1 do
TacDatasource(l[i]).Free;
finally
AUnionSubQuery.EndUpdate;
end;
finally
l.Free;
end;
end;
Vitaly Sotnikov | email
4 days, 19 hours since original post
Works great, thanks Vitaly.

Johnny.
Johnny | email
6 days, 18 hours since original post
Using Delphi 2006, AQB VCL edition.

I have set up an acADOMetadataProvider and one ADOConnection.
The program works fine. I can load the Metadata and I can make
queries. But I have a little problem.

I am trying to do the same thing that Jonnhy.I only want a single
table in the Query Building Area at a time. So when the user double
click on a table in the MetaData Tree, any existing table in the
diagram area is deleted, before the new table is added.

However, I cannot find the handler for BeforeAddDatasource.
Where must I set the Event Handler? I cannot find it in the
Events of AQB Component or Anyone else.

Please, can you explain more deeply the code to do this?
Pablo | email
1 week, 3 days since original post
You should download the latest version. The event is called OnBeforeAddDatasource.
Sergey Smagin | email
1 week, 3 days since original post
This topic is closed