以下错误发生在我指出的行中。我无法弄清楚为什么会出现这个错误。
Project ChirpSR.exe raised exception class $C0000005 with message 'access violation at 0x00e8d088: read of address 0x00000000'.
以下代码来自DataSnap Server的自动生成代理类。
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的新手。
答案 0 :(得分:0)
Project ChirpSR.exe使用消息引发异常类$ C0000005 '访问冲突0x00e8d088:读取地址0x00000000'。
错误消息表明您拥有FDBXConnection = nil
。由于CreateCommand
是虚方法,因此调用TDBXConnection(nil).CreateCommand
将产生您呈现的异常。