Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Field Auto Size feature

edited March 2002 in General
Hi,
I would like to display in the DBText with '*****' characters if the
actual data size exceed the size of the displayable width. I needed to set
the AutoSize of the DBText to false due to some reasons. Any suggestion
will be appreciated.

Thomas Liaw

Comments

  • edited March 2002
    This can be accomplished by placing a Variable on the form in place of the
    DBText and making sure the type of the variable is String and that no
    formatting is applied. In the OnCalc of the Variable pull the data of
    interest from the data pipeline as a string, compute it's pixel width, and
    compare it to the width of the Variable field to see if the String will fit.
    Below is sample code that pulls a data string from the pipeline and, if it
    is too wide, fills theVariable field with '*'s.

    ----------------------------------------------------------------------------
    ------------------------------------

    function TForm1.WidthInReportUnits(aString: String): Single;
    var
    liWidthPixels: Integer;
    liWidthMM: Integer;
    begin

    { Get the width of the string }
    liWidthPixels := ppReport1.Printer.Canvas.TextWidth(aString);

    { Convert width to report units }
    liWidthMM := ppToMMThousandths(liWidthPixels, utPrinterPixels,
    pprtHorizontal, ppReport1.Printer);
    Result := ppFromMMThousandths(liWidthMM, ppReport1.Units, pprtHorizontal,
    ppReport1.Printer);

    end;


    procedure TForm1.ppVariable1Calc(Sender: TObject; var Value: Variant);
    var
    lsString: String;
    liStringWidth: Single;
    liStarCount: Integer;
    liIndex: Integer;
    begin

    Value := '';

    // retrieve the desired data value as a string
    lsString := ppReport1.DataPipeline.GetFieldForName('Company').AsString;

    // compute the string width
    liStringWidth := WidthInReportUnits(lsString);

    // if that width is less than the text field, the value fits
    if (liStringWidth <= ppVariable1.Width) then
    Value := lsString

    // otherwise...
    else
    begin
    // compute width of one star character
    liStringWidth := WidthInReportUnits('*');

    // compute the number of start needed to fill the field
    liStarCount := Trunc(ppVariable1.Width / liStringWidth);

    // build the string of stars
    for liIndex := 0 to liStarCount - 1 do
    Value := Value + '*';
    end;

    end;


    ----------------------------------------------------------------------------
    ------------------------------------

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

  • edited March 2002
    Hi Alex,
    Thanks you for your reply. It is certainly not so simple to implement
    for what I saked for.
    For most of my situations, my concern is on the numeric fields rather
    than string fields. There are limited space for us to put the numeric
    results fields on the report form and setting autosize to true will make the
    DBText all overlapped one another and making my support personnel a hard
    time in field support. So we have to set the DBText to non-autosize and
    make sure no overlaping amount the fields. In certain condition where we
    underestimate the amount of the numeric result, the DBText will automatic
    trancate the print out, making the end user thinking is a incorrect
    calculation but in fact is the insufficient width in DBText. If Report
    Builder have an options for the report designer to print just '****' in this
    kind of situation, we can easily educate the end users and thus making
    support personnel easier to support them. I guess this can be only put into
    the wish list. If you do have a solution that I can write it as an wrapper
    function, said to ppReport, please let me know (We have thousands of such
    numeric fileds).

    Thomas Liaw
  • edited March 2002
    You can provide such a solution to your end-users by creating a custom
    component. An example of a static sized DBText component has been created
    and can be obtained from
    www.digital-metaphors.com/tips/CustomDBTextComponent.zip. You can include
    the package in the example with your report to provide the component in the
    designer at run time or install it in delphi to provide the component in
    report designer at design time.

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

This discussion has been closed.