title: Creating and deleting objects in Fast Report VCL (Delphi)
body: <p>I'm using FastReport 4 to display some dynamically generated data and rearrange it in the report.</p>
  
  <p>I use a "template" object in the report to get the initial position (in my real program I copy font properties, alignment, etc.)</p>
  
  <p>I've managed to create a small project so I can create a memo component in the report, preview the report, and then <em>remove</em> the component so I can reuse the report with different data.</p>
  
  <p>However, when I free the created object, I lose other objects from the report (in this case, my template object is not found the second time I preview the report).</p>
  
  <p>What is the right way to create and remove objects from a Fast Report report?</p>
  
  <p>Here is the pascal unit:</p>
  
  
  
  <pre><code>unit Unit1;
  
  interface
  
  uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, frxClass;
  
  type
    TForm1 = class(TForm)
      frxReport1: TfrxReport;
      btn1: TButton;
      procedure btn1Click(Sender: TObject);
    end;
  
  var
    Form1: TForm1;
  
  implementation
  
  {$R *.dfm}
  
  procedure TForm1.btn1Click(Sender: TObject);
  var
    modelObj: TfrxComponent;
    newObj: TfrxMemoView;
  begin
    modelObj := frxReport1.FindObject('modelObj');
    newObj := TfrxMemoView.Create(modelObj.Parent);
    newObj.CreateUniqueName;
    newObj.Text := 'Whee';
    newObj.SetBounds(modelObj.Left, modelObj.Top + modelObj.Height,
      modelObj.Width, modelObj.Height);
    frxReport1.PrepareReport;
    frxReport1.ShowPreparedReport;
    newObj.Free;
  end;
  
  end.
  </code></pre>
  
  <p>Here's the DFM:</p>
  
  <pre><code>object Form1: TForm1
    Left = 0
    Top = 0
    Caption = 'Form1'
    ClientHeight = 299
    ClientWidth = 635
    Color = clBtnFace
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    OldCreateOrder = False
    PixelsPerInch = 96
    TextHeight = 13
    object btn1: TButton
      Left = 224
      Top = 48
      Width = 75
      Height = 25
      Caption = 'btn1'
      TabOrder = 0
      OnClick = btn1Click
    end
    object frxReport1: TfrxReport
      Version = '4.15'
      DotMatrixReport = False
      IniFile = '\Software\Fast Reports'
      PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick]
      PreviewOptions.Zoom = 1.000000000000000000
      PrintOptions.Printer = 'Por defecto'
      PrintOptions.PrintOnSheet = 0
      ReportOptions.CreateDate = 41905.757295162040000000
      ReportOptions.LastChange = 41905.757295162040000000
      ScriptLanguage = 'PascalScript'
      ScriptText.Strings = (
        'begin'
        ''
        'end.')
      Left = 72
      Top = 32
      Datasets = &lt;&gt;
      Variables = &lt;&gt;
      Style = &lt;&gt;
      object Data: TfrxDataPage
        Height = 1000.000000000000000000
        Width = 1000.000000000000000000
      end
      object Page1: TfrxReportPage
        PaperWidth = 216.000000000000000000
        PaperHeight = 279.000000000000000000
        PaperSize = 1
        LeftMargin = 10.000000000000000000
        RightMargin = 10.000000000000000000
        TopMargin = 10.000000000000000000
        BottomMargin = 10.000000000000000000
        object PageHeader1: TfrxPageHeader
          Height = 279.685220000000000000
          Top = 18.897650000000000000
          Width = 740.787880000000000000
          object modelObj: TfrxMemoView
            Left = 166.299320000000000000
            Top = 30.236240000000000000
            Width = 264.567100000000000000
            Height = 18.897650000000000000
            ShowHint = False
            Color = clYellow
            Font.Charset = DEFAULT_CHARSET
            Font.Color = clBlack
            Font.Height = -13
            Font.Name = 'Arial'
            Font.Style = []
            Memo.UTF8W = (
              'Model')
            ParentFont = False
          end
        end
      end
    end
  end
  </code></pre>