how do I customize barcode width?

I've seen some examples in forum, but I can't resolve the issue. It only change with the WideBarRatio property, but it isn't valid.
Always I want the width to be equal, 8cm; but... depending on text, barcode have a different width.

I'm using Code128 and Ean128.

thx a lot

Comments

  • edited 5:49PM
    I've seen some examples in forum, but I can't resolve the issue. It only change with the WideBarRatio property, but it isn't valid.
    Always I want the width to be equal, 8cm; but... depending on text, barcode have a different width.

    I'm using Code128 and Ean128.

    thx a lot

    Depending on how much data is placed inside the barcode, it grows. I did something like this. It is not perfect but works in the situations where I needed fixed width barcodes. Important remark, do not make the required width too small or the barcode will not be scannable:
    TLocusBarcodeView = class(TfrxBarCodeView)
      private
        FRequiredWidth: extended;
      private
        procedure CalculateZoom;
      protected
        procedure setRequiredWidth(const aValue: extended);
      public
        constructor Create(AOwner: TComponent); override;
        procedure GetData; override;
      published
        property RequiredWidth: extended read FRequiredWidth write SetRequiredWidth;
      end;
    
    constructor TLocusBarcodeView.Create(AOwner: TComponent);
    begin
      inherited;
    
      FRequiredWidth := 0.0;
    end;
    
    
    procedure TLocusBarcodeView.CalculateZoom;
    
      procedure Calculate;
      var
        r : TfrxRect;
        RealWidth: extended;
      begin
        r := GetRealBounds;
        RealWidth := (r.Right - r.Left);
        if (RealWidth > 0.01) and (CompareValue(RealWidth, RequiredWidth, 0.01)<>EqualsValue) then
        begin
          Zoom := RequiredWidth/RealWidth;
        end;
      end;
    
    begin
      Calculate;
    end;
    
    
    procedure TLocusBarcodeView.GetData;
    
    function AddLeadingZeroes(const aNumber: string; const Length : integer) : string;
    begin
      try
        Result := Format('%.*d', [Length, strtoint(aNumber)]);
      except
        Result := aNumber;
      end;
    end;
    
    begin
      inherited;
    
      case BarType of
        bcCodeEAN8:
        begin
          Text := AddLeadingZeroes(Text,8);
        end;
      end;
    
      if (RequiredWidth > 0.0) then
      begin
        Zoom := 1.0;
        CalculateZoom;
      end;
    end;
    
    
    procedure TLocusBarcodeView.setRequiredWidth(const aValue: extended);
    begin
      FRequiredWidth := aValue;
    end;
    

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.