unit UDBGridUtils;
interface
{Unit dxDBGrid auskommentieren, falls Quantum Express nicht verwendet wird}
uses DB, Controls, SysUtils, Dialogs, dbctrls, DBGrids, dxDBGrid;
function SearchField(feld: TField):Boolean;
function SearchDBControl(DBcontrol: Tcontrol):Boolean;
implementation
function SearchField(feld: TField):Boolean;
var
s:
string;
ds : TDataSet;
options : TLocateOptions;
begin
Result := False;
if Assigned(feld)
then
begin
ds := feld.DataSet;
if InputQuery(PssGetString(ID_FrmLnw_SearchField) + '
' + feld.DisplayName, '
', s)
then
begin
// Wenn das letzte Zeichen ein * ist,
// dann wird nur mit einem Teilschlüssel gesucht
if (Length(s) >= 2)
and (s[Length(s)]='
*')
then
begin
SetLength(s, Length(s)-1);
// letztes Zeichen (das *) löschen
options := [loPartialKey];
end
else
options := [];
Result := ds.Locate(feld.FieldName, s, options);
end;
end;
end;
function SearchDBControl(DBcontrol: Tcontrol):Boolean;
begin
if DBcontrol
is TDBEdit
then
Result := SearchField(TDBEdit(DBcontrol).Field)
else if DBcontrol
is TDBGrid
then
result := SearchField(TDBGrid(DBcontrol).SelectedField)
else if DBcontrol
is TdxDBGrid
then
result := SearchField(TdxDBGrid(DBcontrol).FocusedField)
else if DBcontrol
is TDBText
then
Result := SearchField(TDBText(DBcontrol).Field)
else if DBcontrol
is TDBComboBox
then
Result := SearchField(TDBComboBox(DBcontrol).Field)
else if Assigned(DBcontrol)
then
raise Exception.Create('
unsupported control: '+DBcontrol.ClassName)
else
Result := False;
end;
end.