1
votes

im using the Crystal Reports VCL for Delphi 7 to run Crystal Reports from Delphi. I want to set current parameter values from this Delphi application. I'm sending succesfully this values for Number or String Parameters. But now i'm struggling with Date Parameters that have set Allow Ranges to True.

The Error im getting is: 305:Error converting string to ValueInfo - ParamFields[2].CurrentValues.Add <StrToValueInfo>

I'm using this code which like i said works for no Range Parameters. In the code below the parameter PARAM_DATE is a Date parameter which allows Ranges. Any idea how to pass range values?

procedure TReportFrame.btnExecuteReportClick(Sender: TObject);
var
    Crpe1 : TCrpe;
    varArr : variant;
    i : integer;
    a : TCrpeParamFieldRangesItem;
    b : TCrpeParamFieldCurrentValuesItem;
begin
  SetCurrentDir( GetCommonFilesPath );
  try
  Crpe1 := TCrpe.Create(Self);
  Crpe1.DiscardSavedData();
  Crpe1.ReportName := getReportBasePath() + reportFileName;

  Crpe1.IgnoreKnownProblems := true;
  Crpe1.LoadEngineOnUse := true;
  Crpe1.Connect.Clear;

  Crpe1.Tables[0].ConnectBuffer := glbDBMan.GetConnectionString;

    Crpe1.ParamByName('PARAM_SORTING_TYPE', EmptyStr).CurrentValue :=  VarToStr( paramSposobSortowania.getSelectedValue());

  varArr := parameterOsobaOdpowiedzialna.getSelectedValues();
  for i := VarArrayLowBound(varArr,1) to VarArrayHighBound(varArr,1) do
  begin
    Crpe1.ParamByName('PARAM_PERSON', EmptyStr).CurrentValues.Add(VarToStr( varArr[i]));
  end;

//  Crpe1.ParamByName('PARAM_DATA_ZLOZENIA_WNIOSKU', EmptyStr).CurrentValues.Add('2012-4-1');
//  a := TCrpeParamFieldRangesItem.Create;
//  a.RangeStart := '2012-4-1';
//  a.RangeEnd := '2012-4-6';
//  Crpe1.ParamByName('PARAM_DATE', EmptyStr).Ranges.Add();
//  Crpe1.ParamByName('PARAM_DATE', EmptyStr).Ranges[0].RangeStart := '2012-4-1';
//  Crpe1.ParamByName('PARAM_DATE', EmptyStr).Ranges[0].RangeEnd := '2012-4-6';

//  Crpe1.ParamByName('PARAM_DATE', EmptyStr).CurrentValues.Add('2012-4-1');

    //PARAM_DATE is a DATE Range
  Crpe1.ParamByName('PARAM_DATE', EmptyStr).CurrentValues.Add('2012-4-1');
  Crpe1.ParamByName('PARAM_DATE', EmptyStr).CurrentValues.Add('2012-4-6');

  if Crpe1.Connect.Test then
    Crpe1.Show
  else
    ShowMessage('Error Connecting');

    Crpe1.DiscardSavedData;

    finally
      SetCurrentDir( ExtractFileDir(ParamStr(0)) );
    end;
end;
2
OK i found out that if i put the date is this format 2012,4,7 (commas instead of minuses) it works. BUt this way i can only pass one value. i still cannot pass a range... - Robert Niestroj
Use FastReport instead of Crystal Report in delphi projects.FastReport is easier and faster than CR. - MajidTaheri

2 Answers

0
votes

Did you try something like this?

i:= Crpe1.ParamByName('PARAM_DATE', EmptyStr).Ranges.Add();
Crpe1.ParamByName('PARAM_DATE', EmptyStr).Ranges.Items[i].RangeStart := '2012-4-1';
Crpe1.ParamByName('PARAM_DATE', EmptyStr).Ranges.Itens[i].RangeEnd := '2012-4-6';
0
votes
Crpe1.ParamByName('PARAM_DATE', EmptyStr).Ranges.Add();
Crpe1.ParamByName('PARAM_DATE', EmptyStr).Ranges[0].RangeStart := '2012,4,1';
Crpe1.ParamByName('PARAM_DATE', EmptyStr).Ranges[0].RangeEnd := '2012,4,6';

UPDATE: there is a function in the VCL (file: UCrpeUtl) called CrDateToStr which takes a TDateTime and returns this format of a date string.