5,387
社区成员
发帖
与我相关
我的任务
分享
//判断输入的值是否有效,有效返回KEY值,无KEY时返回第1列,无效显示提示并返回''.
function LocateEh(ADataSet: TDataSet; AListFields,AValue: string;
AKeyField: string = '';AHint: Boolean = True): string;
var
i:integer;
bFind:boolean;
lStr: TStrings;
cFields: string;
begin
Result := Char(255);
cFields := AListFields + ';';
if Pos(AKeyField + ';',cFields) > 0 then
lStr := StringToList(cFields,';')
else
lStr := StringToList(AKeyField + ';' + cFields,';');
bFind := False;
for i := 0 to lStr.Count - 1 do
try
if (lStr[i] <> '') and ADataSet.Locate(lStr[i],AValue,[loCaseInsensitive,loPartialKey]) then
begin
bFind := True;
if AKeyField = '' then
Result := ADataSet.FieldbyName(lStr[0]).Text
else
Result := ADataSet.FieldByName(AKeyField).Text;
Break;
end;
except
end;
lStr.Free;
if (not bFind) and AHint then
Application.MessageBox('无效的编码、名称或助记符或您没有使用该编码的权限!', '提示',64);
end;