jvcllaz: Add JvDBSearchEdit (incl demo)
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6247 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
7386207e69
commit
a123ccb4f7
@ -5,7 +5,7 @@ unit JvDBReg;
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils;
|
||||
SysUtils, PropEdits, DBPropEdits;
|
||||
|
||||
procedure Register;
|
||||
|
||||
@ -14,14 +14,38 @@ implementation
|
||||
{$R ../../resource/jvdbreg.res}
|
||||
|
||||
uses
|
||||
Classes, JvDsgnConsts, JvDBHTLabel;
|
||||
Classes, JvDsgnConsts, JvDBSearchEdit, JvDBHTLabel; //, JvDBTreeView;
|
||||
|
||||
procedure Register;
|
||||
const
|
||||
// cDataField = 'DataField';
|
||||
// cKeyField = 'KeyField';
|
||||
// cListField = 'ListField';
|
||||
// cDisplayField = 'DisplayField';
|
||||
// cListKeyField = 'ListKeyField';
|
||||
cMasterField = 'MasterField';
|
||||
cDetailField = 'DetailField';
|
||||
cIconField = 'IconField';
|
||||
cItemField = 'ItemField';
|
||||
// cLookupField = 'LookupField';
|
||||
// cSectionField = 'SectionField';
|
||||
// cValueField = 'ValueField';
|
||||
// cEditControls = 'EditControls';
|
||||
// cSortedField = 'SortedField';
|
||||
// cSortMarker = 'SortMarker';
|
||||
|
||||
begin
|
||||
RegisterComponents(RsPaletteJvclDB, [
|
||||
RegisterComponents(RsPaletteJvclDB, [ // was: TsPaletteDBVisual
|
||||
TJvDBSearchEdit,
|
||||
TJvDBHtLabel
|
||||
// TJvDBTreeView
|
||||
]);
|
||||
//RegisterComponents(RsPaletteDBVisual, [TJvDBHTLabel]);
|
||||
(*
|
||||
RegisterPropertyEditor(TypeInfo(string), TJvDBTreeView, cItemField, TFieldProperty); //TJvDataFieldProperty);
|
||||
RegisterPropertyEditor(TypeInfo(string), TJvDBTreeView, cMasterField, TFieldProperty); //TJvDataFieldProperty);
|
||||
RegisterPropertyEditor(TypeInfo(string), TJvDBTreeView, cDetailField, TFieldProperty); //TJvDataFieldProperty);
|
||||
RegisterPropertyEditor(TypeInfo(string), TJvDBTreeView, cIconField, TFieldProperty); //TJvDataFieldProperty);
|
||||
*)
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -1 +1,4 @@
|
||||
tjvdbhtlabel.bmp
|
||||
tjvdbsearchcombobox.bmp
|
||||
tjvdbsearchedit.bmp
|
||||
tjvdbtreeview.bmp
|
||||
|
BIN
components/jvcllaz/design/JvDB/images/tjvdbsearchcombobox.bmp
Normal file
BIN
components/jvcllaz/design/JvDB/images/tjvdbsearchcombobox.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
components/jvcllaz/design/JvDB/images/tjvdbsearchedit.bmp
Normal file
BIN
components/jvcllaz/design/JvDB/images/tjvdbsearchedit.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
components/jvcllaz/design/JvDB/images/tjvdbtreeview.bmp
Normal file
BIN
components/jvcllaz/design/JvDB/images/tjvdbtreeview.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="JvSearchEditDemo"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
</General>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<DestinationDirectory Value=""/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
<Modes Count="1">
|
||||
<Mode0 Name="default"/>
|
||||
</Modes>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="3">
|
||||
<Item1>
|
||||
<PackageName Value="JvDBLazR"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="FCL"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item3>
|
||||
</RequiredPackages>
|
||||
<Units Count="2">
|
||||
<Unit0>
|
||||
<Filename Value="JvSearchEditDemo.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="main.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="..\..\bin\JvSearchEditDemo"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
</CONFIG>
|
@ -0,0 +1,21 @@
|
||||
program JvSearchEditDemo;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, main
|
||||
{ you can add units after this };
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
RequireDerivedFormResource := True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
|
112
components/jvcllaz/examples/JvDBSearchEdit/main.lfm
Normal file
112
components/jvcllaz/examples/JvDBSearchEdit/main.lfm
Normal file
@ -0,0 +1,112 @@
|
||||
object Form1: TForm1
|
||||
Left = 680
|
||||
Height = 340
|
||||
Top = 320
|
||||
Width = 408
|
||||
Caption = 'DBSearchEdit demo'
|
||||
ClientHeight = 340
|
||||
ClientWidth = 408
|
||||
OnCreate = FormCreate
|
||||
LCLVersion = '1.9.0.0'
|
||||
object Panel1: TPanel
|
||||
Left = 0
|
||||
Height = 39
|
||||
Top = 0
|
||||
Width = 408
|
||||
Align = alTop
|
||||
AutoSize = True
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 39
|
||||
ClientWidth = 408
|
||||
TabOrder = 0
|
||||
object JvDBSearchEdit1: TJvDBSearchEdit
|
||||
AnchorSideLeft.Control = Label1
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Panel1
|
||||
AnchorSideRight.Control = CheckBox1
|
||||
Left = 76
|
||||
Height = 23
|
||||
Top = 8
|
||||
Width = 184
|
||||
DataSource = DataSource1
|
||||
DataResult = 'OK'
|
||||
DataField = 'Name'
|
||||
ClearOnEnter = False
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 7
|
||||
BorderSpacing.Top = 8
|
||||
BorderSpacing.Right = 16
|
||||
BorderSpacing.Bottom = 8
|
||||
TabOrder = 0
|
||||
Text = 'JvDBSearchEdit1'
|
||||
end
|
||||
object Label1: TLabel
|
||||
AnchorSideLeft.Control = Panel1
|
||||
AnchorSideTop.Control = JvDBSearchEdit1
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 16
|
||||
Height = 15
|
||||
Top = 12
|
||||
Width = 53
|
||||
BorderSpacing.Left = 16
|
||||
Caption = 'Search for'
|
||||
ParentColor = False
|
||||
end
|
||||
object CheckBox1: TCheckBox
|
||||
AnchorSideTop.Control = JvDBSearchEdit1
|
||||
AnchorSideTop.Side = asrCenter
|
||||
AnchorSideRight.Control = Panel1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 276
|
||||
Height = 19
|
||||
Top = 10
|
||||
Width = 116
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Right = 16
|
||||
Caption = 'Clear on get focus'
|
||||
OnChange = CheckBox1Change
|
||||
TabOrder = 1
|
||||
end
|
||||
end
|
||||
object DBGrid1: TDBGrid
|
||||
Left = 0
|
||||
Height = 301
|
||||
Top = 39
|
||||
Width = 408
|
||||
Align = alClient
|
||||
Color = clWindow
|
||||
Columns = <>
|
||||
DataSource = DataSource1
|
||||
Options = [dgTitles, dgIndicator, dgColumnResize, dgColumnMove, dgColLines, dgRowLines, dgTabs, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgDisableInsert]
|
||||
ReadOnly = True
|
||||
TabOrder = 1
|
||||
end
|
||||
object BufDataset1: TBufDataset
|
||||
FieldDefs = <>
|
||||
left = 104
|
||||
top = 96
|
||||
object BufDataset1Name: TStringField
|
||||
FieldKind = fkData
|
||||
FieldName = 'Name'
|
||||
Index = 0
|
||||
LookupCache = False
|
||||
ProviderFlags = [pfInUpdate, pfInWhere]
|
||||
ReadOnly = False
|
||||
Required = False
|
||||
end
|
||||
object BufDataset1Birthdate: TDateField
|
||||
FieldKind = fkData
|
||||
FieldName = 'Birthdate'
|
||||
Index = 1
|
||||
LookupCache = False
|
||||
ProviderFlags = [pfInUpdate, pfInWhere]
|
||||
ReadOnly = False
|
||||
Required = False
|
||||
end
|
||||
end
|
||||
object DataSource1: TDataSource
|
||||
DataSet = BufDataset1
|
||||
left = 104
|
||||
top = 184
|
||||
end
|
||||
end
|
110
components/jvcllaz/examples/JvDBSearchEdit/main.pas
Normal file
110
components/jvcllaz/examples/JvDBSearchEdit/main.pas
Normal file
@ -0,0 +1,110 @@
|
||||
unit main;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, BufDataset, db, FileUtil, Forms, Controls, Graphics,
|
||||
Dialogs, ExtCtrls, StdCtrls, DBGrids, Buttons, JvDBSearchEdit;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
BufDataset1: TBufDataset;
|
||||
BufDataset1Birthdate: TDateField;
|
||||
BufDataset1Name: TStringField;
|
||||
CheckBox1: TCheckBox;
|
||||
DataSource1: TDataSource;
|
||||
DBGrid1: TDBGrid;
|
||||
JvDBSearchEdit1: TJvDBSearchEdit;
|
||||
Label1: TLabel;
|
||||
Panel1: TPanel;
|
||||
procedure CheckBox1Change(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
private
|
||||
|
||||
public
|
||||
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
function RandomBirthDate: TDate;
|
||||
begin
|
||||
Result := Date() - Random(20*365) - 10;
|
||||
end;
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.CheckBox1Change(Sender: TObject);
|
||||
begin
|
||||
JvDBSearchEdit1.ClearOnEnter := Checkbox1.Checked;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
begin
|
||||
with BufDataset1 do
|
||||
begin
|
||||
CreateDataset;
|
||||
|
||||
// Add records
|
||||
Append;
|
||||
BufDataset1Name.AsString := 'Johnny';
|
||||
BufDataset1BirthDate.AsDateTime := RandomBirthdate;
|
||||
Post;
|
||||
|
||||
Append;
|
||||
BufDataset1Name.AsString := 'Tom';
|
||||
BufDataset1BirthDate.AsDateTime := RandomBirthdate;
|
||||
Post;
|
||||
|
||||
Append;
|
||||
BufDataset1Name.AsString := 'Dick';
|
||||
BufDataset1BirthDate.AsDateTime := RandomBirthdate;
|
||||
Post;
|
||||
|
||||
Append;
|
||||
BufDataset1Name.AsString := 'John';
|
||||
BufDataset1BirthDate.AsDateTime := RandomBirthdate;
|
||||
Post;
|
||||
|
||||
Append;
|
||||
BufDataset1Name.AsString := 'Jack';
|
||||
BufDataset1BirthDate.AsDateTime := RandomBirthdate;
|
||||
Post;
|
||||
|
||||
Append;
|
||||
BufDataset1Name.AsString := 'Michael';
|
||||
BufDataset1BirthDate.AsDateTime := RandomBirthdate;
|
||||
Post;
|
||||
|
||||
Append;
|
||||
BufDataset1Name.AsString := 'Robert';
|
||||
BufDataset1BirthDate.AsDateTime := RandomBirthdate;
|
||||
Post;
|
||||
|
||||
Append;
|
||||
BufDataset1Name.AsString := 'Harry';
|
||||
BufDataset1BirthDate.AsDateTime := RandomBirthdate;
|
||||
Post;
|
||||
|
||||
Append;
|
||||
BufDataset1Name.AsString := 'Henry';
|
||||
BufDataset1BirthDate.AsDateTime := RandomBirthdate;
|
||||
Post;
|
||||
|
||||
// Index
|
||||
IndexFieldNames := 'Name';
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -24,16 +24,19 @@
|
||||
<UnitName Value="JvDBReg"/>
|
||||
</Item1>
|
||||
</Files>
|
||||
<RequiredPkgs Count="3">
|
||||
<RequiredPkgs Count="4">
|
||||
<Item1>
|
||||
<PackageName Value="JvCoreLazD"/>
|
||||
<PackageName Value="IDEIntf"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="JvDBLazR"/>
|
||||
<PackageName Value="JvCoreLazD"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<PackageName Value="FCL"/>
|
||||
<PackageName Value="JvDBLazR"/>
|
||||
</Item3>
|
||||
<Item4>
|
||||
<PackageName Value="FCL"/>
|
||||
</Item4>
|
||||
</RequiredPkgs>
|
||||
<UsageOptions>
|
||||
<UnitPath Value="$(PkgOutDir)"/>
|
||||
|
@ -16,11 +16,19 @@
|
||||
- Hypertext components "/>
|
||||
<License Value="The JVCL is released in accordance with the MPL 1.1 license. To get your own copy or read it, go to http://www.mozilla.org/MPL/MPL-1.1.html. "/>
|
||||
<Version Major="1" Release="4"/>
|
||||
<Files Count="1">
|
||||
<Files Count="3">
|
||||
<Item1>
|
||||
<Filename Value="..\run\JvDB\JvDBHTLabel.pas"/>
|
||||
<UnitName Value="JvDBHTLabel"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Filename Value="..\run\JvDB\JvDBTreeView.pas"/>
|
||||
<UnitName Value="JvDBTreeView"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Filename Value="..\run\JvDB\JvDBSearchEdit.pas"/>
|
||||
<UnitName Value="JvDBSearchEdit"/>
|
||||
</Item3>
|
||||
</Files>
|
||||
<RequiredPkgs Count="3">
|
||||
<Item1>
|
||||
|
Binary file not shown.
306
components/jvcllaz/run/JvDB/JvDBSearchEdit.pas
Normal file
306
components/jvcllaz/run/JvDB/JvDBSearchEdit.pas
Normal file
@ -0,0 +1,306 @@
|
||||
{-----------------------------------------------------------------------------
|
||||
The contents of this file are subject to the Mozilla Public License
|
||||
Version 1.1 (the "License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/MPL-1.1.html
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
|
||||
the specific language governing rights and limitations under the License.
|
||||
|
||||
The Original Code is: JvDBSearchEdit.pas, released on 2004-02-28.
|
||||
|
||||
The Initial Developer of the Original Code is Lionel Reynaud
|
||||
Portions created by Sébastien Buysse are Copyright (C) 2004 Lionel Reynaud.
|
||||
All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
|
||||
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
|
||||
located at http://jvcl.delphi-jedi.org
|
||||
|
||||
Known Issues:
|
||||
|
||||
Description:
|
||||
// DB Component to find record with Edit
|
||||
// Free modified and corrected component TDBSearchEdit from Alexander Burlakov
|
||||
-----------------------------------------------------------------------------}
|
||||
// $Id$
|
||||
|
||||
unit JvDBSearchEdit;
|
||||
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
// Windows,
|
||||
// Messages,
|
||||
LCLType, LCLIntf, LMessages,
|
||||
Classes, Controls, StdCtrls, DB, DBCtrls;
|
||||
// JvEdit;
|
||||
|
||||
type
|
||||
TJvDBCustomSearchEdit = class(TCustomEdit) //JvCustomEdit)
|
||||
private
|
||||
FDataLink: TFieldDataLink;
|
||||
FSearchOptions: TLocateOptions;
|
||||
FClearOnEnter: Boolean;
|
||||
FDataResult: string;
|
||||
FRaiseLocateException: Boolean;
|
||||
procedure DataChange(Sender: TObject);
|
||||
function GetDataSource: TDataSource;
|
||||
function GetDataField: string;
|
||||
procedure SetDataSource(Value: TDataSource);
|
||||
procedure SetDataField(const Value: string);
|
||||
procedure SetSearchOptions(const Value: TLocateOptions);
|
||||
procedure CMChanged(var Msg: TLMessage); message CM_CHANGED;
|
||||
protected
|
||||
procedure DoEnter; override;
|
||||
procedure DoExit; override;
|
||||
procedure KeyPress(var Key: Char); override;
|
||||
procedure Notification(Component: TComponent; Operation: TOperation); override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
function GetResult: Variant;
|
||||
property SearchOptions: TLocateOptions read FSearchOptions
|
||||
write SetSearchOptions default [loCaseInsensitive, loPartialKey];
|
||||
published
|
||||
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||
property DataResult: string read FDataResult write FDataResult;
|
||||
property DataField: string read GetDataField write SetDataField;
|
||||
property TabStop default True;
|
||||
property ClearOnEnter: Boolean read FClearOnEnter write FClearOnEnter default True;
|
||||
//1 Property to raise/hide any exception inside the Dataset.Locate call
|
||||
property RaiseLocateException: Boolean read FRaiseLocateException write FRaiseLocateException default true;
|
||||
end;
|
||||
|
||||
{$IFDEF RTL230_UP}
|
||||
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
|
||||
{$ENDIF RTL230_UP}
|
||||
TJvDBSearchEdit = class(TJvDBCustomSearchEdit)
|
||||
published
|
||||
property SearchOptions default [loCaseInsensitive, loPartialKey];
|
||||
property Align;
|
||||
property Alignment;
|
||||
property Anchors;
|
||||
property AutoSelect;
|
||||
property AutoSize;
|
||||
// property BevelEdges;
|
||||
// property BevelInner;
|
||||
// property BevelKind default bkNone;
|
||||
// property BevelOuter;
|
||||
property BiDiMode;
|
||||
property BorderSpacing;
|
||||
property BorderStyle;
|
||||
property CharCase;
|
||||
property Color;
|
||||
property Constraints;
|
||||
property Cursor;
|
||||
// property Flat;
|
||||
property DragCursor;
|
||||
property DragKind;
|
||||
// property ImeMode;
|
||||
// property ImeName;
|
||||
// property OEMConvert;
|
||||
// property ParentFlat;
|
||||
property DragMode;
|
||||
property Enabled;
|
||||
property Font;
|
||||
property Height;
|
||||
property HelpContext;
|
||||
property HelpKeyword;
|
||||
property HelpType;
|
||||
property HideSelection;
|
||||
property Hint;
|
||||
property MaxLength;
|
||||
property NumbersOnly;
|
||||
property ParentBiDiMode;
|
||||
property ParentColor;
|
||||
property ParentFont;
|
||||
property ParentShowHint;
|
||||
property PopupMenu;
|
||||
property ReadOnly;
|
||||
property ShowHint;
|
||||
property TabOrder;
|
||||
property TabStop;
|
||||
property Text;
|
||||
property TextHint;
|
||||
property Top;
|
||||
property Visible;
|
||||
property Width;
|
||||
property OnChange;
|
||||
property OnChangeBounds;
|
||||
property OnClick;
|
||||
property OnContextPopup;
|
||||
property OnDblClick;
|
||||
property OnDragDrop;
|
||||
property OnDragOver;
|
||||
property OnEditingDone;
|
||||
property OnEndDrag;
|
||||
property OnEnter;
|
||||
property OnExit;
|
||||
property OnKeyDown;
|
||||
property OnKeyPress;
|
||||
property OnKeyUp;
|
||||
property OnMouseDown;
|
||||
property OnMouseEnter;
|
||||
property OnMouseLeave;
|
||||
property OnMouseMove;
|
||||
property OnMouseUp;
|
||||
property OnMouseWheel;
|
||||
property OnMouseWheelDown;
|
||||
property OnMouseWheelUp;
|
||||
property OnResize;
|
||||
property OnStartDrag;
|
||||
property OnUTF8KeyPress;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
Variants, Forms,
|
||||
JvConsts;
|
||||
|
||||
//=== { TJvDBCustomSearchEdit } ==============================================
|
||||
|
||||
constructor TJvDBCustomSearchEdit.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FDataLink := TFieldDataLink.Create;
|
||||
FDataLink.Control := Self;
|
||||
FDataLink.OnDataChange := @DataChange;
|
||||
FSearchOptions := [loCaseInsensitive, loPartialKey];
|
||||
FClearOnEnter := True;
|
||||
Text := '';
|
||||
FRaiseLocateException := True;
|
||||
end;
|
||||
|
||||
destructor TJvDBCustomSearchEdit.Destroy;
|
||||
begin
|
||||
FDataLink.Free;
|
||||
FDataLink := nil;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TJvDBCustomSearchEdit.Notification(Component: TComponent; Operation: TOperation);
|
||||
begin
|
||||
inherited Notification(Component, Operation);
|
||||
if (FDataLink <> nil) and (Component = DataSource) and (Operation = opRemove) then
|
||||
DataSource := nil;
|
||||
end;
|
||||
|
||||
procedure TJvDBCustomSearchEdit.DataChange(Sender: TObject);
|
||||
begin
|
||||
if FDataLink.Field <> nil then
|
||||
begin
|
||||
if Screen.ActiveControl <> Self then
|
||||
begin
|
||||
if FDataLink.CanModify then
|
||||
Text := FDataLink.Field.Text
|
||||
else
|
||||
Text := FDataLink.Field.DisplayText;
|
||||
SelectAll;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
if csDesigning in ComponentState then
|
||||
Text := Name
|
||||
else
|
||||
Text := '';
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJvDBCustomSearchEdit.CMChanged(var Msg: TLMessage);
|
||||
var
|
||||
LText: string;
|
||||
begin
|
||||
if (not ((csDesigning in ComponentState) and
|
||||
(csLoading in ComponentState))) and
|
||||
Assigned(FDataLink.DataSet) then
|
||||
if (Screen.ActiveControl = Self) and FDataLink.Active then
|
||||
try
|
||||
if FDataLink.DataSet.Locate(FDataLink.FieldName, Text, FSearchOptions) then
|
||||
begin
|
||||
LText := Text;
|
||||
Text := FDataLink.DataSet.FieldByName(DataField).AsString;
|
||||
SelStart := Length(LText);
|
||||
SelLength := Length(Text) - SelStart;
|
||||
end;
|
||||
except
|
||||
if RaiseLocateException then
|
||||
raise;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJvDBCustomSearchEdit.KeyPress(var Key: Char);
|
||||
var
|
||||
LLength: Integer;
|
||||
begin
|
||||
if Key = Backspace then
|
||||
begin
|
||||
LLength := SelLength;
|
||||
SelStart := SelStart - 1;
|
||||
SelLength := LLength + 1;
|
||||
end;
|
||||
inherited KeyPress(Key);
|
||||
end;
|
||||
|
||||
function TJvDBCustomSearchEdit.GetDataSource: TDataSource;
|
||||
begin
|
||||
Result := FDataLink.DataSource;
|
||||
end;
|
||||
|
||||
procedure TJvDBCustomSearchEdit.SetDataSource(Value: TDataSource);
|
||||
begin
|
||||
FDataLink.DataSource := Value;
|
||||
end;
|
||||
|
||||
function TJvDBCustomSearchEdit.GetDataField: string;
|
||||
begin
|
||||
Result := FDataLink.FieldName;
|
||||
end;
|
||||
|
||||
procedure TJvDBCustomSearchEdit.SetDataField(const Value: string);
|
||||
begin
|
||||
FDataLink.FieldName := Value;
|
||||
end;
|
||||
|
||||
procedure TJvDBCustomSearchEdit.SetSearchOptions(const Value: TLocateOptions);
|
||||
begin
|
||||
FSearchOptions := Value;
|
||||
end;
|
||||
|
||||
function TJvDBCustomSearchEdit.GetResult: Variant;
|
||||
begin
|
||||
Result := Null;
|
||||
if Assigned(FDataLink.DataSet) and FDataLink.DataSet.Active and (DataResult <> '') then
|
||||
Result := FDataLink.DataSet.Lookup(DataField, Text, DataResult);
|
||||
end;
|
||||
|
||||
procedure TJvDBCustomSearchEdit.DoEnter;
|
||||
begin
|
||||
if FClearOnEnter then
|
||||
Text := '';
|
||||
inherited DoEnter;
|
||||
end;
|
||||
|
||||
procedure TJvDBCustomSearchEdit.DoExit;
|
||||
begin
|
||||
inherited DoExit;
|
||||
// On replace le texte sur l'enregistrement en cours
|
||||
if Assigned(FDataLink.DataSet) and FDataLink.DataSet.Active then
|
||||
Text := FDataLink.DataSet.FieldByName(DataField).AsString;
|
||||
end;
|
||||
|
||||
{$IFDEF UNITVERSIONING}
|
||||
initialization
|
||||
RegisterUnitVersion(HInstance, UnitVersioning);
|
||||
|
||||
finalization
|
||||
UnregisterUnitVersion(HInstance);
|
||||
{$ENDIF UNITVERSIONING}
|
||||
|
||||
end.
|
@ -35,6 +35,9 @@ uses
|
||||
JvComponent;
|
||||
|
||||
type
|
||||
|
||||
{ TYearGridEditForm }
|
||||
|
||||
TYearGridEditForm = class(TForm) //JvForm)
|
||||
Panel1: TPanel;
|
||||
BtnOK: TBitBtn;
|
||||
|
Loading…
Reference in New Issue
Block a user