JvclLaz: Add OnSearchRecord event to TJvDBSearchEdit.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9354 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
c335a9e65a
commit
0e9a6e81b3
@ -38,6 +38,9 @@ uses
|
|||||||
Classes, Controls, StdCtrls, DB, DBCtrls;
|
Classes, Controls, StdCtrls, DB, DBCtrls;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
TJvSearchRecordEvent = procedure (ADataset: TDataset; KeyField, KeyValue: string;
|
||||||
|
Options: TLocateOptions; var Found: Boolean) of object;
|
||||||
|
|
||||||
TJvDBCustomSearchEdit = class(TCustomEdit) //JvCustomEdit)
|
TJvDBCustomSearchEdit = class(TCustomEdit) //JvCustomEdit)
|
||||||
private
|
private
|
||||||
FDataLink: TFieldDataLink;
|
FDataLink: TFieldDataLink;
|
||||||
@ -45,6 +48,7 @@ type
|
|||||||
FClearOnEnter: Boolean;
|
FClearOnEnter: Boolean;
|
||||||
FDataResult: string;
|
FDataResult: string;
|
||||||
FRaiseLocateException: Boolean;
|
FRaiseLocateException: Boolean;
|
||||||
|
FOnSearchRecord: TJvSearchRecordEvent;
|
||||||
procedure DataChange(Sender: TObject);
|
procedure DataChange(Sender: TObject);
|
||||||
function GetDataSource: TDataSource;
|
function GetDataSource: TDataSource;
|
||||||
function GetDataField: string;
|
function GetDataField: string;
|
||||||
@ -55,6 +59,7 @@ type
|
|||||||
protected
|
protected
|
||||||
procedure DoEnter; override;
|
procedure DoEnter; override;
|
||||||
procedure DoExit; override;
|
procedure DoExit; override;
|
||||||
|
function DoSearchRecord(KeyField, KeyValue: String; Options: TLocateOptions): Boolean;
|
||||||
procedure KeyPress(var Key: Char); override;
|
procedure KeyPress(var Key: Char); override;
|
||||||
procedure Notification(Component: TComponent; Operation: TOperation); override;
|
procedure Notification(Component: TComponent; Operation: TOperation); override;
|
||||||
public
|
public
|
||||||
@ -71,6 +76,7 @@ type
|
|||||||
property ClearOnEnter: Boolean read FClearOnEnter write FClearOnEnter default True;
|
property ClearOnEnter: Boolean read FClearOnEnter write FClearOnEnter default True;
|
||||||
//1 Property to raise/hide any exception inside the Dataset.Locate call
|
//1 Property to raise/hide any exception inside the Dataset.Locate call
|
||||||
property RaiseLocateException: Boolean read FRaiseLocateException write FRaiseLocateException default true;
|
property RaiseLocateException: Boolean read FRaiseLocateException write FRaiseLocateException default true;
|
||||||
|
property OnSearchRecord: TJvSearchRecordEvent read FOnSearchRecord write FOnSearchRecord;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$IFDEF RTL230_UP}
|
{$IFDEF RTL230_UP}
|
||||||
@ -213,16 +219,17 @@ end;
|
|||||||
|
|
||||||
procedure TJvDBCustomSearchEdit.CMChanged(var Msg: TLMessage);
|
procedure TJvDBCustomSearchEdit.CMChanged(var Msg: TLMessage);
|
||||||
var
|
var
|
||||||
LText: string;
|
lText: string;
|
||||||
begin
|
begin
|
||||||
if (not ((csDesigning in ComponentState) and
|
if (not ((csDesigning in ComponentState) and
|
||||||
(csLoading in ComponentState))) and
|
(csLoading in ComponentState))) and
|
||||||
Assigned(FDataLink.DataSet) then
|
Assigned(FDataLink.DataSet) then
|
||||||
if (Screen.ActiveControl = Self) and FDataLink.Active then
|
if (Screen.ActiveControl = Self) and FDataLink.Active then
|
||||||
try
|
try
|
||||||
if FDataLink.DataSet.Locate(FDataLink.FieldName, Text, FSearchOptions) then
|
lText := Text;
|
||||||
|
if DoSearchRecord(FDataLink.FieldName, lText, FSearchOptions) then
|
||||||
begin
|
begin
|
||||||
LText := Text;
|
lText := Text;
|
||||||
Text := FDataLink.DataSet.FieldByName(DataField).AsString;
|
Text := FDataLink.DataSet.FieldByName(DataField).AsString;
|
||||||
SelStart := Length(LText);
|
SelStart := Length(LText);
|
||||||
SelLength := Length(Text) - SelStart;
|
SelLength := Length(Text) - SelStart;
|
||||||
@ -293,6 +300,28 @@ begin
|
|||||||
Text := FDataLink.DataSet.FieldByName(DataField).AsString;
|
Text := FDataLink.DataSet.FieldByName(DataField).AsString;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TJvDBCustomSearchEdit.DoSearchRecord(KeyField, KeyValue: String;
|
||||||
|
Options: TLocateOptions): Boolean;
|
||||||
|
var
|
||||||
|
bm: TBookmark;
|
||||||
|
begin
|
||||||
|
if Assigned(FOnSearchRecord) then
|
||||||
|
begin
|
||||||
|
bm := FDatalink.Dataset.GetBookmark;
|
||||||
|
FDataLink.Dataset.DisableControls;
|
||||||
|
try
|
||||||
|
FOnSearchRecord(FDataLink.Dataset, KeyField, KeyValue, Options, Result);
|
||||||
|
if not Result then
|
||||||
|
FDataLink.Dataset.GotoBookmark(bm);
|
||||||
|
finally
|
||||||
|
FDatalink.Dataset.EnableControls;
|
||||||
|
FDatalink.Dataset.FreeBookmark(bm);
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := FDataLink.Dataset.Locate(Keyfield, KeyValue, Options);
|
||||||
|
end;
|
||||||
|
|
||||||
{$IFDEF UNITVERSIONING}
|
{$IFDEF UNITVERSIONING}
|
||||||
initialization
|
initialization
|
||||||
RegisterUnitVersion(HInstance, UnitVersioning);
|
RegisterUnitVersion(HInstance, UnitVersioning);
|
||||||
|
Loading…
Reference in New Issue
Block a user