没有大富来解答这个问题吗?谁看过李维的书,快来看看啊!
附代码:
procedure TForm2.FormActivate(Sender: TObject);
begin
DCOM1.Connected := True;
ClientDataSet1.Active := True;
bFunc := True;
edtRecNo.Text := IntToStr(ClientDataSet1.RecordCount);
end;
procedure TForm2.FormDeactivate(Sender: TObject);
begin
ClientDataSet1.Active := False;
DCOM1.Connected := False;
end;
procedure TForm2.btnLocateClick(Sender: TObject);
begin
bFunc := True;
end;
procedure TForm2.btnImprovedClick(Sender: TObject);
begin
bFunc := False;
end;
procedure TForm2.btnQueryClick(Sender: TObject);
var
lStart, lEnd : Integer;
lCurr, lOffset : Integer;
procedure CheckData;
var
iCount : Integer;
begin
cdsTemp.Data := ClientDataSet1.Data;
while not (ClientDataSet2.Eof)do
begin
if (cdsTemp.Locate('NAME', ClientDataSet2.FieldByName('NAME').Value, []) ) then
ClientDataSet2.Delete
else
ClientDataSet2.Next;
end;
ClientDataSet2.MergeChangeLog;
end;
begin
lStart := GetTickCount;
if (bFunc) then
begin
ClientDataSet1.Locate('NAME', edtSearchField.Text, [loPartialKey, loCaseInsensitive]);
// ClientDataSet1.Open;
edtRecNo.Text := IntToStr(ClientDataSet1.RecordCount);
end
else
begin
ClientDataSet2.Close;
ClientDataSet2.CommandText := 'select * from animals where NAME like ''' + edtSearchField.Text + '%''';
ClientDataSet2.Open;
lCurr := ClientDataSet1.RecNo;
lOffset := ClientDataSet1.RecordCount - lCurr + 1;
CheckData;
ClientDataSet1.AppendData(ClientDataSet2.Data, False);
ClientDataSet1.MoveBy(lOffset);
end;
lEnd := GetTickCount;
edtRecNo.Text := IntToStr(ClientDataSet1.RecordCount);
edtTime.Text := FloatToStr((lEnd - lStart) / 1000.0) + '?';
end;
procedure TForm2.btnGeneralClick(Sender: TObject);
var
lStart, lEnd : Integer;
begin
lStart := GetTickCount;
ClientDataSet3.Close;
if (edtSearchField.Text = '*') then
begin
ClientDataSet1.Active := False;
ClientDataSet1.Active := True;
end
else
begin
ClientDataSet3.CommandText := 'select * from animals where NAME like ' + '''' + edtSearchField.Text + '%''';
ClientDataSet3.Open;
if (ClientDataSet3.RecordCount > 0) then
ClientDataSet1.Data := ClientDataSet3.Data;
end;
lEnd := GetTickCount;
edtRecNo.Text := IntToStr(ClientDataSet1.RecordCount);
edtTime.Text := FloatToStr((lEnd - lStart) / 1000.0) + '?';
end;
end.