下面的错误发生在我下面指出的行中。我不明白为什么会有这个错误。
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的新手。
发布于 2014-02-28 23:41:05
Project ChirpSR.exe引发异常类$C0000005,其消息“访问冲突在0x00e8d088: read 0x00000000”。
错误消息提示您拥有什么FDBXConnection = nil。由于CreateCommand是虚拟方法,调用TDBXConnection(nil).CreateCommand将产生您所呈现的异常。
https://stackoverflow.com/questions/22102294
复制相似问题