I build a report and used the Wizard to make the selection
Fields and has insert the condition (Where). Now I need
change the command SQL (Clause where) in runtime, before
of print the report. What i need make to change the command
SQL in runTime???
Thank you,
Comments
Tech Tip: How to access the SQL object associated
with a Report created using DADE
-------------------------------------------------
TdaSQL is a class defined in daSQL.pas.
TdaSQL has a run-time interface for adding search Criteria,
etc. For an example see the EndUser\Custom DataViews example.
OR you can assign its SQLText property. Please note that
once you directly assign the SQLText property the Query tool
buttons such as Sort, Search can no longer be used.
uses
daDataModule;
function GetSQLObject(aReport: TppReport; var aSQL: TdaSQL): Boolean;
var
lDataModule: TdaDataModule;
lDataView: TdaDataView;
begin
aSQL := nil;
{get the datamodule}
lDataModule := daGetDataModule(aReport);
if (lDataModule <> nil) then
begin
lDataView := lDataModule.DataViews[0];
if (lDataView <> nil) and (lDataView is TdaQueryDataView) then
aSQL := TdaQueryDataView(lDataView).SQL;
end;
Result := (aSQL <> nil);
end;
Once you have the SQL object, you can do useful operations on it, such as
creating search criteria:
procedure CreateCriteria;
var
lSQL: TdaSQL;
lFields: TStringList;
lCriteria: TdaCriteria;
liIndex: Integer;
begin
{get SQL object}
GetSQLObject(ppReport1, lSQL);
{if criteria have not been created, then add them}
if (lSQL.CriteriaCount = 0) then
begin
{get all available criteria fields}
lFields := TStringList.Create;
lSQL.AvailableCriteriaList(lFields);
{set string list entries to field names}
for liIndex := 0 to lFields.Count - 1 do
lFields[liIndex] := TdaField(lFields.Objects[liIndex]).FieldName;
{create order no criteria}
liIndex := lFields.IndexOf('CustNo');
if (liIndex <> -1) then
begin
lCriteria := lSQL.SelectCriteria(liIndex);
lCriteria.Operator := dacoEqual;
end;
{create art code criteria}
liIndex := lFields.IndexOf('Paymentmethod');
if (liIndex <> -1) then
begin
lCriteria := lSQL.SelectCriteria(liIndex);
lCriteria.Operator := dacoLike;
end;
{create begin/end date criteria}
liIndex := lFields.IndexOf('SaleDate');
if (liIndex <> -1) then
begin
lCriteria := lSQL.SelectCriteria(liIndex);
lCriteria.Operator := dacoBetween;
end;
lFields.Free;
end;
{set order no. search value}
lSQL.Criteria[0].Value := '1221';
{set payment method search value}
lSQL.Criteria[1].Value := 'Visa';
{set order date search value}
lSQL.Criteria[2].Value := '12/31/1990,12/31/1999';
end;
--
Cheers,
Alexander Kramnik
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
I try this.
Thank you
Mauri
"Alexander Kramnik (Digital Metaphors)"
http://www.digital-metaphors.com/tips/ExtractSQLObject.zip
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com