Search code examples
delphidelphi-10-seattlefastreport

Put text and numbers in boxes


Using FastReport , how can I put Text and Numbers from database in boxes like :

|_|_|_|_|_|_|_|_|_|_|

So "Sami" it becomes :

enter image description here

and the same for numbers too, I try to do it with TfrxLineView but I fail.


Solution

  • Take the easy way :

    • Drop 4 TfrxMemoView component in your report (or as you need) like :

    enter image description here

    • In OnPreview event of your report, set your code for example:

      procedure TForm1.frxReport1Preview(Sender: TObject);
      var Str : WideString;   I : Integer;  Mem : TfrxMemoView;
      begin
         Str := 'Sami';   // Or get it from query/table (database)
      
         // Find the TFrxMemoView Component and set in it the String you want
         for I := 1 to 4 do
           begin
             Mem := frxReport1.FindObject('M'+IntToStr(I)) as TfrxMemoView;
             Mem.Text := Str[I];
           end;
        end;
      
    • The result will be :

    enter image description here

    Update :

    You can also do it programmatically as :

    var RT : TfrxBand;
        Mem : array [1..100] of TfrxMemoView ;
        i : Byte;
        Name : WideString;
    begin
      // Find the band
      RT := frxReport1.FindObject('RT') as TfrxBand;
      // Set the String
      Name := 'DELPHI FAST REPORT';
      for I := 1 to Length(Name) do
        begin
          Mem[i] := TfrxMemoView.Create(RT);
          Mem[i].Text :=  Name[i];
          Mem[i].Font.Style := [fsBold];
          Mem[i].Frame.Width := 2;
          Mem[i].Height := 20;
          Mem[i].AutoWidth := False;
          Mem[i].HAlign := haCenter;
          Mem[i].Frame.Typ := [ftLeft , ftBottom , ftRight];
          Mem[i].Width := 20;
          if i =1 then
            Mem[i].Left := 0
              else
                Mem[i].Left := Mem[i-1].Left + 5 + 15;
        end;
      frxReport1.ShowReport();
    end;
    

    The result is :

    enter image description here