Barcode Centering

edited 11:24AM in FastReport 4.0
Hi,

I think I have found an issue with the barcode component. I am trying to print a barcode on a label sheet, where each label is half the width of the physical page. I need the barcode to be centered horizontally on the label, not the sheet, so I added this to the OnAfterData event for the barcode:

procedure BarCode1OnAfterData(Sender: TfrxComponent);
begin
// center barcode on the label
BarCode1.Left := ( Shape1.Width - BarCode1.Width ) / 2;
end;


Shape1 is a rectangle which has the width of the label. The intention of the code is to center the barcode component within Shape1.

This doesn't work though, as Barcode1 doesn't change width when its Text property changes (i.e. when an actual value is assigned from the database). I have proven this by adding a couple of ShowMessage calls to the body of the event handler above.

Am I missing something? Can anyone think of a smart way to achieve what I am trying to achieve?

On a related note - it seems very odd that the properties of the components are not in physical units when accessed in a script. Example: the Width property for the barcode1 component is shown in the designer as 3.5 but when running the script it comes out as 123. This makes it un-neccesarily difficult to bind together design-time values and run-time values.

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 11:24AM
    use the CalcWidth property of the barcode not the design property width
  • edited 11:24AM
    gordk wrote: »
    use the CalcWidth property of the barcode not the design property width

    That doesn't seem to work - I get a script error that CalcWidth property does not exist when I run the report...

    procedure BarCode1OnAfterData(Sender: TfrxComponent);
    begin
    // center barcode on the label
    BarCode1.Left := ( Shape1.Width - BarCode1.CalcWidth ) / 2;
    end;

    I have a work-round in place involving a user function to recalculate the size of the bar code control, but I would prefer a cleaner solution.

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.