Calc fields initialization
Hello,
I'm using Delphi 6 and RBuilder 6.03.
I would like to intercept the query generated by the end-user report. The
idea is to change dynamically the name of a Table (we are using tables that
are named using the current date).
It works fine by using the procedure that gets the TdaSQL and modifying it
before launching preview :
function TmyEndUSerSolution.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;
BUT when the TdaSQL contains calc fields, something's wrong :
The calculated field remains with the old table name even if all the string
SQL query contains only new names!
Do you have any ideas to dynamically change the calc field name ?
Thank's
I'm using Delphi 6 and RBuilder 6.03.
I would like to intercept the query generated by the end-user report. The
idea is to change dynamically the name of a Table (we are using tables that
are named using the current date).
It works fine by using the procedure that gets the TdaSQL and modifying it
before launching preview :
function TmyEndUSerSolution.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;
BUT when the TdaSQL contains calc fields, something's wrong :
The calculated field remains with the old table name even if all the string
SQL query contains only new names!
Do you have any ideas to dynamically change the calc field name ?
Thank's
This discussion has been closed.
Comments
is the calc field based on? You could try recreating the calc field
dynamically:
procedure TForm1.CreateSumCalcField(const aFieldName: String);
var
lSQL: TdaSQL;
lField: TdaField;
lCalc: TdaCalculation;
liIndex: Integer;
begin
{get SQL object}
GetSQLObject(ppReport1, lSQL);
lSQL.ClearCalcFields;
liIndex := 0;
while (liIndex < lSQL.SelectFieldCount) do
begin
lField := lSQL.SelectFields[liIndex];
if (lField.FieldName = aFieldName) then
begin
lCalc := TdaCalculation.Create(lSQL);
lCalc.Assign(lField);
lCalc.CalcType := dacaSum;
lCalc.Parent := lSQL;
end;
Inc(liIndex);
{exit loop}
if (lField.FieldName = aFieldName) then
liIndex := lSQL.SelectFieldCount;
end;
end;
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com