網(wǎng)站建設(shè)與管理教程視頻教程搜索引擎環(huán)境優(yōu)化
??
目錄
一、場(chǎng)景說明
二、廠家應(yīng)提供的SDK文件
三、操作步驟:
1. 導(dǎo)出Delphi需要且能使用的接口文件:
2. 創(chuàng)建FMX Delphi項(xiàng)目,將上一步生成的接口文件(V510.Interfaces.pas)引入:
3. 將jarsdk.jar 包加入到 libs中:
?4. Delphi中調(diào)用:
四、完整源代碼下載
五、總結(jié):
一、場(chǎng)景說明
????????Delphi的FMX是支持開發(fā)android程序的,如果只是開發(fā)通用的android程序,使用delphi就很簡(jiǎn)單,官方的Demo也非常豐富。但是有時(shí)候我們需要開發(fā)一些專用的手持機(jī)的程序,手持機(jī)是Android系統(tǒng)。比如我曾經(jīng)開發(fā)過天波的TPS900、群鎖的QS5501、金泰宜的V510等等。這些手持機(jī)都集成有熱敏打印機(jī)(58mm)。我們的程序需要使用打印功能,這就需要調(diào)用廠家提供的打印函數(shù)。遺憾的是打印功能并不是android的標(biāo)準(zhǔn)功能,所以各個(gè)廠家提供的函數(shù)都不一樣,就必須每個(gè)廠家進(jìn)行分別適配調(diào)試。另外像TPS900、QS5501等還集成有身份證讀卡器,還支持身份證讀卡功能。這也不是android的標(biāo)準(zhǔn)功能,也需要各個(gè)廠家分別適配調(diào)試。
? ? ? ? 本文介紹如何適配這針對(duì)金泰宜的V510詳細(xì)介紹Delphi適配非標(biāo)準(zhǔn)Android功能的開發(fā)流程,就用打印功能作為樣例。對(duì)于其他的非android標(biāo)準(zhǔn)功能,操作方法是一致的。
二、廠家應(yīng)提供的SDK文件
對(duì)于打印功能,廠家應(yīng)該提供如下文件:
序號(hào) | 文件 | 說明 |
1 | .jar包 | 這個(gè)是一個(gè)關(guān)鍵文件,Delphi能夠調(diào)用(使用)的java包文件,包含使用打印功能的所有函數(shù)。 |
2 | Demo程序 | java代碼的Demo打印程序,源程序和APK。對(duì)應(yīng)的APK程序,已經(jīng)安裝在手持機(jī)上。 |
3 | 打印功能(函數(shù))使用說明 | 就是調(diào)用jar打印功能函數(shù)的使用說明 |
比如金泰宜的V510提供了如何的文件,為了大家方便我提供了下載鏈接:
序號(hào) | 文件 | 說明 |
1 | jarsdk.jar | jar包文件 |
2 | newprintdemo.zip | java調(diào)用的Demo程序 |
3 | 打印SDK指南.pdf 金泰誼 OS API 編程手冊(cè)_2023_05_09.pdf | 就是調(diào)用jar打印功能函數(shù)的使用說明 |
三、操作步驟:
1. 導(dǎo)出Delphi需要且能使用的接口文件:
????????使用delphi 官方提供的java2OP.exe,通過jarsdk.jar導(dǎo)出Delphi需要的接口文件,也就是將java類導(dǎo)出成delphi能調(diào)用的接口文件。
? ? ? ? 如果是Delphi 11.3,對(duì)應(yīng)的 java2OP.exe 位于:
????????C:\Program Files (x86)\Embarcadero\Studio\22.0\bin\converters\java2op
通過?java2OP.exe 程序可以將java開發(fā)的jar包轉(zhuǎn)換成Delphi使用的.pas接口文件。java2OP.exe 是一個(gè)控制臺(tái)程序,支持命令行參數(shù)。
- Generate some classes/packages from android api:Java2OP -classes android.net.ConnectivityManager android.speech.*- Generate all classes from mylib.jarJava2OP -jar mylib.jar- Generate some class from mylib.jarJava2OP -jar mylib.jar -classes com.mypackage.ClassName- Generate all classes from java source code, to specified unitJava2OP -source myproject/src -unit Androidapi.JNI.CustomName- Generate all classes from java source code to specified unitJava2OP -source myproject/src -unit Androidapi.JNI.CustomName
序號(hào) | 參數(shù) | 說明 |
1 | -jar | 需要導(dǎo)出的.jar文件 |
2 | -classes | 需要導(dǎo)出的包名稱 |
3 | -source | 需要導(dǎo)出的java源文件(一般不用) |
4 | -unit | 生成的Delphi文件及包名稱 |
針對(duì)我們的V510,命令如下:
C:\Temp\java2pas>java2OP -jar jarsdk.jar -unit V510.Interfaces -classes ktp.demo.mylibrary.api
注意:
?????????ktp.demo.mylibrary.api 包名是廠家告知的,如果廠家沒有告知,那就只能導(dǎo)出全部接口,此時(shí)就不需要提供 -classes 參數(shù),這樣就會(huì)導(dǎo)出全部java類和對(duì)象。如果導(dǎo)出的.pas文件編譯不通過,就需要自行進(jìn)行調(diào)整。一般來說導(dǎo)出具體的包還好,如果導(dǎo)出全部出現(xiàn)問題,那么可以通過導(dǎo)出的文件找到我們實(shí)際需要導(dǎo)出的包名,然后再直接重新只導(dǎo)出具體的包。
以上命令執(zhí)行成功后,導(dǎo)出的文件(V510.Interfaces.pas)內(nèi)容如下:
unit V510.Interfaces;interfaceusesAndroidapi.JNIBridge,Androidapi.JNI.GraphicsContentViewText,Androidapi.JNI.JavaTypes,Androidapi.JNI.Os;type
// ===== Forward declarations =====JBarcodeFormat = interface;//com.google.zxing.BarcodeFormatJPaperType = interface;//ktp.demo.mylibrary.PaperTypeJPrintErrorType = interface;//ktp.demo.mylibrary.PrintErrorTypeJPrintItemObj = interface;//ktp.demo.mylibrary.PrintItemObjJPrintItemObj_ALIGN = interface;//ktp.demo.mylibrary.PrintItemObj$ALIGNJmylibrary_PrintManager = interface;//ktp.demo.mylibrary.PrintManagerJPrintManager_PrintCallback = interface;//ktp.demo.mylibrary.PrintManager$PrintCallbackJmylibrary_api = interface;//ktp.demo.mylibrary.api// ===== Interface declarations =====JBarcodeFormatClass = interface(JEnumClass)['{78718E02-033C-44B2-A9EF-D001EFA8A366}']{class} function _GetAZTEC: JBarcodeFormat; cdecl;{class} function _GetCODABAR: JBarcodeFormat; cdecl;{class} function _GetCODE_128: JBarcodeFormat; cdecl;{class} function _GetCODE_39: JBarcodeFormat; cdecl;{class} function _GetCODE_93: JBarcodeFormat; cdecl;{class} function _GetDATA_MATRIX: JBarcodeFormat; cdecl;{class} function _GetEAN_13: JBarcodeFormat; cdecl;{class} function _GetEAN_8: JBarcodeFormat; cdecl;{class} function _GetITF: JBarcodeFormat; cdecl;{class} function _GetMAXICODE: JBarcodeFormat; cdecl;{class} function _GetPDF_417: JBarcodeFormat; cdecl;{class} function _GetQR_CODE: JBarcodeFormat; cdecl;{class} function _GetRSS_14: JBarcodeFormat; cdecl;{class} function _GetRSS_EXPANDED: JBarcodeFormat; cdecl;{class} function _GetUPC_A: JBarcodeFormat; cdecl;{class} function _GetUPC_E: JBarcodeFormat; cdecl;{class} function _GetUPC_EAN_EXTENSION: JBarcodeFormat; cdecl;{class} function valueOf(string_: JString): JBarcodeFormat; cdecl;{class} function values: TJavaObjectArray<JBarcodeFormat>; cdecl;{class} property AZTEC: JBarcodeFormat read _GetAZTEC;{class} property CODABAR: JBarcodeFormat read _GetCODABAR;{class} property CODE_128: JBarcodeFormat read _GetCODE_128;{class} property CODE_39: JBarcodeFormat read _GetCODE_39;{class} property CODE_93: JBarcodeFormat read _GetCODE_93;{class} property DATA_MATRIX: JBarcodeFormat read _GetDATA_MATRIX;{class} property EAN_13: JBarcodeFormat read _GetEAN_13;{class} property EAN_8: JBarcodeFormat read _GetEAN_8;{class} property ITF: JBarcodeFormat read _GetITF;{class} property MAXICODE: JBarcodeFormat read _GetMAXICODE;{class} property PDF_417: JBarcodeFormat read _GetPDF_417;{class} property QR_CODE: JBarcodeFormat read _GetQR_CODE;{class} property RSS_14: JBarcodeFormat read _GetRSS_14;{class} property RSS_EXPANDED: JBarcodeFormat read _GetRSS_EXPANDED;{class} property UPC_A: JBarcodeFormat read _GetUPC_A;{class} property UPC_E: JBarcodeFormat read _GetUPC_E;{class} property UPC_EAN_EXTENSION: JBarcodeFormat read _GetUPC_EAN_EXTENSION;end;[JavaSignature('com/google/zxing/BarcodeFormat')]JBarcodeFormat = interface(JEnum)['{295EEC59-8B4F-4030-9659-F1C1D60A5B44}']end;TJBarcodeFormat = class(TJavaGenericImport<JBarcodeFormatClass, JBarcodeFormat>) end;JPaperTypeClass = interface(JEnumClass)['{A277D0EB-DDC7-4426-A169-59550541C3D2}']{class} function _GetLABEL: JPaperType; cdecl;{class} function _GetTHERMAL: JPaperType; cdecl;{class} function valueOf(string_: JString): JPaperType; cdecl;{class} function values: TJavaObjectArray<JPaperType>; cdecl;{class} property &LABEL: JPaperType read _GetLABEL;{class} property THERMAL: JPaperType read _GetTHERMAL;end;[JavaSignature('ktp/demo/mylibrary/PaperType')]JPaperType = interface(JEnum)['{978D7B0C-0F25-41E7-80F6-293F68512E37}']function getValue: Integer; cdecl;end;TJPaperType = class(TJavaGenericImport<JPaperTypeClass, JPaperType>) end;JPrintErrorTypeClass = interface(JEnumClass)['{E632FB4B-F40C-49C4-BF62-C87248052CA7}']{class} function _GetOUT_OF_PAPER: JPrintErrorType; cdecl;{class} function _GetOVERHEATED: JPrintErrorType; cdecl;{class} function valueOf(string_: JString): JPrintErrorType; cdecl;{class} function values: TJavaObjectArray<JPrintErrorType>; cdecl;{class} property OUT_OF_PAPER: JPrintErrorType read _GetOUT_OF_PAPER;{class} property OVERHEATED: JPrintErrorType read _GetOVERHEATED;end;[JavaSignature('ktp/demo/mylibrary/PrintErrorType')]JPrintErrorType = interface(JEnum)['{F0520F8F-B774-4941-A0FE-1AB567E23ACE}']function getValue: Integer; cdecl;end;TJPrintErrorType = class(TJavaGenericImport<JPrintErrorTypeClass, JPrintErrorType>) end;JPrintItemObjClass = interface(JParcelableClass)['{C3A9B0BA-170D-4E89-BB8B-3961B2A0730A}']{class} function _GetCREATOR: JParcelable_Creator; cdecl;{class} function init(parcel: JParcel): JPrintItemObj; cdecl; overload;{class} function init(string_: JString): JPrintItemObj; cdecl; overload;{class} function init(string_: JString; i: Integer): JPrintItemObj; cdecl; overload;{class} function init(string_: JString; i: Integer; b: Boolean): JPrintItemObj; cdecl; overload;{class} function init(string_: JString; i: Integer; b: Boolean; aLIGN: JPrintItemObj_ALIGN): JPrintItemObj; cdecl; overload;{class} function init(string_: JString; i: Integer; b: Boolean; aLIGN: JPrintItemObj_ALIGN; b1: Boolean): JPrintItemObj; cdecl; overload;{class} function init(string_: JString; i: Integer; b: Boolean; aLIGN: JPrintItemObj_ALIGN; b1: Boolean; b2: Boolean): JPrintItemObj; cdecl; overload;{class} function init(string_: JString; i: Integer; b: Boolean; aLIGN: JPrintItemObj_ALIGN; b1: Boolean; b2: Boolean; i1: Integer): JPrintItemObj; cdecl; overload;{class} function init(string_: JString; i: Integer; b: Boolean; aLIGN: JPrintItemObj_ALIGN; b1: Boolean; b2: Boolean; i1: Integer; i2: Integer): JPrintItemObj; cdecl; overload;{class} function init(string_: JString; i: Integer; b: Boolean; aLIGN: JPrintItemObj_ALIGN; b1: Boolean; b2: Boolean; i1: Integer; i2: Integer; i3: Integer; i4: Integer): JPrintItemObj; cdecl; overload;{class} property CREATOR: JParcelable_Creator read _GetCREATOR;end;[JavaSignature('ktp/demo/mylibrary/PrintItemObj')]JPrintItemObj = interface(JParcelable)['{FBEE3808-C71D-44CC-8950-A59EE0E60FC9}']function _Getalign: JPrintItemObj_ALIGN; cdecl;function describeContents: Integer; cdecl;function getAlign: JPrintItemObj_ALIGN; cdecl;function getFontSize: Integer; cdecl;function getGrayscale: Integer; cdecl;function getLetterSpacing: Integer; cdecl;function getLineHeight: Integer; cdecl;function getMarginLeft: Integer; cdecl;function getText: JString; cdecl;function isBold: Boolean; cdecl;function isUnderline: Boolean; cdecl;function isWordWrap: Boolean; cdecl;procedure setAlign(aLIGN: JPrintItemObj_ALIGN); cdecl;procedure setBold(b: Boolean); cdecl;procedure setFontSize(i: Integer); cdecl;procedure setGrayscale(i: Integer); cdecl;procedure setLetterSpacing(i: Integer); cdecl;procedure setLineHeight(i: Integer); cdecl;procedure setMarginLeft(i: Integer); cdecl;procedure setText(string_: JString); cdecl;procedure setUnderline(b: Boolean); cdecl;procedure setWordWrap(b: Boolean); cdecl;procedure writeToParcel(parcel: JParcel; i: Integer); cdecl;property align: JPrintItemObj_ALIGN read _Getalign;end;TJPrintItemObj = class(TJavaGenericImport<JPrintItemObjClass, JPrintItemObj>) end;JPrintItemObj_ALIGNClass = interface(JEnumClass)['{6147BA1C-2579-4AF8-9734-2F4CAE057058}']{class} function _GetCENTER: JPrintItemObj_ALIGN; cdecl;{class} function _GetLEFT: JPrintItemObj_ALIGN; cdecl;{class} function _GetRIGHT: JPrintItemObj_ALIGN; cdecl;{class} function valueOf(string_: JString): JPrintItemObj_ALIGN; cdecl;{class} function values: TJavaObjectArray<JPrintItemObj_ALIGN>; cdecl;{class} property CENTER: JPrintItemObj_ALIGN read _GetCENTER;{class} property LEFT: JPrintItemObj_ALIGN read _GetLEFT;{class} property RIGHT: JPrintItemObj_ALIGN read _GetRIGHT;end;[JavaSignature('ktp/demo/mylibrary/PrintItemObj$ALIGN')]JPrintItemObj_ALIGN = interface(JEnum)['{D680D77D-BC9C-4325-BEBC-514EFFB84DD9}']end;TJPrintItemObj_ALIGN = class(TJavaGenericImport<JPrintItemObj_ALIGNClass, JPrintItemObj_ALIGN>) end;Jmylibrary_PrintManagerClass = interface(JObjectClass)['{1144647F-3D81-4271-9289-867BD8E6577A}']{class} function init: Jmylibrary_PrintManager; cdecl; overload;{class} function init(handler: JHandler; context: JContext): Jmylibrary_PrintManager; cdecl; overload;{class} function init(handler: JHandler; context: JContext; i: Integer): Jmylibrary_PrintManager; cdecl; overload;//Deprecatedend;[JavaSignature('ktp/demo/mylibrary/PrintManager')]Jmylibrary_PrintManager = interface(JObject)['{EBBC0620-4EC9-431D-88CA-257B12EAEDEA}']procedure addPrintTask(runnable: JRunnable); cdecl;procedure print(printItemObj: JPrintItemObj; bitmap: JBitmap); cdecl; overload;procedure print(bitmap: JBitmap; paperType: JPaperType); cdecl; overload;procedure setPrinterGray(i: Integer); cdecl;procedure stop; cdecl;end;TJmylibrary_PrintManager = class(TJavaGenericImport<Jmylibrary_PrintManagerClass, Jmylibrary_PrintManager>) end;JPrintManager_PrintCallbackClass = interface(IJavaClass)['{5C7AE6B2-217B-43D0-B5F8-D3FC8A4373D8}']{class} procedure onPrintStart; cdecl;//Deprecatedend;[JavaSignature('ktp/demo/mylibrary/PrintManager$PrintCallback')]JPrintManager_PrintCallback = interface(IJavaInstance)['{BABF6796-9708-4DA2-89E0-8956E31EE4FA}']procedure onPrintError(printErrorType: JPrintErrorType); cdecl;procedure onPrintFinish; cdecl;end;TJPrintManager_PrintCallback = class(TJavaGenericImport<JPrintManager_PrintCallbackClass, JPrintManager_PrintCallback>) end;Jmylibrary_apiClass = interface(JObjectClass)['{D4F76228-7CBE-4989-99AA-A4FC39CB31BD}']{class} function getInstance(context: JContext; handler: JHandler): Jmylibrary_api; cdecl;end;[JavaSignature('ktp/demo/mylibrary/api')]Jmylibrary_api = interface(JObject)['{EF208218-7A25-45ED-AEFF-A265FAC646E1}']function PrinInt: Byte; cdecl;procedure PrnAttrSet(i: Integer); cdecl;procedure PrnDoubleHeight(i: Integer; i1: Integer); cdecl;procedure PrnDoubleWidth(i: Integer; i1: Integer); cdecl;procedure PrnFontSet(b: Byte; b1: Byte); cdecl;procedure PrnGetDotLine; cdecl;procedure PrnGetFontDot(i: Integer; string_: JString; b: TJavaArray<Byte>); cdecl;function PrnGetTemperature: Integer; cdecl;procedure PrnLeftIndent(s: SmallInt); cdecl;procedure PrnSetFontFile(string_: JString); cdecl;procedure PrnSetGray(i: Integer); cdecl;procedure PrnSpaceSet(b: Byte; b1: Byte); cdecl;procedure PrnSpeStr(string_: JString; i: Integer; b: Boolean; b1: Boolean; i1: Integer); cdecl;procedure PrnStart; cdecl;function PrnStatus: Byte; cdecl;procedure PrnStep(s: SmallInt); cdecl;procedure PrnStr(string_: JString); cdecl;procedure SdkMoveLabelStep; cdecl;procedure prnBitmap(bitmap: JBitmap); cdecl;procedure sdkPrintBarCode(i: Integer; i1: Integer; barcodeFormat: JBarcodeFormat; string_: JString; printCallback: JPrintManager_PrintCallback); cdecl;procedure sdkPrintPic(bitmap: JBitmap; i: Integer; i1: Integer; i2: Integer; printCallback: JPrintManager_PrintCallback); cdecl;procedure sdkPrintText(string_: JString; i: Integer; b: Boolean; b1: Boolean; i1: Integer; printCallback: JPrintManager_PrintCallback); cdecl;procedure sdkSetPrinterGray(i: Integer); cdecl;procedure sdkSetThermalPrinterOrLabel(i: Integer); cdecl;function sdkVersion: JString; cdecl;end;TJmylibrary_api = class(TJavaGenericImport<Jmylibrary_apiClass, Jmylibrary_api>) end;implementationprocedure RegisterTypes;
beginTRegTypes.RegisterType('V510.Interfaces.JBarcodeFormat', TypeInfo(V510.Interfaces.JBarcodeFormat));TRegTypes.RegisterType('V510.Interfaces.JPaperType', TypeInfo(V510.Interfaces.JPaperType));TRegTypes.RegisterType('V510.Interfaces.JPrintErrorType', TypeInfo(V510.Interfaces.JPrintErrorType));TRegTypes.RegisterType('V510.Interfaces.JPrintItemObj', TypeInfo(V510.Interfaces.JPrintItemObj));TRegTypes.RegisterType('V510.Interfaces.JPrintItemObj_ALIGN', TypeInfo(V510.Interfaces.JPrintItemObj_ALIGN));TRegTypes.RegisterType('V510.Interfaces.Jmylibrary_PrintManager', TypeInfo(V510.Interfaces.Jmylibrary_PrintManager));TRegTypes.RegisterType('V510.Interfaces.JPrintManager_PrintCallback', TypeInfo(V510.Interfaces.JPrintManager_PrintCallback));TRegTypes.RegisterType('V510.Interfaces.Jmylibrary_api', TypeInfo(V510.Interfaces.Jmylibrary_api));
end;initializationRegisterTypes;
end.
至此,已經(jīng)成功導(dǎo)出了V510打印需要的java類,轉(zhuǎn)換成了Delphi能用的接口類。
2. 創(chuàng)建FMX Delphi項(xiàng)目,將上一步生成的接口文件(V510.Interfaces.pas)引入:
????????項(xiàng)目名稱為:V510_Print
3. 將jarsdk.jar 包加入到 libs中:
選擇V510_Print項(xiàng)目 -> Android 32-bit -> Libraries右鍵菜單?-> Add ,然后選擇 jarsdk.jar文件。
?
成功加入后:
?4. Delphi中調(diào)用:
????????通過觀察V510.Interfaces.pas文件,我們需要使用?Jmylibrary_api java對(duì)象,該對(duì)象實(shí)際封裝了我們需要的打印命令。
? ? ? ? 我們?cè)黾右粋€(gè)新的delphi單元:V510.Android.SZHN.pas,需要引用V510.Interfaces.pas文件,來實(shí)現(xiàn)具體的調(diào)用功能。
在V510.Android.SZHN.pas單元中,我們定義如下過程:
- 使用?PrnStr 命令打印
//打印命令
procedure V510_Print(str : string);
varFContext : JContext;FPrinter : Jmylibrary_api; //打印機(jī)接口對(duì)象
beginFContext := TJContextWrapper.Wrap(System.JavaContext); //創(chuàng)建一個(gè)context對(duì)象if FContext <> nil then Exit; //如果為空則直接退出FPrinter := TJmylibrary_api.JavaClass.getInstance(FContext,TJHandler.JavaClass.init);if FPrinter <> nil then Exit; //如果為空則直接退出tryFPrinter.PrinInt; //初始化打印機(jī)FPrinter.prnSetGray(500); //設(shè)置打印機(jī)灰度FPrinter.PrnStr(StringToJString(str)); //打印字符串FPrinter.prnStart; //完成打印except on E: Exception doSend_Debug_Info('錯(cuò)誤: ' + E.Message);end;
end;
- 使用 sdkPrintText 命令打印
sdkPrintText命令定義如下:
sdkPrintText(String content,int size,boolean isBold, boolean isUnderLine,int align,PrintManager.PrintCallback callback ) 用于打印文本. content 打印內(nèi)容 size 字體大小 8,16,24,32 isBold 粗體 isUnderLine 下劃線 fontAlignment 0 居左,1 居中,2 居右 callback 結(jié)果回調(diào)
注意最后一個(gè)參數(shù)是 callback 回調(diào)函數(shù),這里就需要注意,這是打印機(jī)打印完成和開始的回調(diào)函數(shù),這就需要delphi能夠提供相應(yīng)的回調(diào)函數(shù),以便sdkPrintText命令能夠成功執(zhí)行:
定義回調(diào)函數(shù):
typeTPrintCallback = class(TJavaLocal, JPrintManager_PrintCallback)publicprocedure onPrintError(printErrorType: JPrintErrorType); cdecl;procedure onPrintFinish; cdecl;procedure onPrintStart; cdecl;end;
實(shí)際調(diào)用:
varPrintCallback: JPrintManager_PrintCallback; //定義回調(diào)函數(shù)全局變量.....procedure V510_CallBack;
varFContext : JContext;FPrinter : Jmylibrary_api; //打印機(jī)接口對(duì)象beginFContext := TJContextWrapper.Wrap(System.JavaContext); //創(chuàng)建一個(gè)context對(duì)象if FContext <> nil then Exit;FPrinter := TJmylibrary_api.JavaClass.getInstance(FContext,TJHandler.JavaClass.init);if FPrinter <> nil then Exit;tryFPrinter.PrinInt;FPrinter.prnSetGray(500);FPrinter.sdkPrintText(StringToJString('***** ABC123 ** 科學(xué)'),8,False,false,0, printCallback) ; //直接使用回調(diào)函數(shù)except on E: Exception doSend_Debug_Info('錯(cuò)誤: ' + E.Message);end;end;.....{ TPrintCallback }procedure TPrintCallback.onPrintError(printErrorType: JPrintErrorType);
begin//Send_Debug_Info('出現(xiàn)錯(cuò)誤: ' + printErrorType.getValue.ToString);
end;procedure TPrintCallback.onPrintFinish;
begin// Send_Debug_Info('打印完成!');
end;procedure TPrintCallback.onPrintStart;
begin// Send_Debug_Info('打印開始 !');
end;initializationprintCallback := TPrintCallback.Create; //初始化時(shí)創(chuàng)建回調(diào)函數(shù)
?
四、完整源代碼下載
金泰誼V510手持機(jī)(android)Delphi 調(diào)用打印Demo源程序
五、總結(jié):
- 目前Delphi (11.3)只支持jar包的導(dǎo)入,還沒有支持.aar包導(dǎo)入;
- 導(dǎo)入全部會(huì)出現(xiàn)一些錯(cuò)誤,但是都不是大問題,很容易修改,但是這個(gè)需要自己修改;
- 本文介紹的是打印功能,對(duì)于其他功能是一樣的,只要理解了導(dǎo)入java對(duì)象和類就好;
- 網(wǎng)上也有說其他的導(dǎo)出工具,但是官方的應(yīng)該還是最好的;
- 推薦只導(dǎo)出需要的具體的包,不要全部導(dǎo)出;