前幾天,Delphi 10.3.2 正式發佈,這個小版本升級卻增長了一個很是大的平臺支持,增長了macos
macos 64位的支持,今天作一個macOS 64位的kbmmw應用,讓kbmmw 服務器的應用更普遍。服務器
固然了,你須要先根據要求,設置好相關的·macos64 的開發環境。this
首先咱們新建一個FMX 應用。spa
設置對應的參數3d
procedure TForm2.Button1Click(Sender: TObject); begin kbmmwserver1.AutoRegisterServices; kbmmwserver1.Active:=true; end;
平臺上添加mac os64 code
新建一個kbmmw 服務。orm
服務名設爲mactest,生成一個服務,並修改代碼以下:server
type [kbmMW_Service('name:mactest, flags:[listed]')] [kbmMW_Rest('path:/mactest')] // Access to the service can be limited using the [kbmMW_Auth..] attribute. // [kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')] TkbmMWCustomHTTPSmartService1 = class(TkbmMWCustomHTTPSmartService) private { Private declarations } protected { Protected declarations } public { Public declarations } // HelloWorld function callable from both a regular client, // due to the optional [kbmMW_Method] attribute, // and from a REST client due to the optional [kbmMW_Rest] attribute. // The access path to the function from a REST client (like a browser)+ // is in this case relative to the services path. // In this example: http://.../mactest/helloworld // Access to the function can be limited using the [kbmMW_Auth..] attribute. // [kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')] [kbmMW_Rest('method:get, path:helloworld')] [kbmMW_Method] function HelloWorld:string; [kbmMW_Method] function version:string; [kbmMW_Method] function EchoString(const AString:string):string; [kbmMW_Method] function AddNumbers(const AValue1,AValue2:integer; [kbmMW_Arg(mwatRemoteLocation)] const ARemoteLocation:string ):integer ; end; implementation {%CLASSGROUP 'System.Classes.TPersistent'} uses kbmMWExceptions, mainp; {$R *.dfm} // Service definitions. //--------------------- function TkbmMWCustomHTTPSmartService1.AddNumbers(const AValue1, AValue2: integer; const ARemoteLocation: string): integer; begin Result:=AValue1+AValue2; end; function TkbmMWCustomHTTPSmartService1.EchoString( const AString: string): string; begin Result:=AString; end; function TkbmMWCustomHTTPSmartService1.HelloWorld:string; begin Result:='Hello world'; end; function TkbmMWCustomHTTPSmartService1.version: string; begin result:='kbmmw server for macos 64'; end; initialization TkbmMWRTTI.EnableRTTI(TkbmMWCustomHTTPSmartService1); end.
服務端作好了blog
咱們能夠運行了。開發
如今作一個簡單客戶端
設置對應的代碼
procedure TForm1.Button1Click(Sender: TObject); var c:IkbmMWSmartClient; s:string; begin Transport.Host:=eIP.Text; // Get a client which establishes connection over the given transport // to the given service which is set to be default for this client. c:=TkbmMWSmartRemoteClientFactory.GetClient(Transport,'MACTEST'); s:=c.Service. helloworld ; memo1.Lines.Add(s); s:=c.Service.EchoString('abc'); memo1.Lines.Add(s); s:=c.Service.version; memo1.Lines.Add(s); s:=c.Service.AddNumbers(34,7); memo1.Lines.Add(s); end;
運行客戶端
正確運行。
基本上比較順利。