DELPHI10.2开发的跨平台中间件
Posted 咏南中间件和开发框架
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DELPHI10.2开发的跨平台中间件相关的知识,希望对你有一定的参考价值。
咏南LINUX中间件
什么是跨平台?
DELPHI跨平台已经不是停留在理论,而是可以实用了。
同一套中间件既能在WINDOWS服务器上面部署,又可以在LINUX服务器上面部署。
而做到这一切,只需要一套源代码,这完全得益于DELPHI 10.2全新的跨平台编译器。
想想,你的同一个中间件同时可以在WINDOWS和LINUX服务器上部署运行,这是一件多么激动人心的事情啊!
笔者不免心情澎湃!同时支持TCP/IP、HTTP通信协议。
LINUX 支持:
- Ubuntu Server (Ubuntu 16.04 LTS)
- RedHat Enterprise Linux (版本 7)
CENTOS 7 服务器上运行中间件:
中间件详情日志:
WINDOWS客户端访问CENTOS7上的中间件并返回查询数据:
同一份源代码只需要编译成不同的目标平台即可:
WINDOWS服务器上部署运行中间件:
支持REST调用
测试客户端代码:
// cxg 2017-9-16 跨平台中间件的客户端
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Data.SqlExpr,
Data.DBXDataSnap, Data.DBXCommon, IPPeerClient, Unit2, Vcl.Grids, Vcl.DBGrids,
Vcl.StdCtrls, FireDAC.Stan.Def, FireDAC.Stan.StorageJSON, FireDAC.Stan.StorageBin,
FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error,
FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Comp.DataSet,
FireDAC.Comp.Client, Vcl.ExtCtrls, Data.DbxHTTPLayer;
type
TForm1 = class(TForm)
SQLConnection1: TSQLConnection;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
FDMemTable1: TFDMemTable;
btnsave: TButton;
btnappend: TButton;
btndel: TButton;
btnquery: TButton;
btnsp: TButton;
procedure FormCreate(Sender: TObject);
procedure btnsaveClick(Sender: TObject);
procedure btnappendClick(Sender: TObject);
procedure btndelClick(Sender: TObject);
procedure btnqueryClick(Sender: TObject);
procedure btnspClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
ujson;
procedure TForm1.btnsaveClick(Sender: TObject);
// 保存数据
var
c: TServerMethods1Client;
sResult: string;
begin
if FDMemTable1.State in [dsInsert, dsEdit] then
FDMemTable1.Post;
if FDMemTable1.ChangeCount = 0 then
Exit;
SQLConnection1.Close;
SQLConnection1.Open;
c := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
try
sResult := c.ExecuteSQL(ujson.deltaToJSON(FDMemTable1, \'t1\', \'c1\', \'\'));
if Pos(\'true\', sResult) > 0 then
begin
FDMemTable1.MergeChangeLog;
ShowMessage(\'save ok\');
end
else
begin
FDMemTable1.Cancel;
ShowMessage(\'save fail\');
end;
finally
c.Free;
SQLConnection1.Close;
end;
end;
procedure TForm1.btnspClick(Sender: TObject);
// 执行存储过程
//CREATE PROCEDURE sp2(in a varchar(5))
//BEGIN
//SELECT * FROM t1 where c1=a;
//END;
var
c: TServerMethods1Client;
begin
SQLConnection1.Close;
SQLConnection1.Open;
c := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
try
ujson.jsonToDB(c.SPOpen(\'sp2\', \'{"a":"1"}\'), FDMemTable1);
finally
c.Free;
SQLConnection1.Close;
end;
end;
procedure TForm1.btnqueryClick(Sender: TObject);
// 查询数据
var
c: TServerMethods1Client;
begin
SQLConnection1.Close;
SQLConnection1.Open;
c := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
try
ujson.jsonToDB(c.QuerySQL(\'select * from t1\'), FDMemTable1);
FDMemTable1.MergeChangeLog;
finally
c.Free;
SQLConnection1.Close;
end;
end;
procedure TForm1.btnappendClick(Sender: TObject);
// 新增
begin
FDMemTable1.Append;
end;
procedure TForm1.btndelClick(Sender: TObject);
// 删除数据
var
c: TServerMethods1Client;
sResult: string;
begin
if not FDMemTable1.IsEmpty then
begin
FDMemTable1.Delete; // del
SQLConnection1.Close;
SQLConnection1.Open;
c := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
try
sResult := c.ExecuteSQL(ujson.deltaToJSON(FDMemTable1, \'t1\', \'c1\', \'\'));
if Pos(\'true\', sResult) > 0 then
begin
FDMemTable1.MergeChangeLog;
ShowMessage(\'del ok\');
end
else
begin
FDMemTable1.Cancel;
ShowMessage(\'del fail\');
end;
finally
c.Free;
SQLConnection1.Close;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FDMemTable1.CachedUpdates := True; // 否则不能保存
end;
end.
以上是关于DELPHI10.2开发的跨平台中间件的主要内容,如果未能解决你的问题,请参考以下文章
使用delphi 10.2 开发linux 上的Daemon