关于记录查找locate的用法

jhcsq 2008-08-08 04:47:39
我想只查一个字段,但发现出错,如查两个字段则没问题了,不知啥?代码如下
arry1[0]:=trim(edit1.Text) ;
arry1[1]:=trim(edit2.Text) ;
arry1[2]:=trim(edit3.Text) ;
with DataModule8.ADOTable1zhzl do
begin
if (length(edit1.text)<>0 )then
begin
if (locate('acno;name',vararrayof(arry1),[loPartialKey])) then //如将 ;name去掉查则出错
delete
else
showmessage('该记录不存在');
end
上面的如这样写则错了,错哪? if (locate('acno',vararrayof(arry1),[loPartialKey])) then
...全文
150 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
JeffChung 2008-08-09
  • 打赏
  • 举报
回复

procedure TfrmMain.btnLocateClick(Sender: TObject);
var
sFields : String;
begin
sFields := GetSerchFields;
dmSearchData.sqlcdsTest.Locate(sFields, GetSearchValues,[loCaseInsensitive, loPartialKey]);
end;

function TfrmMain.GetSearchValues : Variant;
var
iCount : Integer;
sCond : String;
begin
Result := VarArrayCreate([0, Self.clbConditions.Items.Count - 1],varVariant);
for iCount := 0 to Self.clbConditions.Items.Count - 1 do
begin
sCond := Self.clbConditions.Items[iCount];
Result[iCount] := GetSearchValue(sCond);
end;
end;

function TfrmMain.GetSearchFields: String;
var
iCount : Integer;
sCond : String;
begin
Result := '';
for iCount := 0 to Self.clbConditions.Items.Count - 1 do
begin
sCond := Self.clbConditions.Items[iCount];
Result := Result + GetSearchField(sCond) + ';';
end;
Delete(Result, Length(Result), 1);
end;
lyguo 2008-08-09
  • 打赏
  • 举报
回复
if (locate('acno',vararrayof(arry1),[loPartialKey])) then

你这个当然有错, 前面 acno 是一个参数,
而后面arry1 它是三个参数啊。

楼上的几种方式都行。
xmfan2000 2008-08-08
  • 打赏
  • 举报
回复
一个不能使用这样的Locate方法,应该使用:
if Locate('acno', Trim(Edit1.Text), [loPartialKey]) then
.....
yangkunjie 2008-08-08
  • 打赏
  • 举报
回复
if Locate('acno',vararrayof(arry1),[loCaseInsensitive, loPartialKey])
whisht 2008-08-08
  • 打赏
  • 举报
回复
if (locate('acno',vararrayof([trim(edit1.Text)]),[loPartialKey])) then

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧