Change FIBQuery SQL text runtime before report show or execution

Hi All, please help me..

I have made a report in runtime where I save the report in the table and called if necessary.
the report contained FIBQuery1 by default SQL text "SELECT * FROM SP_JUALPERBARANG4 (: PERIODE,: TGLFIRST,: TGLLAST)"
I want to add a WHERE clause in runtime eg be
"SELECT * FROM SP_JUALPERBARANG4 (: PERIODE,: TGLFIRST,: TGLLAST) WHERE NAMABARANG CONTAINING ELA "

My problem is when the report is displayed appears error "can not change the database because the dataset open", but already I close and open FIBQuery.
The following piece of code that I have made.
procedure TFCetak.sBitBtn1Click(Sender: TObject);
var
  frx: TfrxReport;
  frxFIBDB : TfrxFIBComponents;
  frxFIBQ : TfrxFIBQuery;
  st: TStream;
begin
  frx       :=  TfrxReport.Create(Self);
  frxFIBDB  :=  TfrxFIBComponents.Create(Self);
  frxFIBDB.DefaultDatabase  := DM.db;
  
  DM.Laporan.Open;
  if DM.Laporan.Locate('Nama',Caption,[]) then
  begin
    st:=DM.Laporan.CreateBlobStream(DM.LaporanSOURCE,bmRead);
    frx.LoadFromStream(st);
    st.Free;
  end;
  
  frxFIBQ := (TfrxFIBQuery(frx.FindComponent('FIBQuery1')));
  ShowMessage(frxFIBQ.SQL.Text); // SELECT * FROM SP_JUALPERBARANG4(:PERIODE,:TGLFIRST,:TGLLAST)
  
  if not (frxFIBQ=Nil) then
  begin
    frxFIBQ.Close;
    frxFIBQ.SQL.Add('WHERE NAMABARANG CONTAINING ''ELA'' ');
    ShowMessage(frxFIBQ.SQL.Text); // SELECT * FROM SP_JUALPERBARANG4(:PERIODE,:TGLFIRST,:TGLLAST) WHERE NAMABARANG CONTAINING ELA
    frxFIBQ.Open;
    
    frx.Variables['PERIODE']  := _CurrentPeriode;
    frx.Variables['TGLFIRST'] := pTgl1.Date;
    frx.Variables['TGLLAST']  := pTgl2.Date;

    frx.ShowReport();
  end;
end;

I use FastReport 4.14, Delphi 7, Firebird 2.5

Thx b4.
Sorry for my bad english.. >

Comments

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.