Delphi 下利用UniStoredProc空间执行MySQL存储过程问题
Delphi 下利用UniStoredProc空间执行MySQL存储过程问题
参数可以赋值
执行可以成功
但是如果参数中 是返回类型参数 返回回来的参数值 delphi这边捕获不到
不知道什么原因 还请指教
函数 代码如下:
function ExecUniStoredProc(UniStoredProc: TUniStoredProc; ProcName: string;
AParamName: array of string;
var AParamValue: array of Variant;
AParamType: array of TFieldType; OpenFlag: Boolean): Boolean;
var
i: Integer;
begin
Result := True;
with UniStoredProc do
begin
Close;
Params.Clear;
StoredProcName := ProcName;
// UnPrepare;//这里要注释掉,不然执行会出错
// Prepare;//执行一下后面的参数等信息才可以显示出来
for i := Low(AParamName) to High(AParamName) do
begin
if Params.FindParam(AParamName[i]) = nil then Continue;
try
case AParamType[i] of
ftString, ftInteger, ftFloat, ftDateTime, ftDate:
begin//VarIsEmpty:判断是否为Unassigned VarIsNull:判断是否为Null
//如果Variant是Unassigned,则将其赋值为null
if VarIsEmpty(AParamValue[i]) then
AParamValue[i] := null
else
Params.ParamByName(AParamName[i]).Value := AParamValue[i];
end;
ftBoolean:
begin
//如果Variant是Unassigned;并且数据类型是Boolean类型,则将其赋值为false(因为对于Variant类型,若将其赋值为False,则Variant类型为Unassigned)
if VarIsEmpty(AParamValue[i]) then
Params.ParamByName(AParamName[i]).Value := False
else
Params.ParamByName(AParamName[i]).Value := AParamValue[i];
end;
ftBlob:
begin
//若添加的是图片类型或文件类型的处理 参数值为图片文件所在的本地路径
if FileExists(AParamValue[i]) then
Params.ParamByName(AParamName[i]).LoadFromFile(AParamValue[i], ftBlob)
else
Params.ParamByName(AParamName[i]).Value := null;
end;
end;
except
Application.MessageBox(PChar('错误过程:'+ProcName+'参数:'+AParamName[i]), '错误', MB_OK + MB_ICONINFORMATION);
Exit;
end;
end;
try
if OpenFlag then Open
else ExecProc;
except
Result := False;
Application.MessageBox(PChar('错误过程:'+ProcName), '错误', MB_OK + MB_ICONINFORMATION);
Exit;
end;
//获取返回值(这里包括存储过程自身返回值,和存储过程定义的Output返回值)
for i := Low(AParamName) to High(AParamName) do
begin
if (Params.ParamByName(AParamName[i]).ParamType = ptOutput)
or (Params.ParamByName(AParamName[i]).ParamType = ptInputOutput) then
AParamValue[i] := Params.ParamByName(AParamName[i]).Value;
end;
end;
end;
执行代码:
AFieldName[0] := 'vTeacherCode'; AFieldValue[0] := Trim(txtedtTeacherCode.Text); AFieldType[0] := ftString;
AFieldName[1] := 'vPasswords'; AFieldValue[1] := Trim(txtedtPasswords.Text); AFieldType[1] := ftString;
AFieldName[2] := 'iTeacherID'; AFieldValue[2] := null; AFieldType[2] := ftInteger;
AFieldName[3] := 'vTeacherName'; AFieldValue[3] := null; AFieldType[3] := ftString;
AFieldName[4] := 'vReturnValue'; AFieldValue[4] := null; AFieldType[4] := ftString;
AFieldName[5] := 'iResult'; AFieldValue[5] := null; AFieldType[5] := ftString;
ExecUniStoredProc(UniStoredProc, 'P_LoginTeacher', AFieldName, AFieldValue, AFieldType, True);
showmessage(AFieldValue[4]);
这里show出来 总是空置
代码跟踪 发现 返回值并没东西赋值进去
不知道为什么 还请指教 谢谢。。。。