W
WilliamGui
Unregistered / Unconfirmed
GUEST, unregistred user!
函数如何:
function TfrmBasGenFrm.DataSetFieldIsRepeat(DataSet: TDataSet;
ARepeatField: TField): boolean;
var
iRecNo:integer;
RepeatFieldValue: string;
begin
Result:=true;
if (DataSet=nil) or (not DataSet.Active)
or (ARepeatField=nil) or DataSet.IsEmpty
then
begin
Result:=false;
exit;
end;
iRecNo:=DataSet.RecNo;
RepeatFieldValue:=ARepeatField.AsString;
if DataSet is TClientDataSet then
begin
with TClientDataSet.Create(self)do
begin
CloneCursor(TClientDataSet(DataSet), False, True);
First;
while not Eofdo
begin
if iRecNo<>RecNo then
begin
//有问题
if FieldByName(ARepeatField.FieldName).AsString=RepeatFieldValue
then
begin
SetDBControlFocus(DataSet, ARepeatField);
//设置焦点
WarningMsgBox(ARepeatField.DisplayLabel+' 不能重复!');
Exit;
end;
end;
//RecNo
Next;
end;
Free;
end;
//with
end else
if DataSet is TADODataSet then
begin
end;
Result:=False;
end;
function TfrmBasGenFrm.DataSetFieldIsRepeat(DataSet: TDataSet;
ARepeatField: TField): boolean;
var
iRecNo:integer;
RepeatFieldValue: string;
begin
Result:=true;
if (DataSet=nil) or (not DataSet.Active)
or (ARepeatField=nil) or DataSet.IsEmpty
then
begin
Result:=false;
exit;
end;
iRecNo:=DataSet.RecNo;
RepeatFieldValue:=ARepeatField.AsString;
if DataSet is TClientDataSet then
begin
with TClientDataSet.Create(self)do
begin
CloneCursor(TClientDataSet(DataSet), False, True);
First;
while not Eofdo
begin
if iRecNo<>RecNo then
begin
//有问题
if FieldByName(ARepeatField.FieldName).AsString=RepeatFieldValue
then
begin
SetDBControlFocus(DataSet, ARepeatField);
//设置焦点
WarningMsgBox(ARepeatField.DisplayLabel+' 不能重复!');
Exit;
end;
end;
//RecNo
Next;
end;
Free;
end;
//with
end else
if DataSet is TADODataSet then
begin
end;
Result:=False;
end;