//Bu programı çalıştırmak için forma 1 adet Table, 1 adet DataSource, 1 adet DbGrid ve
//1 adet Stringgrid Yerleştirin. Ben DataBaseName olarak DBDEMOS ve TableName olarak customer.db değerlerini verdim. Siz bunu Değiştirebilirsiniz.
}
unit filtreunit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, DbGrids, Db, DBTables;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
Table1: TTable;
DbGrid1: TDbGrid;
StringGrid1: TStringGrid;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Table1FilterRecord(DataSet: TDataSet; var Accept: Boolean);
procedure StringGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormShow(Sender: TObject);
var i : integer;
begin
DataSource1.Dataset := Table1;
Table1.DatabaseName := 'DBDEMOS';
Table1.TableName := 'customer.db';
Table1.Filtered := True;
Table1.Open;
StringGrid1.Width := DbGrid1.Width;
StringGrid1.Colcount := DbGrid1.Fieldcount;
StringGrid1.RowCount := 2;
StringGrid1.Options := StringGrid1.Options + [goediting];
DbGrid1.Options := DbGrid1.Options - [dgindicator];
StringGrid1.DefaultRowHeight := 18;
StringGrid1.FixedCols := 0;
for i := 0 to DbGrid1.FieldCount-1 do
begin
StringGrid1.Colwidths[i] := DbGrid1.Columns[i].width;
StringGrid1.cells[i,0] := DbGrid1.Columns[i].title.caption;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Table1.Close;
end;
Function bh (s : string) : string;
var
kucuk,buyuk : string;
i,j : integer;
begin
kucuk := 'abcçdefgğhıijklmnoöpqrsştuüvwxyz';
buyuk := 'ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZ';
for i := 1 to length(s) do
begin
for j:=1 to length(kucuk) do
begin
if (kucuk[j]=s[i]) then s[i]:=buyuk[j];
end;
end;
result := s;
end;
procedure TForm1.Table1FilterRecord(DataSet: TDataSet;var Accept: Boolean);
var i : integer;
alan : array[0..100] of string;
begin
for i := 0 to StringGrid1.Colcount-1 do
alan[i] := StringGrid1.Cells[i,1];
for i := 0 to DbGrid1.Columns.Count - 1 do
begin
accept :=(accept) and (((((alan[i]='') or (alan[i]='*')) or ((alan[i]<>'') and (alan[i]<>'*') and (alan[i][1]='*') and (pos(bh(copy(alan[i],2,length(alan[i])-1)),bh(Table1.FieldbyName(DbGrid1.Columns[i].Fieldname).asstring)) > 0 )))
or ((alan[i]='') or ((alan[i]<>'') {and (alan[i][1]<>'*')} and (bh(alan[i])=copy(bh(Table1.FieldbyName(DbGrid1.Columns[i].Fieldname).asstring),1,length(alan[i])))))));
end;
end;
procedure TForm1.StringGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Table1.First;
end;
end.