刚学datasnap,环境是xe7和win8,用了unidac的插件连接oracle数据库和查询数据,按照创建datasnap的服务端的方法创建一个最基础的服务器端,在TServerMethods1里增加了一个QueryAll方法,代码如下:
unit MServerMethodsUnit;
interface
uses System.SysUtils, System.Classes, System.Json,
Datasnap.DSServer, Datasnap.DSAuth, DataSnap.DSProviderDataModuleAdapter,
Datasnap.Provider, Data.DB, MemDS, DBAccess, Uni, UniProvider,
OracleUniProvider;
type
TServerMethods1 = class(TDSServerModule)
MOracleUniProvider: TOracleUniProvider;
MUniConnection: TUniConnection;
MUniQuery: TUniQuery;
MDataSetProvider: TDataSetProvider;
private
{ Private declarations }
public
{ Public declarations }
function EchoString(Value: string): string;
function ReverseString(Value: string): string;
function QueryAll: string;
end;
implementation
{$R *.dfm}
uses System.StrUtils,JsonTools;
function TServerMethods1.EchoString(Value: string): string;
begin
Result := Value;
end;
function TServerMethods1.ReverseString(Value: string): string;
begin
Result := System.StrUtils.ReverseString(Value);
end;
function TServerMethods1.QueryAll: string;
begin
MUniQuery.Active:=true;
Result := TJsonTools.DataSetToJson(MUniQuery).ToString;
//Result:=MUniQuery.Fields.FieldByName('aac001').AsString;
end;
end.
其中用到的JsonTools.pas代码如下,DataSetToJson这个方法没有任何处理:
unit JsonTools;
interface
uses
System.Json,Uni,DB;
type
TJsonTools = class(TObject)
private
public
class function DataSetToJson(Prm_DataSet:TUniQuery):TJsonObject;
end;
implementation
class function TJsonTools.DataSetToJson(Prm_DataSet:TUniQuery):TJsonObject;
var
i:word;
begin
end;
end.
unit MServerMethodsUnit;
interface
uses System.SysUtils, System.Classes, System.Json,
Datasnap.DSServer, Datasnap.DSAuth, DataSnap.DSProviderDataModuleAdapter,
Datasnap.Provider, Data.DB, MemDS, DBAccess, Uni, UniProvider,
OracleUniProvider;
type
TServerMethods1 = class(TDSServerModule)
MOracleUniProvider: TOracleUniProvider;
MUniConnection: TUniConnection;
MUniQuery: TUniQuery;
MDataSetProvider: TDataSetProvider;
private
{ Private declarations }
public
{ Public declarations }
function EchoString(Value: string): string;
function ReverseString(Value: string): string;
function QueryAll: string;
end;
implementation
{$R *.dfm}
uses System.StrUtils,JsonTools;
function TServerMethods1.EchoString(Value: string): string;
begin
Result := Value;
end;
function TServerMethods1.ReverseString(Value: string): string;
begin
Result := System.StrUtils.ReverseString(Value);
end;
function TServerMethods1.QueryAll: string;
begin
MUniQuery.Active:=true;
Result := TJsonTools.DataSetToJson(MUniQuery).ToString;
//Result:=MUniQuery.Fields.FieldByName('aac001').AsString;
end;
end.
其中用到的JsonTools.pas代码如下,DataSetToJson这个方法没有任何处理:
unit JsonTools;
interface
uses
System.Json,Uni,DB;
type
TJsonTools = class(TObject)
private
public
class function DataSetToJson(Prm_DataSet:TUniQuery):TJsonObject;
end;
implementation
class function TJsonTools.DataSetToJson(Prm_DataSet:TUniQuery):TJsonObject;
var
i:word;
begin
end;
end.
服务器运行后,在浏览器中输入http://localhost:8080/datasnap/rest/TServerMethods1/QueryAll/,总是提示"{"error":"Access violation at address 006EBB6B in module 'DTDSServer.exe'. Read of address 8DC30048"}",但如果运行的是红色字体的那一行就没问题,请问是啥原因?
回复于: 2015-06-28 19:35:33
|
#2 得分:0
回复于: 2015-06-28 21:39:04
|