同意djdsz,下面是我自已写的一段函数以供参考:
function TFZLRForm.GetXs(sTab, sField, sTj, sRField: string
iCase: integer):
variant;
//sTab:表名
//sField:字段名
//sTj:条件
//sRField:返回值所在的字段名
//iCase:返回字段类型,如果需要的话你可以返回无数不同类型的值
var
fJg : double;
sJg : string;
iJg : integer;
begin
fJg := 0;
iJg := 0;
sJg := '';
with Qcx do
begin
Close;
Sql.Clear;
Sql.Add('SELECT * FROM ' + sTab);
Sql.Add('WHERE ' + sField + '=''' + sTj + '''');
Open;
case iCase of
0: fJg := FieldByName(sRField).AsFloat;
1: sJg := FieldByName(sRField).AsString;
2: iJg := FieldByName(sRField).AsInteger;
end
{Case}
Close;
end;
case iCase of
0: Result := fJg;
1: Result := sJg;
2: Result := iJg;
end
{Case}
end;