You've already forked lazarus-ccr
aarre
applications
bindings
components
ZVDateTimeCtrls
aboutcomponent
acs
beepfp
chelper
cmdline
cmdlinecfg
colorpalette
csvdocument
epiktimer
fpsound
fpspreadsheet
fractions
freetypepascal
geckoport
gradcontrols
iosdesigner
iphonelazext
jujiboutils
jvcllaz
kcontrols
lazbarcodes
lclextensions
longtimer
manualdock
mplayer
multithreadprocs
nvidia-widgets
onguard
orpheus
playsoundpackage
poweredby
powerpdf
rgbgraphics
richmemo
richview
rtfview
rx
trunk
version
2.1
Demos
docs
images
languages
lib
RxMDICloseIcon.lrs
WinXP.manifest
WindowsXP.RES
WindowsXP.rc
autopanel.pas
boxprocs.pas
curredit.pas
dateutil.pas
dbcurredit.pas
dbdateedit.pas
dbutils.pas
dcl_rx_ctrl.lpk
dcl_rx_ctrl.pas
duallist.pas
ex_rx_bin_datapacket.pas
ex_rx_datapacket.pas
ex_rx_xml_datapacket.pas
exsortfb.pas
exsortmds.pas
exsortsql.pas
exsortzeos.pas
fduallst.lfm
fduallst.lrs
fduallst.lrt
fduallst.pas
folderlister.pas
pagemngr.pas
pickdate.lrs
pickdate.pas
register_rxctrl.pas
registerrx.pas
registerrxdb.pas
registerrxtools.pas
rx.inc
rx.lrs
rx_sort_fbdataset.lpk
rx_sort_fbdataset.pas
rx_sort_sqldb.lpk
rx_sort_sqldb.pas
rx_sort_zeos.lpk
rx_sort_zeos.pas
rxaboutdialog.pas
rxaboutformunit.lfm
rxaboutformunit.pas
rxappicon.pas
rxapputils.pas
rxceeditlookupfields.pas
rxclock.pas
rxcloseformvalidator.pas
rxconfigvalues.pas
rxconst.pas
rxctrls.pas
rxcustomchartpanel.pas
rxdbcolorbox.pas
rxdbcomb.pas
rxdbctrls.pas
rxdbgrid.lrs
rxdbgrid.pas
rxdbgrid_columsunit.lfm
rxdbgrid_columsunit.lrt
rxdbgrid_columsunit.pas
rxdbgrid_findunit.lfm
rxdbgrid_findunit.pas
rxdbspinedit.pas
rxdbtimeedit.pas
rxdconst.pas
rxdice.inc
rxdice.pas
rxfileutils.pas
rxfilterby.lfm
rxfilterby.lrt
rxfilterby.pas
rxhistory.pas
rxhistorynavigator.pas
rxiconv.pas
rxinipropstorage.pas
rxlogin.lfm
rxlogin.lrs
rxlogin.pas
rxlookup.pas
rxmdi.pas
rxmemds.pas
rxnew.lpk
rxnew.pas
rxpopupunit.pas
rxsortby.lfm
rxsortby.lrt
rxsortby.pas
rxsortfbdataset.pas
rxsortmemds.pas
rxsortsqldb.pas
rxsortzeos.pas
rxspin.lrs
rxspin.pas
rxstrutils.pas
rxswitch.inc
rxswitch.pas
rxsystemservices.pas
rxtbrsetup.lfm
rxtbrsetup.lrt
rxtbrsetup.pas
rxtimeedit.pas
rxtoolbar.pas
rxversinfo.pas
rxviewspanel.pas
rxxpman.pas
seldsfrm.lfm
seldsfrm.lrs
seldsfrm.lrt
seldsfrm.pas
tooledit.pas
tooledit.res
vclutils.pas
v2.6_laz_1.2
scrolltext
smnetgradient
spktoolbar
svn
tdi
thtmlport
tparadoxdataset
tvplanit
virtualtreeview
virtualtreeview-new
xdev_toolkit
zlibar
examples
lclbindings
wst
251 lines
6.7 KiB
ObjectPascal
251 lines
6.7 KiB
ObjectPascal
![]() |
{ dbcurredit unit
|
||
|
|
||
|
Copyright (C) 2005-2010 Lagunov Aleksey alexs@hotbox.ru and Lazarus team
|
||
|
original conception from rx library for Delphi (c)
|
||
|
|
||
|
This library is free software; you can redistribute it and/or modify it
|
||
|
under the terms of the GNU Library General Public License as published by
|
||
|
the Free Software Foundation; either version 2 of the License, or (at your
|
||
|
option) any later version with the following modification:
|
||
|
|
||
|
As a special exception, the copyright holders of this library give you
|
||
|
permission to link this library with independent modules to produce an
|
||
|
executable, regardless of the license terms of these independent modules,and
|
||
|
to copy and distribute the resulting executable under terms of your choice,
|
||
|
provided that you also meet, for each linked independent module, the terms
|
||
|
and conditions of the license of that module. An independent module is a
|
||
|
module which is not derived from or based on this library. If you modify
|
||
|
this library, you may extend this exception to your version of the library,
|
||
|
but you are not obligated to do so. If you do not wish to do so, delete this
|
||
|
exception statement from your version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
|
||
|
for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; if not, write to the Free Software Foundation,
|
||
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||
|
|
||
|
First version By Daniel Simões de Almeida
|
||
|
}
|
||
|
|
||
|
unit dbcurredit ;
|
||
|
|
||
|
{$I rx.inc}
|
||
|
|
||
|
interface
|
||
|
|
||
|
uses
|
||
|
Classes, SysUtils, LResources, LMessages, LCLType, Controls, Graphics,
|
||
|
DB, DbCtrls, curredit ;
|
||
|
|
||
|
type
|
||
|
|
||
|
{ TRxDBCurrEdit }
|
||
|
|
||
|
TRxDBCurrEdit = class(TCurrencyEdit)
|
||
|
private
|
||
|
FDataLink: TFieldDataLink;
|
||
|
procedure DoCheckEnable;
|
||
|
function GetDataField: string;
|
||
|
function GetDataSource: TDataSource;
|
||
|
function GetReadOnly: Boolean;
|
||
|
procedure SetDataField(const AValue: string);
|
||
|
procedure SetDataSource(const AValue: TDataSource);
|
||
|
procedure SetReadOnly(const AValue: Boolean);
|
||
|
protected
|
||
|
procedure ActiveChange(Sender:TObject);
|
||
|
procedure DataChange(Sender:TObject);
|
||
|
procedure EditingChange(Sender: TObject);
|
||
|
procedure UpdateData(Sender:TObject);
|
||
|
procedure CMExit(var Message:TLMessage); message CM_EXIT;
|
||
|
procedure LMCut(var Message: TLMessage); message LM_CUT;
|
||
|
procedure LMPaste(var Message: TLMessage); message LM_PASTE;
|
||
|
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||
|
procedure Change; override;
|
||
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||
|
procedure EditingDone; override;
|
||
|
public
|
||
|
constructor Create(AOwner: TComponent); override;
|
||
|
destructor Destroy; override;
|
||
|
published
|
||
|
property DataField: string read GetDataField write SetDataField;
|
||
|
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||
|
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
|
||
|
end;
|
||
|
|
||
|
implementation
|
||
|
|
||
|
Uses math ;
|
||
|
|
||
|
{ TRxDBCurrEdit }
|
||
|
|
||
|
procedure TRxDBCurrEdit.DoCheckEnable;
|
||
|
begin
|
||
|
Enabled:=FDataLink.Active and (FDataLink.Field<>nil) and (not FDataLink.Field.ReadOnly);
|
||
|
end;
|
||
|
|
||
|
function TRxDBCurrEdit.GetDataField: string;
|
||
|
begin
|
||
|
Result:=FDataLink.FieldName;
|
||
|
end;
|
||
|
|
||
|
function TRxDBCurrEdit.GetDataSource: TDataSource;
|
||
|
begin
|
||
|
Result:=FDataLink.DataSource;
|
||
|
end;
|
||
|
|
||
|
function TRxDBCurrEdit.GetReadOnly: Boolean;
|
||
|
begin
|
||
|
Result:=FDataLink.ReadOnly;
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.SetDataField(const AValue: string);
|
||
|
begin
|
||
|
try
|
||
|
FDataLink.FieldName:=AValue;
|
||
|
finally
|
||
|
DoCheckEnable;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.SetDataSource(const AValue: TDataSource);
|
||
|
begin
|
||
|
FDataLink.DataSource:=AValue;
|
||
|
DoCheckEnable;
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.SetReadOnly(const AValue: Boolean);
|
||
|
begin
|
||
|
FDataLink.ReadOnly:=AValue;
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.ActiveChange(Sender: TObject);
|
||
|
begin
|
||
|
DoCheckEnable;
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.DataChange(Sender: TObject);
|
||
|
begin
|
||
|
if Assigned(FDataLink.Field) and
|
||
|
(FDataLink.Field is TNumericField) then
|
||
|
begin
|
||
|
if FDataLink.Field.IsNull then
|
||
|
Text:=''
|
||
|
else
|
||
|
Self.Value := SimpleRoundTo( FDataLink.Field.AsFloat, -DecimalPlaces) ;
|
||
|
end
|
||
|
else Text:='';
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.EditingChange(Sender: TObject);
|
||
|
begin
|
||
|
inherited ReadOnly := not FDataLink.Editing;
|
||
|
{ if FDataLink.Editing and DefaultToday and (FDataLink.Field <> nil) and
|
||
|
(FDataLink.Field.AsDateTime = NullDate) then
|
||
|
FDataLink.Field.AsDateTime := SysUtils.Now;}
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.UpdateData(Sender: TObject);
|
||
|
begin
|
||
|
if Assigned(FDataLink.Field) then
|
||
|
begin
|
||
|
if Self.Text<>'' then
|
||
|
FDataLink.Field.AsFloat := SimpleRoundTo( Self.Value, -Self.DecimalPlaces)
|
||
|
else
|
||
|
FDataLink.Field.Clear;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.CMExit(var Message: TLMessage);
|
||
|
begin
|
||
|
try
|
||
|
FDataLink.UpdateRecord;
|
||
|
except
|
||
|
SetFocus;
|
||
|
SelectAll;
|
||
|
raise;
|
||
|
end;
|
||
|
inherited;
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.LMCut(var Message: TLMessage);
|
||
|
begin
|
||
|
FDataLink.Edit;
|
||
|
inherited;
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.LMPaste(var Message: TLMessage);
|
||
|
begin
|
||
|
FDataLink.Edit;
|
||
|
inherited;
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.KeyDown(var Key: Word; Shift: TShiftState);
|
||
|
begin
|
||
|
inherited KeyDown(Key, Shift);
|
||
|
if Key=VK_ESCAPE then
|
||
|
begin
|
||
|
//cancel out of editing by reset on esc
|
||
|
FDataLink.Reset;
|
||
|
SelectAll;
|
||
|
Key := VK_UNKNOWN;
|
||
|
end
|
||
|
else
|
||
|
if (Key<>VK_UNKNOWN) then
|
||
|
begin
|
||
|
//make sure we call edit to ensure the datset is in edit,
|
||
|
//this is for where the datasource is in autoedit, so we aren't
|
||
|
//read only even though the dataset isn't realy in edit
|
||
|
FDataLink.Edit;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.Change;
|
||
|
begin
|
||
|
FDataLink.Modified;
|
||
|
inherited Change;
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.Notification(AComponent: TComponent;
|
||
|
Operation: TOperation);
|
||
|
begin
|
||
|
inherited Notification(AComponent, Operation);
|
||
|
// if the datasource is being removed then we need to make sure
|
||
|
// we are updated or we can get AV/Seg's *cough* as I foolishly
|
||
|
// discovered firsthand....
|
||
|
if (Operation=opRemove) then
|
||
|
begin
|
||
|
if (FDataLink<>nil) and (AComponent=DataSource) then
|
||
|
DataSource:=nil;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
procedure TRxDBCurrEdit.EditingDone;
|
||
|
begin
|
||
|
inherited EditingDone;
|
||
|
if FDataLink.CanModify then
|
||
|
FDataLink.UpdateRecord;
|
||
|
end;
|
||
|
|
||
|
constructor TRxDBCurrEdit.Create(AOwner: TComponent);
|
||
|
begin
|
||
|
inherited Create(AOwner);
|
||
|
FDataLink:=TFieldDataLink.Create;
|
||
|
FDataLink.Control:=Self;
|
||
|
FDataLink.OnActiveChange:=@ActiveChange;
|
||
|
FDataLink.OnDataChange:=@DataChange;
|
||
|
FDataLink.OnUpdateData:=@UpdateData;
|
||
|
end;
|
||
|
|
||
|
destructor TRxDBCurrEdit.Destroy;
|
||
|
begin
|
||
|
FreeAndNil(FDataLink);
|
||
|
inherited Destroy;
|
||
|
end;
|
||
|
|
||
|
end.
|
||
|
|