Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Change autoseach default dates programatically

edited September 2003 in General

I have a report that uses the auto search feature to specify a date range of
the report (using between). How can I programatically, in Delphi, set the
default date at runtime before I execute PrintReport?

Using:
Delphi 6
Report Builder 7.03 Enterprise
DBISAM 3.25 Database Engine with the DADE


Thanks
J. Michael Eubanks

Comments

  • edited September 2003
    This is my main routine and a dependant function:

    procedure TrptHiddenForm.SetDefaultParamDate(rpt: TppReport);
    var
    lCriteria: TdaCriteria;
    FlSQL: TdaSQL;
    i, x: byte;
    lValues: TStringlist;
    lAutoSearch: TppAutosearchfield;
    lDataModule: TdaDataModule;
    begin
    {get SQL object}
    lValues := nil;
    lAutoSearch := nil;
    try
    lValues := TStringlist.create;

    lDataModule := daGetDataModule(rpt);
    for x := 0 to lDataModule.DataViewCount - 1 do
    begin
    GetSQLObject(rpt, FlSQL, x);
    if FlSQL.CriteriaCount > 0 then
    for i := 0 to pred(FlSQL.CriteriaCount) do
    begin
    lValues.clear;
    lCriteria := FlSQL.Criteria[i];
    if (lCriteria.field.AutoSearch = true) then lAutoSearch :=
    rpt.AutoSearchFieldByName(lCriteria.field.FieldName);
    ppParseString(lCriteria.Value, lValues);
    if (lCriteria.Field.DataType = dtDateTime) and
    (lCriteria.field.Mandatory) then // lets fill some default dates
    begin
    if not (lCriteria.Operator in [dacoBetween, dacoNotBetween])
    then // must have 1 criterion
    begin
    lCriteria.Value := DateTimetoStr(Date); // used for late
    returns list, not sent out list, etc
    if (lCriteria.field.AutoSearch = true) then
    lAutoSearch.SearchExpression := lCriteria.Value;
    end;
    if lCriteria.Operator in [dacoBetween, dacoNotBetween] then //
    must be range
    begin
    lCriteria.value := DateTimetoStr(Date) + ',' +
    DateTimetoStr(incMonth(Date, 1));
    if (lCriteria.field.AutoSearch = true) then
    lAutoSearch.SearchExpression := lCriteria.value;
    end;
    end;
    end;
    end;
    finally
    lvalues.Free;
    end;
    end;

    function TrptHiddenForm.GetSQLObject(aReport: TppReport; var aSQL: TdaSQL;
    DataView: integer): Boolean;
    var
    lDataModule: TdaDataModule;
    lDataView: TdaDataView;
    begin
    aSQL := nil;
    {get the datamodule}
    lDataModule := daGetDataModule(aReport);
    if (lDataModule <> nil) then
    begin
    lDataView := lDataModule.DataViews[DataView];
    if (lDataView <> nil) and (lDataView is TdaQueryDataView) then
    aSQL := TdaQueryDataView(lDataView).SQL;
    end;
    Result := (aSQL <> nil);
    end;



    --
    Paul Toms (mailto:paultoms@cix.co.uk)
  • edited September 2003
    Paul,

    Thanks for the info. That is some mean looking code just to change thoes
    dates, but it works great. I just needed to change this code:

    if (lCriteria.Field.DataType = dtDateTime) and
    (lCriteria.field.Mandatory) then // lets fill some default dates

    to this:

    if (lCriteria.Field.DataType = dtDate) and
    (lCriteria.field.Mandatory) then // lets fill some default dates

    and it works fine.

    Thanks again,

    J. Michael Eubanks


This discussion has been closed.