I have the code below, but when I try to free the variable checkID, I get an access violation error, and if I don't destroy it I will have a memory leak problem.
function TdtmData.CheckID(AID: String): Boolean;
var
checkID : TJSONObject;
clientModule : TcmClientModule;
ok : Boolean;
begin
Result := False;
try
try
clientModule := TcmClientModule.Create(Self);
checkID := clientModule.smMethodsServerClient.CheckID(AID);
ok := checkID.GetValue<Boolean>('Register', False);
if not(ok) then
raise Exception.Create('ID ERROR.');
finally
clientModule.DisposeOf;
checkID.Free; // <-- The error is here (Access violation)
end;
Result := ok;
except
on e : Exception do
raise Exception.Create(e.Message);
end;
end;
The smMethodsServerClient.CheckID(AID) method was created automatically through the TDSRestConnection component.
function TsmMethodsServerClient.CheckID(AID: string; const ARequestFilter: string): TJSONObject;
begin
if FCheckIDCommand = nil then
begin
FCheckIDCommand := FConnection.CreateCommand;
FCheckIDCommand.RequestType := 'GET';
FCheckIDCommand.Text := 'TsmMethodsServer.CheckID';
FCheckIDCommand.Prepare(TsmMethodsServer_CheckID);
end;
FCheckIDCommand.Parameters[0].Value.SetWideString(AIDPDV);
FCheckIDCommand.Execute(ARequestFilter);
Result := TJSONObject(FCheckIDCommand.Parameters[1].Value.GetJSONValue(FInstanceOwner));
end;
I also used the Datasnap REST Client Module wizard to create my class TcmClientModule.