开发者

Remove All non numeric row in dbgrid

i want remove all non numeric row in dbgrid

for example my dbgrid row's is:

row1= 127.0.0.1:900
row2= 103.43.122.40:8000
row3= 122.12.75.4:3128
row4= netfire.se98.ar:3000
row5= po-ryd.449.br:3128
row6= 93.5.32.150开发者_如何转开发:6540

Now, remove all non numeric row in dbgrid.


A DbGrid is backed by a TDataSet descendant. That TDataSet descendant has a Filtered property and an OnFilterRecord that can be used to filter records.

Here's a sample OnFilterRecord implementation that rejects any record that's made up of characters that are not numbers, not '.' or ':'. Please note I'm not using an char-in-set test so the code is perfectly compatible with both Unicode Delphi and non-Unicode Delphi.

procedure TForm1.ClientDataSet1FilterRecord(DataSet: TDataSet; var Accept: Boolean);
var Value: string;
    i: Integer;
    C: Char;
begin
  Value := DataSet['IP']; // Replace "IP" with your field's name
  for i:=1 to Length(Value) do
  begin
    C := Value[i];
    if not(C in ['.', ':', '0'..'9']) then // Detect bad characters
    begin
      Accept := False; // This record will NOT be shown.
      Exit;
    end;
  end;
  Accept := True; // No bad characters were found, show the record.
end;

After you assign this OnFilterRecord handler, don't forget to set Filtered := True.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜