分类: LINUX
2005-11-06 12:19:18
var
??TFm_Main: TTFm_Main;
?
?implementation
?
?{$R *.DFM}
?
?procedure TTFm_Main.dbg_DataTitleClick(Column: TColumn);
?var
??vi_Counter: Integer;
??vs_Field: String;
?begin
??with dbg_Data do
??begin
???//First, deselect all the Grid Columns
???for vi_Counter:=0 to Columns.Count-1 do
????Columns[vi_Counter].Color := clWindow;
?
???//Next Select the column the user has Clicked on
???Column.Color := clTeal;
?
???//Get the FieldName of the Selected Column
???vs_Field := Column.FieldName;
?
???//Order the Grid Data by the Selected column
???with qry_Data do
???begin
????DisableControls;
????Close;
????SQL.Clear;
????SQL.Text := QueryStatement + ' ORDER BY '+ vs_Field;
????Open;
????EnableControls;
???end;
?
???//Get the DataType of the selected Field and change the Edit event
???//onKeyPress to the proper method Pointer
???case Column.Field.DataType of
????ftFloat: Ed_Search.onKeyPress := FloatonKeyPress;
????else
?????Ed_Search.onKeyPress := FALphaNumericKeyPress;
???end;
??end;
?
?end;
?
?procedure TTFm_Main.FloatonKeyPress(Sender: TObject; var Key: Char);
?begin
??if not(Key in ['0'..'9', #13, #8, #10, #46]) then
???Key := #0;
?
?end;
?
?procedure TTFm_Main.FormCreate(Sender: TObject);
?begin
??//Keep a pointer for the default event Handler
??FALphaNumericKeyPress := Ed_Search.onKeyPress;
?
??//Set the original Query SQL Statement
??FQueryStatement := 'SELECT * FROM your_table_name';
?
??//Select the first Grid Column
??dbg_DataTitleClick(dbg_Data.Columns[0]);
?
?end;
?
?procedure TTFm_Main.Ed_SearchChange(Sender: TObject);
?var
??vi_counter: Integer;
??vs_Field: String;
?begin
??try
??with dbg_Data do
??begin
???//First determine wich is the Selected Column
???for vi_Counter:=0 to Columns.Count-1 do
????if Columns[vi_Counter].Color = clTeal then
????begin
?????vs_Field := Columns[vi_Counter].FieldName;
?????Break;
????end;
?
???//Locate the value in the Query
???with qry_Data do
????case Columns[vi_Counter].Field.DataType of
?????ftFloat: Locate(vs_Field, StrToFloat(Ed_Search.Text),
?????????[loCaseInsensitive, loPartialKey]);
?????else
??????Locate(vs_Field, Ed_Search.Text,[loCaseInsensitive,
????????? loPartialKey]);
????end;
??end;
??except
??end;
?end;
?
?end.