Forum > General
Problem with Generics.Defaults / Compiler message
Grahame Grieve:
Yes you're right. The enumeration is here: https://github.com/grahamegrieve/ZXing.Delphi/blob/v_3.0/Lib/Classes/Common/ZXing.BarCodeFormat.pas#L41
The List declaration is here: https://github.com/grahamegrieve/ZXing.Delphi/blob/611677e49fb4fcd021048985a638e04a85919b72/Lib/Classes/Common/ZXing.DecodeHintType.pas#L133
It's not my code, but it's forked so I can change it. But this is valid code, isn't it?
Thaddy:
--- Quote from: Grahame Grieve on November 21, 2022, 06:22:09 am ---It's not my code, but it's forked so I can change it. But this is valid code, isn't it?
--- End quote ---
Change the enum into constants should fix the error. In your enum there are holes, and for the holes there is no type info, only for the named enum members. The specialization needs proper type info. Your code is correct for non-generic applications. For generics you can do E.g.:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type TBarcodeFormat = type integer; const /// <summary>No format set. All formats will be used</summary> Auto = 0; /// <summary>Aztec 2D barcode format.</summary> AZTEC = 1; /// <summary>CODABAR 1D format.</summary> CODABAR = 2; /// <summary>Code 39 1D format.</summary> CODE_39 = 4; /// <summary>Code 93 1D format.</summary> CODE_93 = 8; /// <summary>Code 128 1D format.</summary> CODE_128 = 16; /// <summary>Data Matrix 2D barcode format.</summary> DATA_MATRIX = 32; /// <summary>EAN-8 1D format.</summary> EAN_8 = 64; /// <summary>EAN-13 1D format.</summary> EAN_13 = 128; /// <summary>ITF (Interleaved Two of Five) 1D format.</summary> ITF = 256; /// <summary>MaxiCode 2D barcode format.</summary> MAXICODE = 512; /// <summary>PDF417 format.</summary> PDF_417 = 1024; /// <summary>QR Code 2D barcode format.</summary> QR_CODE = 2048; /// <summary>RSS 14</summary> RSS_14 = 4096; /// <summary>RSS EXPANDED</summary> RSS_EXPANDED = 8192; /// <summary>UPC-A 1D format.</summary> UPC_A = 16384; /// <summary>UPC-E 1D format.</summary> UPC_E = 32768; /// <summary>UPC/EAN extension format. Not a stand-alone format.</summary> UPC_EAN_EXTENSION = 65536; /// <summary>MSI</summary> MSI = 131072; /// <summary>Plessey</summary> PLESSEY = 262144; Should have the least - if any at all - impact on your code and will work with generics.
- Anywhere TBarcodeFormat is referenced, code does not change
- The constants also fit in TBarcodeFormat so anywhere they are used the code need not change too. Untyped consts are a signed type.
- TBarcodeFormat = type Integer, because enums can be a signed type.
If you change just that unit to the above code all other units should keep working..
Thaddy:
Can you test this full modified replacement unit and report back?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{ * Copyright 2008 ZXing authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * Implemented by E. Spelt for Delphi * Implemented for Freepascal by Thaddy de Koning, 2022} unit ZXing.BarCodeFormat;{$ifdef fpc}{$mode delphi}{$endif}interface{$ifndef fpc}type TBarcodeFormat = ( /// <summary>No format set. All formats will be used</summary> Auto = 0, /// <summary>Aztec 2D barcode format.</summary> AZTEC = 1, /// <summary>CODABAR 1D format.</summary> CODABAR = 2, /// <summary>Code 39 1D format.</summary> CODE_39 = 4, /// <summary>Code 93 1D format.</summary> CODE_93 = 8, /// <summary>Code 128 1D format.</summary> CODE_128 = 16, /// <summary>Data Matrix 2D barcode format.</summary> DATA_MATRIX = 32, /// <summary>EAN-8 1D format.</summary> EAN_8 = 64, /// <summary>EAN-13 1D format.</summary> EAN_13 = 128, /// <summary>ITF (Interleaved Two of Five) 1D format.</summary> ITF = 256, /// <summary>MaxiCode 2D barcode format.</summary> MAXICODE = 512, /// <summary>PDF417 format.</summary> PDF_417 = 1024, /// <summary>QR Code 2D barcode format.</summary> QR_CODE = 2048, /// <summary>RSS 14</summary> RSS_14 = 4096, /// <summary>RSS EXPANDED</summary> RSS_EXPANDED = 8192, /// <summary>UPC-A 1D format.</summary> UPC_A = 16384, /// <summary>UPC-E 1D format.</summary> UPC_E = 32768, /// <summary>UPC/EAN extension format. Not a stand-alone format.</summary> UPC_EAN_EXTENSION = 65536, /// <summary>MSI</summary> MSI = 131072, /// <summary>Plessey</summary> PLESSEY = 262144 );{$else fpc} type TBarcodeFormat = type integer; const /// <summary>No format set. All formats will be used</summary> Auto = 0; /// <summary>Aztec 2D barcode format.</summary> AZTEC = 1; /// <summary>CODABAR 1D format.</summary> CODABAR = 2; /// <summary>Code 39 1D format.</summary> CODE_39 = 4; /// <summary>Code 93 1D format.</summary> CODE_93 = 8; /// <summary>Code 128 1D format.</summary> CODE_128 = 16; /// <summary>Data Matrix 2D barcode format.</summary> DATA_MATRIX = 32; /// <summary>EAN-8 1D format.</summary> EAN_8 = 64; /// <summary>EAN-13 1D format.</summary> EAN_13 = 128; /// <summary>ITF (Interleaved Two of Five) 1D format.</summary> ITF = 256; /// <summary>MaxiCode 2D barcode format.</summary> MAXICODE = 512; /// <summary>PDF417 format.</summary> PDF_417 = 1024; /// <summary>QR Code 2D barcode format.</summary> QR_CODE = 2048; /// <summary>RSS 14</summary> RSS_14 = 4096; /// <summary>RSS EXPANDED</summary> RSS_EXPANDED = 8192; /// <summary>UPC-A 1D format.</summary> UPC_A = 16384; /// <summary>UPC-E 1D format.</summary> UPC_E = 32768; /// <summary>UPC/EAN extension format. Not a stand-alone format.</summary> UPC_EAN_EXTENSION = 65536; /// <summary>MSI</summary> MSI = 131072; /// <summary>Plessey</summary> PLESSEY = 262144;{$endif}implementation end.Curious that the original works in Delphi with generics. Or does it?
Did you introduce the generics or is that also in the original sources? [edit] Ah, I see: ZXing.DecodeHintType;
Anyway, this unit should not require any code changes anywhere else. Not in Delphi and not in Freepascal.
I just tested that ZXing.DecodeHintType now compiles correctly which is at least an indication it should work anywhere else.
Note that IF you use this unit, you should not use scoped enums. The Lazarus example for vwf compiles with the original unit, not with mine.
Grahame Grieve:
Thanks. it compiles in Delphi, but I'm not entirely sure I'd know whether it works - I can read QR codes no problems in a web server, but is that the same as 'working?' - I don't know.
The changes weren't neutral to other code, since the code always prefixes the enum names with the type
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- TBarcodeFormat.CODE_128
but it's a simple search and replace
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- {$IFNDEF FPC}TBarcodeFormat{$ELSE}ZXing.BarCodeFormat{$ENDIF}.CODE_128
The original code should never have compiled at all, right? It shouldn't compile on the second pass, no? But the new code does compile with no problems
Thaddy:
It may be that because the sources use scoped enums, there is sufficient RTTI available in that case, but I will have to test that. The original demo compiles and works at least in Lazarus without changes. Strange problem :o :-\
Will investigate further. I will first try the original code with simply {$scopedenums on}
Navigation
[0] Message Index
[#] Next page
[*] Previous page