Create and Destroy objects at runtime

I need to create some objects (tfrxMemoview) for every record in the report, then number of objects may vary from one record to another. I am using the followin code in the MasterDataOnbeforeprint event:
procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
var
  s : string;
  i : integer;
  dLeft,dWidth : double;                                    
begin
  if <Cheques."POS"> = 'S' then
  begin
    picLogoS.DataField := 'LogoBanco';  
    picLogoI.Datafield := 'Logo';                                                                                         
  end
  else            
  begin
    picLogoI.DataField := 'LogoBanco';  
    picLogoS.Datafield := 'Logo';                                                                                         
  end;
  ChequesSimbolo.left := 653.86;                                                                                
  dWidth := ChequesSimbolo.width / 2;        
  dLeft := ChequesSimbolo.left + dwidth;
  ChequesSimbolo.Left := dLeft - ChequesSimbolo.width - (Length(<Cheques."MONTOSTR">) * dWidth);                                                                                            
  for i:= Length(<Cheques."MONTOSTR">) downto 1 do
  begin
    s := Copy(<Cheques."MONTOSTR">,i,1);
    with TfrxMemoView.Create(MasterData1) do
    begin
      Memo.text := s;
      Left := dLeft;
      AutoWidth := false;                                                     
      width := dWidth;
      Color := ChequesSimbolo.color;
      Font := chequesSimbolo.font;        
      Height := ChequesSimbolo.Height;
      Top := ChequesSimbolo.Top;                                                              
      HAlign := haCenter;
      VAlign := vaCenter;
    end;
    if i > 1 then                                       
      dLeft := dLeft - dWidth;  
  end;
  ChequesSimbolo.left := dleft - ChequesSimbolo.Width;                                                                
  frmSombra.left := ChequesSimbolo.left;                                                                                     
end;

It's work fine, however I need to destroy them for the next record, because some records needs less objects than others.

How can I do that?
Should I change my code?

Thanks in advance.

J.C. Arteaga
ARTESOFT

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 8:31PM
    instead of continually creating why not just put the memoview in the design and control its visibility and content and position
  • edited 8:31PM
    Finally I did it creating an array:
    var
      aMemos : array[1..10] of TfrxMemoView;
      aLiteral : array[1..10] of TfrxMemoView;
    
    procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
    var
      s : string;
      i : integer;
      dLeft,dWidth : double;
    begin
      if <Cheques."POS"> = 'S' then
      begin
        picLogoS.DataField := 'LogoBanco';  
        picLogoI.Datafield := 'Logo';                                                                                         
      end
      else            
      begin
        picLogoI.DataField := 'LogoBanco';  
        picLogoS.Datafield := 'Logo';                                                                                         
      end;
      ChequesSimbolo.left := 653.86;                                                                                
      dWidth := ChequesSimbolo.width / 2;        
      dLeft := ChequesSimbolo.left + dwidth;
      ChequesSimbolo.Left := dLeft - ChequesSimbolo.width - (Length(<Cheques."MONTOSTR">) * dWidth);                                                                                            
      for i:= Length(<Cheques."MONTOSTR">) downto 1 do
      begin
        s := Copy(<Cheques."MONTOSTR">,i,1);
        aMemos[i] := TfrxMemoView.Create(MasterData1);                                   
        with aMemos[i] do
        begin
          Memo.text := s;
          Left := dLeft;
          AutoWidth := false;                                                     
          width := dWidth;
          Color := ChequesSimbolo.color;
          Font := chequesSimbolo.font;        
          Height := ChequesSimbolo.Height;
          Top := ChequesSimbolo.Top;                                                              
          HAlign := haCenter;
          VAlign := vaCenter;
        end;
        aLiteral[i] := TfrxMemoView.Create(MasterData1);                                             
        with aLiteral[i] do
        begin
          Memo.Text := Literal(s);                                                          
          Left := dLeft;
          AutoWidth := false;                                                     
          width := dWidth;
          Color := frmSombra.color;
          Font := frmSombra.font;        
          Height := frmSombra.Height;
          Top := frmSombra.Top;                                                              
          HAlign := haCenter;
          VAlign := vaCenter;
        end;              
        if i > 1 then                                       
          dLeft := dLeft - dWidth;  
      end;
      ChequesSimbolo.left := dleft - ChequesSimbolo.Width;                                                                
      frmSombra.left := ChequesSimbolo.left;                                                                                     
    end;
    
    procedure MasterData1OnAfterPrint(Sender: TfrxComponent);
    var
       i : integer;                                        
    begin
     for i:= Length(<Cheques."MONTOSTR">) downto 1 do
     begin             
       aMemos[i].free;
       aLiteral[i].free;
     end;                
    end;
    
    Thank you

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.