Hi all, i was wondering if anyone has ha any experience drawing a barcode with ABMaterial framework, specifically on a modalsheet.
I found this thread which has a few code modules that generate different types of barcodes, while the code is very simple to follow, it requires a canvas object to draw the barcode on.
I found that with ABMaterial there is a ABMCanvas object, but it seems to be a bit different than the standard Canvas Object in B4X, I tried replacing the regular Canvas object with the ABMaterialCanvas Object but for some reason I can't seem to get this to work.
Below is my code.
This part is inside the ModalSheet generation code.
Inside the modalsheet I have a table, and the idea is that when the user Enters a PartNumber, the part number should be used to generate a barcode and show it below the table.
The code below shows when a change is done on any column of the table.
And Here's is the code that should actually generate the barcode which is based on the examples shown on the link provided above.
I'm not sure if I'm not understanding correctly how the ABMCanvas object should be used, but it just doesn't seem to draw anything.
I also found another thread somewhere mentioning that there was a bug on ABMaterial when trying to draw a canvas inside a modalsheet, can't find that thread for now, but not sure if this was already fixed or not.
Does anyone have any other ideas on how to accomplish this?
Walter
I found this thread which has a few code modules that generate different types of barcodes, while the code is very simple to follow, it requires a canvas object to draw the barcode on.
I found that with ABMaterial there is a ABMCanvas object, but it seems to be a bit different than the standard Canvas Object in B4X, I tried replacing the regular Canvas object with the ABMaterialCanvas Object but for some reason I can't seem to get this to work.
Below is my code.
B4X:
Dim cnvs1 As ABMCanvas
cnvs1.Initialize(page, "barcodecanvas", ABM.COLOR_BLACK, ABM.INTENSITY_DARKEN4, 800, 400dip, False)
cont1.Cell(2, 1).AddComponent(cnvs1)
Dim cnvObject As ABMCanvasObject
cnvObject.InitializeAsRectangle(page, "cnvObject", 0, 0, 800, 400, False)
cnvs1.AddObject(cnvObject)
cnvs1.Refresh
This part is inside the ModalSheet generation code.
Inside the modalsheet I have a table, and the idea is that when the user Enters a PartNumber, the part number should be used to generate a barcode and show it below the table.
The code below shows when a change is done on any column of the table.
B4X:
Sub itemEntryTable_Changed(Params As Map)
''Log("params changed: " & Params)
Dim col, row As Int
col = Params.Get("column")
row = Params.Get("row")
Dim val As String
If col = 1 And row = 0 Then
val = Params.Get("value")
Dim modal As ABMModalSheet = page.ModalSheet("ItemEntry") '''page.Component("ItemEntry")
Dim container As ABMContainer = modal.Content.Component("itementrycontainer")
Log("container id: " & container.ID)
Dim cnv As ABMCanvas = container.Component("barcodecanvas")
Dim cnvObject As ABMCanvasObject = cnv.GetObject("cnvObject")
draw_barcode_Code39(cnvObject, Code39.Draw_Code39("1234567890"))
cnv.Refresh
cnvObject.Refresh
'''modal.Refresh
End If
End Sub
And Here's is the code that should actually generate the barcode which is based on the examples shown on the link provided above.
B4X:
Sub draw_barcode_Code39 (cnv As ABMCanvasObject, mes As String)
Dim su As StringUtilities
su.Initialize
Dim mywidth As Int = cnv.Width
Dim myheight As Int = cnv.Height
Dim silent As Int = (mywidth - 4*su.stringLength(mes))/2
Log (mywidth)
Log (myheight)
Log (silent)
cnv.beginPath
Dim cnt As Int = silent + 1
For i = 0 To su.stringLength(mes) - 1
If su.Mid(mes,i,1) = "1" Then
'''cnv.fillRect(cnt, 10, 4, 80)
'''cnv.rect(cnt, 10, 4, 80)
cnv.fillText("Walter", cnt, 80)
cnv.fillStyleColor(ABM.COLOR_BLACK)
cnv.fill
'''cnv.DrawRect(cnt,10,4,80,ABM.COLOR_BLACK,True,2)
Else
'''Canvas2.DrawRect(cnt,10,4,80,fx.Colors.White,True,2)
cnv.rect(cnt, 10, 4, 80)
cnv.fillStyleColor(ABM.COLOR_WHITE)
cnv.fill
'''cnv.fillRect(cnt, 10, 4, 80)
End If
cnt = cnt + 4
Next
''' cnv.Refresh
End Sub
I'm not sure if I'm not understanding correctly how the ABMCanvas object should be used, but it just doesn't seem to draw anything.
I also found another thread somewhere mentioning that there was a bug on ABMaterial when trying to draw a canvas inside a modalsheet, can't find that thread for now, but not sure if this was already fixed or not.
Does anyone have any other ideas on how to accomplish this?
Walter