第一个 macOS 64位 kbmmw 服务器

 

 

 

前几天,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;

运行客户端

正确运行。

基本上比较顺利。

相关文章
相关标签/搜索