Calc TfrxMemoView Width

Im writing a layout generation to print Grid and DataSet Contents, I not sure the best way to calc the Width and the left.

I configure the Designer to use CM as mensure, but if a pass the the CM values, is not good, I copy/past the component in a editor and see that is like screen px, is it?

I usually used the Canvas.TextHeight() and Canvas.TextWidth() functions to calc this, but I dont found and as TfrxMemoView is not TControl derivared I cannot typecast safely.

Iny sugestion, example to do this, in in FR3 framework any function?

[]s

Cesar

Comments

  • edited 11:11AM
    To calc the width and height of the memo, use TfrxMemoView.CalcWidth and CalcHeight methods.
  • edited 11:11AM
    CalcWidth will give the width of the content?

    I need to fix this with base in TField.DisplayWidth not the content, so the content can be truncated if is larger than Memo.Width, and I use this to calc the left of the next memo.

    []s
  • edited 11:11AM
    I create 3 bands in design, and then I pass the Field to create the 3 Memo, 1 to header, 2 Data and 3 footer, I pass the band to function:
    procedure TReportDataItem.CreateViews(HeaderBand, DataBand,
      FooterBand: TfrxBand);
    var
      lTempView: TfrxMemoView;
    begin
      if DataBand = nil then
      begin
        raise Exception.Create('Informe a DataBand (TfrxMasterData)');
        Exit;
      end;
    
      FDataView:= TfrxMemoView.Create(DataBand);
      lTempView:= TfrxMemoView.Create(DataBand);
    
      lTempView.Visible:= False;
      lTempView.Memo.Text:= DupeString('O', Field.DisplayWidth);
      lTempView.CalcHeight;
      lTempView.CalcWidth;
    
      with FDataView do
      begin
        CreateUniqueName;
        WordWrap:= False;
        Parent:= DataBand;
        DataSet:= TfrxMasterData(DataBand).DataSet;
    
        DataField:= Field.FieldName;
        Top:= 0;
        Height:= lTempView.Height;
        Width := lTempView.Width;
      end;
    
      if HeaderBand <> nil then
      begin
        FCaptionView:= TfrxMemoView.Create(HeaderBand);
        with FCaptionView do
        begin
          CreateUniqueName;
          Parent:= HeaderBand;
          Memo.Text:= Field.DisplayLabel;
          Top:= FDataView.Top;
          Height:= lTempView.Height;
          Width := lTempView.Width;
          WordWrap:= False;
          Font.Style:= [fsBold];
        end;
      end;
    
      if FooterBand <> nil then
      begin
        FFooterView:= TfrxMemoView.Create(FooterBand);
        with FFooterView do
        begin
          CreateUniqueName;
          Visible:= False;
          Parent:= FooterBand;
          Top:= FDataView.Top;
          Height:= FDataView.Height;
          WordWrap:= False;
          Width:= FDataView.Width;
          Font.Style:= [fsBold];
        end;
      end;
    
      if lTempView <> nil then
      begin
        lTempView.Free;
      end;
    end;
    

    but
    lTempView.CalcHeight;
    lTempView.CalcWidth;

    always returns 0 (Zero)

    what can be wrong?



    []s
  • edited 11:11AM
    var
    lTempView: TfrxMemoView;
    begin
    lTempView := TfrxMemoView.Create(nil);
    lTempView.Memo.Text:= 'OOOOOOOOOOOOO';
    Caption := FloatToStr(lTempView.CalcHeight) + ' ' + FloatToStr(lTempView.CalcWidth);
    end

    works well.
    One note: to calculate height, you should set large Width value to be sure that text lines will not wrap. I.e.

    lTempView := TfrxMemoView.Create(nil);
    lTempView.Memo.Text:= 'OOOOOOOOOOOOO';
    lTempView.Width := 1000;
    Caption := FloatToStr(lTempView.CalcHeight) + ' ' + FloatToStr(lTempView.CalcWidth);
  • edited 11:11AM
    Really works, thanx ;)

    []s

Leave a Comment