Updating the contents of frxPictureView

BJLBJL Brussels, Belgium
edited 9:14AM in FastReport 3.0
Working with BCB6 and FR3.04

In an application, the user makes some selections which result in a metafile. The design of the report includes a TfrxPictureView to display the metafile. This works well.

After closing the preview, the user may change part of its initial selections to generate a new report (using the same FR3 file and the same frxReport). Though the program has produced a revised metafile (under the same name), when the report appears, it still shows the old metafile, despite the fact that the frxReport is Cleared and the FR3 loaded again. The FR3 does not include the metafile assignment, which is done in the BCB code.
I have tried, in the BCB code, to remove the picture from the frxPictureView before reloading the updated metafile without success.

Here is my code
 Chart->Visible = true;
  String WmfFile = ExtractFilePath(Application->ExeName) + "Chart.wmf";
  // these 2 following lines have no effect...
  HENHMETAFILE hMetaFile = GetEnhMetaFile(WmfFile.c_str());
  DeleteEnhMetaFile(hMetaFile);
  Chart->SaveToMetafileEnh(WmfFile);
  Chart->Visible = false;
  String DesignFile = ExtractFilePath(Application->ExeName) + "TempChart.fr3";
  frxReport1->Clear();
  frxReport1->LoadFromFile(DesignFile);
  TfrxPictureView* v = (TfrxPictureView*)frxReport1->FindObject("Picture1");
  v->Picture->LoadFromFile(WmfFile);
  frxReport1->PrepareReport(false);
  frxReport1->ShowPreparedReport();

Any idea to solve this problem?

Happy new year! Bonne ann?©e! Gl??ckliches neues Jahr!

Comments

  • edited 9:14AM
    Sitting with just the same problem! No solution yet? I'm sitting with D7+FR3.08

    Cheers
    /Johan
  • edited January 2005
    This is how I got it to work nicely...
    ? 
     ? [B]var[/B]
      c: TfrxComponent;
    
      ...
      ...
    
     ? // Update diagram picture
     ? currchart.SaveToMetafile('stg.wmf');
     ? frxReport1.LoadFromFile('stg_history.fr3');
     ? c := frxReport1.FindObject('Picture1');
     ? (c as TfrxPictureView).Picture.Metafile.LoadFromFile('stg.wmf');
    
     ? // Show report
     ? sqlTemp.Prepare;
     ? sqlTemp.Open;
     ? frxReport1.ShowReport;
     ? sqlTemp.Close;
    
     ? // Delete wmf-file
     ? DeleteFile('stg.wmf');
    

    Cheers
    Johan
  • gordkgordk St.Catherines On. Canada.
    edited 9:14AM
    here is a sample of i handle it in delphi you will have to translate to bcb

    new method for fr3

    use a pictureview object instead. and the obp event of report component.
    procedure TForm1.frxReport1BeforePrint(Sender: TfrxReportComponent);
    begin
    if Sender.Name='Picture1'then
    TfrxPictureView(Sender).Picture.Assign(form2.Chart1.TeeCreateMetafile(False,
    Rect(0, 0, Round(Sender.Width), Round(Sender.Height))));
    end;

    ;)
  • BJLBJL Brussels, Belgium
    edited 9:14AM
    Thank you Gord.
    Using TeeCreateMetaFile is handy when it is not necessary to keep the metafile on disk.
    In my case, I could not solve the problem by moving the code to the Report obp.
    I have tried to add the frxPictureView at run time, hoping to remove it after closing the preview. But I could not find a way to remove the picture view object.
    My present code is the following with the same problem as explained in the first message.
     frxReport1->Clear();
      frxReport1->LoadFromFile(DesignFile);
      TfrxChild* C = (TfrxChild*)frxReport1->FindObject("Child1");
      TfrxPictureView* v = new TfrxPictureView((TfrxChild*)C);
      v->Align = baWidth;
      v->Width = C->Width;
      v->Height = C->Height;
      v->Center = true;
      v->KeepAspectRatio = false;
      v->Picture->Assign(Chart->TeeCreateMetafile(false, Rect(0, 0, v->Width, v->Height)));
      frxReport1->PrepareReport(false);
      Chart->Visible = false;
      frxReport1->ShowPreparedReport();
      delete v;// this line is not accepted and leads to an error.
    
    However, when using the editor of the PictureView object, there is a CLEAR button which removes the pisture at design time. Which function is this button using?
  • BJLBJL Brussels, Belgium
    edited 9:14AM
    Looking more closely, I found that the code above solves the problem in keeping the first graph and adding the new on a new page.
  • gordkgordk St.Catherines On. Canada.
    edited 9:14AM
    frxreport1->Preparereport;
    frxReport1->ShowPreparedReport();
    delete v;// this line is not accepted and leads to an error.
    of course as you are beyond the design stream after calling
    preparereport.
    the code i gave you assumes an empty pictureview object.
    and by using the external obp event will always load whatever is current when encountered in the report.

    for initial clearing for example of a pictureview object in the report
    try something like
    pv:tfrxpictureview;

    frxreport1.loadfromfile('blah');
    pv := frxreport1.finobject('Picture1');
    pv.picture.clear;
    or pv.picture := nil;
    ;)

  • gordkgordk St.Catherines On. Canada.
    edited 9:14AM
    in the previous example you can clear at the pictureviewlevel.
    pv.clear;
    ;)

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.