服务端:
function TServerMethods1.spExecOut(funcId, sqlId,
inParams: OleVariant): OleVariant;
var
d: TfrmDB;
procName: string;
params: TFDParams;
i, h: Integer;
begin
Result := null;
d := DBPool.Lock;
if not Assigned(d) then
Exit;
try
try
procName := frmBuffer.GetSqlSelect(funcId, sqlId);
if procName = '' then
Exit;
d.proc.Close;
d.proc.StoredProcName := procName;
d.proc.Prepare;
params := TFDParams.Create;
try
UnpackFDParams(inParams, params);
for i:=0 to params.Count -1 do
for h:=0 to d.proc.ParamCount-1 do
if d.proc.Params[h].Name = params[i].Name then
begin
if d.proc.Params[h].ParamType=ptInput then
begin
d.proc.Params[h].Value := params[i].Value;
Break;
end;
end;
finally
params.Free;
end;
d.proc.ExecProc;
Result := PackageFDParams(d.proc.Params);
except
on e: Exception do
begin
Result := null;
Log.WriteLog('TServerMethods1.spExecOut ' + e.Message);
Exit;
end;
end;
finally
DBPool.Unlock(d);
end;
end;
客户端调用:
procedure TfrmMain.Button2Click(Sender: TObject);
var
r:OleVariant;
p:TParams;
begin
p:=TParams.Create(nil);
p.Clear;
p.CreateParam(ftInteger,'@a',ptInput).Value :=1;
p.CreateParam(ftInteger,'@b',ptInput).Value :=2;
p.CreateParam(ftInteger,'@c',ptOutput);
r := spExecOut('9999','3',PackageParams(p));
UnpackParams(r,p);
p.ParamByName('@c').Value;
p.Free;
end;
end.