Barcode Centering
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.
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
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.