How to get the good barcode with

On the report I have one master data band. On the band there is 1 barcode which has the next name: bar_Artikel.

Before I prepare the report, I set the type of barcode in the delphi code:
    Barcode := TfrBarCodeView(Report.FindObject('bar_Artikel'));
    Barcode.Param.cBarType := bcCodePostNet;

Before this code, the barcode has another bartype!

Then I want to get the width of the barcode in a OnBeforePrint event. But I don't get the good width, but I get the width of the barcode before I changed the type.


But I have seen a strange problem. When you double click on the barcode in de designer and then you change some options and presses the OK button, the barcode is updated.

When I use the barcode property of the inspector, I get the same form where I can set some options. But when I presses now the OK button, the barcode is not updated (I mean drawing the barcode with the new options).

So I think here is somewhere the problem.

Does anybody know how I can fix this problem?

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 6:48PM
    I assume tou are trying to center the barcode on a label.
    barcode centering on a label
    since the barcode object does not have its width untill it gets its data
    and it doesn't build around it's center point.
    we have to modify it on the fly.
    This is not perfect but gets close enough
    based on a zoom factor of 1
    first report must be 2pass

    obp event mdband code

    begin

    recid :=[Table2."Idno"];
    // index for array is set
    //retrive val from array if on final pass and store in myval
    // the value is actually loaded into the array in the script of the
    // barcode memo
    if finalpass then myval := arrbcw[recid]
    else myval:= 0 ;
    if finalpass then
    begin
    if (myval = 1) then bar1.left:= 119;
    if (myval > 1) and (myval <7) then bar1.left := (119 - [ROUND((myval*5))]);
    if (myval > 6) and (myval <11) then bar1.left := (115 - [ROUND((myval*5))]);
    if (myval > 10) and (myval <13) then bar1.left := (110 - [ROUND((myval*5))]);
    if (myval > 12) and (myval <15) then bar1.left := (107 - [ROUND((myval*5))]);
    if (myval > 14) and (myval <=16) then bar1.left := (104 - [ROUND((myval*5))]);
    end
    end

    script of barcode memo code
    // get length of the datastring and store in array
    begin
    if not finalpass then
    arrbcw[recid]:=[LENGTH([Table2."Bcstring"])]
    end

    or you can rewrite the barcode units code

    regards ;)
  • edited 6:48PM
    I use the code to center the barcode in a rectangle. The report prints an X number of articles with barcodes.

    Each barcode could be a different type and has a different number.
  • edited 6:48PM
    Is it possible to go through the report (all pages) after the report is prepared and then center the barcode, because the barcode has its good width?
  • edited 6:48PM
    I found the solution. On all pages of the report I use the same type of barcode.

    In my program I create an instance of TfrBarcode.

    In the OBP event of the barcode I have this code:
      if finalpass then
        bar_Artikel.Left := Shape55.Left + (((shp_OmtrekArtikel.Left + shp_OmtrekArtikel.Width - Shape55.Left) - GetBarWidth([frm_BestelboekAfdrukken.cldtst_Bestelboek."ARTIKELNUMMER"])) / 2);
    


    The userdefined function GetBarWidth:
    procedure Tfrm_Reports.fstrp_MainUserFunction(const Name: String; p1, p2, p3: Variant; var Val: Variant);
    var ArtikelNummer: String;
    begin
      if Name = 'GETBARWIDTH' then
      begin
        ArtikelNummer := frParser.Calc(p1);
        frm_Main.Barcode.Text := ArtikelNummer;
        Val := frm_Main.Barcode.GetWidth;
      end;
    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.