【发布时间】:2014-02-28 17:49:44
【问题描述】:
以下错误发生在我在下面指出的行。而且我无法弄清楚为什么会出现此错误。
Project ChirpSR.exe raised exception class $C0000005 with message 'access violation at 0x00e8d088: read of address 0x00000000'.
以下代码来自自动生成的 DataSnap 服务器代理类。
interface
uses Data.DBXCommon, Data.DBXClient, Data.DBXDataSnap, Data.DBXJSON, Datasnap.DSProxy, System.Classes, System.SysUtils, Data.DB, Data.SqlExpr, Data.DBXDBReaders, Data.DBXCDSReaders, Data.DBXJSONReflect;
....
type
TServerMethods1Client = class(TDSAdminClient)
private
FEchoStringCommand: TDBXCommand;
FReverseStringCommand: TDBXCommand;
FGetValleysCommand: TDBXCommand;
FUpdateUserCommand: TDBXCommand;
public
constructor Create(ADBXConnection: TDBXConnection); overload;
constructor Create(ADBXConnection: TDBXConnection; AInstanceOwner: Boolean); overload;
destructor Destroy; override;
function EchoString(Value: string): string;
function ReverseString(Value: string): string;
function GetValleys: TJSONValue;
function UpdateUser(jsonobj: TJSONObject): Integer;
end;
....
// This function runs fine
function TServerMethods1Client.GetValleys: TJSONValue;
begin
if FGetValleysCommand = nil then
begin
FGetValleysCommand := FDBXConnection.CreateCommand;
FGetValleysCommand.CommandType := TDBXCommandTypes.DSServerMethod;
FGetValleysCommand.Text := 'TServerMethods1.GetValleys';
FGetValleysCommand.Prepare;
end;
FGetValleysCommand.ExecuteUpdate;
Result := TJSONValue(FGetValleysCommand.Parameters[0].Value.GetJSONValue(FInstanceOwner));
end;
// This function errors at the highlighted line
function TServerMethods1Client.UpdateUser(jsonobj: TJSONObject): Integer;
begin
if FUpdateUserCommand = nil then
begin
FUpdateUserCommand := FDBXConnection.CreateCommand; <============= Error Here
FUpdateUserCommand.CommandType := TDBXCommandTypes.DSServerMethod;
FUpdateUserCommand.Text := 'TServerMethods1.UpdateUser';
FUpdateUserCommand.Prepare;
end;
FUpdateUserCommand.Parameters[0].Value.SetJSONValue(jsonobj, FInstanceOwner);
FUpdateUserCommand.ExecuteUpdate;
Result := FUpdateUserCommand.Parameters[1].Value.GetInt32;
end;
....
服务器正在运行,否则第一个函数会出错。
我被难住了。
我也是 DataSnap 的新手。
【问题讨论】:
-
错误信息提示你有什么
FDBXConnection = nil。 -
@FreeConsulting 但是 FDBXConnection 是作为创建代理的一部分创建的?哦,我明白了我错过了什么。连接应该在创建时作为参数传递。他们允许在没有参数的情况下创建代理似乎很奇怪?我应该在全局范围内创建一次代理,还是在每次调用时在本地创建一次?将此评论作为答案,我会接受。
标签: delphi delphi-xe5 datasnap