Стартовый пул
This commit is contained in:
204
RXLib/rxdb/ex_rx_bin_datapacket.pas
Normal file
204
RXLib/rxdb/ex_rx_bin_datapacket.pas
Normal file
@@ -0,0 +1,204 @@
|
||||
{ ex_rx_bin_datapacket unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs@yandex.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.
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
TBinaryRxDatapacketReader implementation
|
||||
|
||||
See the file COPYING.FPC, included in this distribution,
|
||||
for details about the copyright.
|
||||
|
||||
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.
|
||||
|
||||
**********************************************************************}
|
||||
|
||||
unit ex_rx_bin_datapacket;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, dom, db, ex_rx_datapacket;
|
||||
|
||||
type
|
||||
TChangeLogEntry = record
|
||||
UpdateKind : TUpdateKind;
|
||||
OrigEntry : integer;
|
||||
NewEntry : integer;
|
||||
end;
|
||||
TChangeLogEntryArr = array of TChangeLogEntry;
|
||||
|
||||
type
|
||||
{ TBinaryRxDatapacketReader }
|
||||
|
||||
TBinaryRxDatapacketReader = class(TRxDataPacketReader)
|
||||
public
|
||||
procedure LoadFieldDefs(AFieldDefs : TFieldDefs); override;
|
||||
procedure StoreFieldDefs(AFieldDefs : TFieldDefs); override;
|
||||
function GetRecordRowState(out AUpdOrder : Integer) : TRowState; override;
|
||||
procedure FinalizeStoreRecords; override;
|
||||
function GetCurrentRecord : boolean; override;
|
||||
procedure GotoNextRecord; override;
|
||||
procedure InitLoadRecords; override;
|
||||
procedure RestoreRecord(ADataset : TDataset); override;
|
||||
procedure StoreRecord(ADataset : TDataset; ARowState : TRowState; AUpdOrder : integer = 0); override;
|
||||
class function RecognizeStream(AStream : TStream) : boolean; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
dbconst;
|
||||
|
||||
{ TBinaryRxDatapacketReader }
|
||||
|
||||
const
|
||||
RxBinaryIdent = 'BinRxDataset';
|
||||
|
||||
procedure TBinaryRxDatapacketReader.LoadFieldDefs(AFieldDefs: TFieldDefs);
|
||||
var
|
||||
FldCount : word;
|
||||
i : integer;
|
||||
begin
|
||||
|
||||
if not RecognizeStream(Stream) then
|
||||
DatabaseError(SStreamNotRecognised);
|
||||
|
||||
FldCount:=Stream.ReadWord;
|
||||
AFieldDefs.Clear;
|
||||
for i := 0 to FldCount -1 do with TFieldDef.create(AFieldDefs) do
|
||||
begin
|
||||
Name := Stream.ReadAnsiString;
|
||||
Displayname := Stream.ReadAnsiString;
|
||||
Size := Stream.ReadWord;
|
||||
DataType := TFieldType(Stream.ReadWord);
|
||||
|
||||
if Stream.ReadByte = 1 then
|
||||
Attributes := Attributes + [faReadonly];
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
procedure TBinaryRxDatapacketReader.StoreFieldDefs(AFieldDefs: TFieldDefs);
|
||||
var i : integer;
|
||||
begin
|
||||
Stream.Write(RxBinaryIdent[1],length(RxBinaryIdent));
|
||||
|
||||
Stream.WriteWord(AFieldDefs.Count);
|
||||
for i := 0 to AFieldDefs.Count -1 do with AFieldDefs[i] do
|
||||
begin
|
||||
Stream.WriteAnsiString(Name);
|
||||
Stream.WriteAnsiString(DisplayName);
|
||||
Stream.WriteWord(size);
|
||||
Stream.WriteWord(ord(DataType));
|
||||
|
||||
if faReadonly in Attributes then
|
||||
Stream.WriteByte(1)
|
||||
else
|
||||
Stream.WriteByte(0);
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
function TBinaryRxDatapacketReader.GetRecordRowState(out AUpdOrder: Integer
|
||||
): TRowState;
|
||||
var Buf : byte;
|
||||
begin
|
||||
Buf := 0;
|
||||
AUpdOrder := 0;
|
||||
|
||||
Stream.Read(Buf,1);
|
||||
Result := ByteToRowState(Buf);
|
||||
if Result<>[] then
|
||||
Stream.ReadBuffer(AUpdOrder,sizeof(integer));
|
||||
|
||||
end;
|
||||
|
||||
procedure TBinaryRxDatapacketReader.FinalizeStoreRecords;
|
||||
begin
|
||||
// Do nothing
|
||||
end;
|
||||
|
||||
function TBinaryRxDatapacketReader.GetCurrentRecord: boolean;
|
||||
var
|
||||
Buf : byte;
|
||||
begin
|
||||
Buf := 0;
|
||||
Result := (Stream.Read(Buf,1)=1) and (Buf=$fe);
|
||||
end;
|
||||
|
||||
procedure TBinaryRxDatapacketReader.GotoNextRecord;
|
||||
begin
|
||||
// Do Nothing
|
||||
end;
|
||||
|
||||
procedure TBinaryRxDatapacketReader.InitLoadRecords;
|
||||
begin
|
||||
// Do Nothing
|
||||
end;
|
||||
|
||||
procedure TBinaryRxDatapacketReader.RestoreRecord(ADataset: TDataset);
|
||||
begin
|
||||
Stream.ReadBuffer(ADataset.ActiveBuffer^,ADataset.RecordSize);
|
||||
end;
|
||||
|
||||
procedure TBinaryRxDatapacketReader.StoreRecord(ADataset: TDataset;
|
||||
ARowState: TRowState; AUpdOrder: integer);
|
||||
begin
|
||||
Stream.WriteByte($fe);
|
||||
Stream.WriteByte(RowStateToByte(ARowState));
|
||||
if ARowState<>[] then
|
||||
Stream.WriteBuffer(AUpdOrder,sizeof(integer));
|
||||
Stream.WriteBuffer(ADataset.ActiveBuffer^,ADataset.RecordSize);
|
||||
end;
|
||||
|
||||
class function TBinaryRxDatapacketReader.RecognizeStream(AStream: TStream
|
||||
): boolean;
|
||||
var s : string;
|
||||
len : integer;
|
||||
begin
|
||||
Len := length(RxBinaryIdent);
|
||||
setlength(s,len);
|
||||
if (AStream.Read (s[1],len) = len)
|
||||
and (s=RxBinaryIdent) then
|
||||
Result := True
|
||||
else
|
||||
Result := False;
|
||||
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterDatapacketReader(TBinaryRxDatapacketReader,dfBinary);
|
||||
end.
|
||||
|
170
RXLib/rxdb/ex_rx_datapacket.pas
Normal file
170
RXLib/rxdb/ex_rx_datapacket.pas
Normal file
@@ -0,0 +1,170 @@
|
||||
{ ex_rx_datapacket unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit ex_rx_datapacket;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils,db;
|
||||
|
||||
type
|
||||
TRowStateValue = (rsvOriginal, rsvDeleted, rsvInserted, rsvUpdated, rsvDetailUpdates);
|
||||
TRowState = set of TRowStateValue;
|
||||
|
||||
type
|
||||
TRxDataPacketFormat = (dfBinary,dfXML,dfXMLUTF8,dfAny);
|
||||
|
||||
type
|
||||
|
||||
{ TRxDatapacketReader }
|
||||
|
||||
TRxDatapacketReaderClass = class of TRxDatapacketReader;
|
||||
TRxDatapacketReader = class(TObject)
|
||||
FStream : TStream;
|
||||
protected
|
||||
class function RowStateToByte(const ARowState : TRowState) : byte;
|
||||
class function ByteToRowState(const AByte : Byte) : TRowState;
|
||||
public
|
||||
constructor create(AStream : TStream); virtual;
|
||||
// Load a dataset from stream:
|
||||
// Load the field-definitions from a stream.
|
||||
procedure LoadFieldDefs(AFieldDefs : TFieldDefs); virtual; abstract;
|
||||
// Is called before the records are loaded
|
||||
procedure InitLoadRecords; virtual; abstract;
|
||||
// Return the RowState of the current record, and the order of the update
|
||||
function GetRecordRowState(out AUpdOrder : Integer) : TRowState; virtual; abstract;
|
||||
// Returns if there is at least one more record available in the stream
|
||||
function GetCurrentRecord : boolean; virtual; abstract;
|
||||
// Store a record from stream in the current record-buffer
|
||||
procedure RestoreRecord(ADataset : TDataset); virtual; abstract;
|
||||
// Move the stream to the next record
|
||||
procedure GotoNextRecord; virtual; abstract;
|
||||
|
||||
// Store a dataset to stream:
|
||||
// Save the field-definitions to a stream.
|
||||
procedure StoreFieldDefs(AFieldDefs : TFieldDefs); virtual; abstract;
|
||||
// Save a record from the current record-buffer to the stream
|
||||
procedure StoreRecord(ADataset : TDataset; ARowState : TRowState; AUpdOrder : integer = 0); virtual; abstract;
|
||||
// Is called after all records are stored
|
||||
procedure FinalizeStoreRecords; virtual; abstract;
|
||||
// Checks if the provided stream is of the right format for this class
|
||||
class function RecognizeStream(AStream : TStream) : boolean; virtual; abstract;
|
||||
property Stream: TStream read FStream;
|
||||
end;
|
||||
|
||||
type
|
||||
TRxDatapacketReaderRegistration = record
|
||||
ReaderClass : TRxDatapacketReaderClass;
|
||||
Format : TRxDatapacketFormat;
|
||||
end;
|
||||
|
||||
function GetRegisterDatapacketReader(AStream : TStream; AFormat : TRxDatapacketFormat; var ADataReaderClass : TRxDatapacketReaderRegistration) : boolean;
|
||||
procedure RegisterDatapacketReader(ADatapacketReaderClass : TRxDatapacketReaderClass; AFormat : TRxDatapacketFormat);
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
RxRegisteredDatapacketReaders : Array of TRxDatapacketReaderRegistration;
|
||||
|
||||
|
||||
function GetRegisterDatapacketReader(AStream: TStream;
|
||||
AFormat: TRxDatapacketFormat;
|
||||
var ADataReaderClass: TRxDatapacketReaderRegistration): boolean;
|
||||
var i : integer;
|
||||
begin
|
||||
Result := False;
|
||||
for i := 0 to length(RxRegisteredDatapacketReaders)-1 do if ((AFormat=dfAny) or (AFormat=RxRegisteredDatapacketReaders[i].Format)) then
|
||||
begin
|
||||
|
||||
if (AStream <> nil) then
|
||||
AStream.Seek(0,soFromBeginning); // ensure at start of stream to check value
|
||||
|
||||
if (AStream=nil) or (RxRegisteredDatapacketReaders[i].ReaderClass.RecognizeStream(AStream)) then
|
||||
begin
|
||||
ADataReaderClass := RxRegisteredDatapacketReaders[i];
|
||||
Result := True;
|
||||
if (AStream <> nil) then
|
||||
AStream.Seek(0,soFromBeginning);
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure RegisterDatapacketReader(
|
||||
ADatapacketReaderClass: TRxDatapacketReaderClass; AFormat: TRxDatapacketFormat
|
||||
);
|
||||
begin
|
||||
setlength(RxRegisteredDatapacketReaders,length(RxRegisteredDatapacketReaders)+1);
|
||||
with RxRegisteredDatapacketReaders[length(RxRegisteredDatapacketReaders)-1] do
|
||||
begin
|
||||
Readerclass := ADatapacketReaderClass;
|
||||
Format := AFormat;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TRxDatapacketReader }
|
||||
|
||||
class function TRxDatapacketReader.RowStateToByte(const ARowState: TRowState
|
||||
): byte;
|
||||
var RowStateInt : Byte;
|
||||
begin
|
||||
RowStateInt:=0;
|
||||
if rsvOriginal in ARowState then RowStateInt := RowStateInt+1;
|
||||
if rsvDeleted in ARowState then RowStateInt := RowStateInt+2;
|
||||
if rsvInserted in ARowState then RowStateInt := RowStateInt+4;
|
||||
if rsvUpdated in ARowState then RowStateInt := RowStateInt+8;
|
||||
Result := RowStateInt;
|
||||
end;
|
||||
|
||||
class function TRxDatapacketReader.ByteToRowState(const AByte: Byte
|
||||
): TRowState;
|
||||
begin
|
||||
result := [];
|
||||
if (AByte and 1)=1 then Result := Result+[rsvOriginal];
|
||||
if (AByte and 2)=2 then Result := Result+[rsvDeleted];
|
||||
if (AByte and 4)=4 then Result := Result+[rsvInserted];
|
||||
if (AByte and 8)=8 then Result := Result+[rsvUpdated];
|
||||
end;
|
||||
|
||||
constructor TRxDatapacketReader.create(AStream: TStream);
|
||||
begin
|
||||
FStream := AStream;
|
||||
end;
|
||||
|
||||
initialization
|
||||
setlength(RxRegisteredDatapacketReaders,0);
|
||||
finalization
|
||||
setlength(RxRegisteredDatapacketReaders,0);
|
||||
end.
|
||||
|
436
RXLib/rxdb/ex_rx_xml_datapacket.pas
Normal file
436
RXLib/rxdb/ex_rx_xml_datapacket.pas
Normal file
@@ -0,0 +1,436 @@
|
||||
{ ex_rx_xml_datapacket unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs@yandex.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.
|
||||
}
|
||||
|
||||
{
|
||||
TXMLRxDatapacketReader implementation
|
||||
|
||||
See the file COPYING.FPC, included in this distribution,
|
||||
for details about the copyright.
|
||||
|
||||
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.
|
||||
|
||||
**********************************************************************}
|
||||
|
||||
unit ex_rx_xml_datapacket;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, dom, db, ex_rx_datapacket;
|
||||
|
||||
type
|
||||
TChangeLogEntry = record
|
||||
UpdateKind : TUpdateKind;
|
||||
OrigEntry : integer;
|
||||
NewEntry : integer;
|
||||
end;
|
||||
TChangeLogEntryArr = array of TChangeLogEntry;
|
||||
|
||||
type
|
||||
{ TXMLRxDatapacketReader }
|
||||
|
||||
TXMLRxDatapacketReader = class(TRxDataPacketReader)
|
||||
XMLDocument : TXMLDocument;
|
||||
DataPacketNode : TDOMElement;
|
||||
MetaDataNode : TDOMNode;
|
||||
FieldsNode : TDOMNode;
|
||||
FChangeLogNode,
|
||||
FParamsNode,
|
||||
FRowDataNode,
|
||||
FRecordNode : TDOMNode;
|
||||
FChangeLog : TChangeLogEntryArr;
|
||||
FEntryNr : integer;
|
||||
FLastChange : integer;
|
||||
public
|
||||
destructor destroy; override;
|
||||
procedure StoreFieldDefs(AFieldDefs : TFieldDefs); override;
|
||||
procedure StoreRecord(ADataset : TDataset; ARowState : TRowState; AUpdOrder : integer = 0); override;
|
||||
procedure FinalizeStoreRecords; override;
|
||||
procedure LoadFieldDefs(AFieldDefs : TFieldDefs); override;
|
||||
procedure InitLoadRecords; override;
|
||||
function GetCurrentRecord : boolean; override;
|
||||
function GetRecordRowState(out AUpdOrder : Integer) : TRowState; override;
|
||||
procedure RestoreRecord(ADataset : TDataset); override;
|
||||
procedure GotoNextRecord; override;
|
||||
class function RecognizeStream(AStream : TStream) : boolean; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses xmlwrite, xmlread, rxdconst;
|
||||
|
||||
const
|
||||
XMLFieldtypenames : Array [TFieldType] of String[15] =
|
||||
(
|
||||
'Unknown',
|
||||
'string',
|
||||
'i2',
|
||||
'i4',
|
||||
'i4',
|
||||
'boolean',
|
||||
'r8',
|
||||
'r8',
|
||||
'fixed',
|
||||
'date',
|
||||
'time',
|
||||
'datetime',
|
||||
'bin.hex',
|
||||
'bin.hex',
|
||||
'i4',
|
||||
'bin.hex',
|
||||
'bin.hex',
|
||||
'bin.hex',
|
||||
'bin.hex',
|
||||
'bin.hex',
|
||||
'bin.hex',
|
||||
'bin.hex',
|
||||
'',
|
||||
'string',
|
||||
'string',
|
||||
'i8',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
''
|
||||
);
|
||||
|
||||
|
||||
{ TXMLRxDatapacketReader }
|
||||
|
||||
destructor TXMLRxDatapacketReader.destroy;
|
||||
begin
|
||||
FieldsNode.Free;
|
||||
MetaDataNode.Free;
|
||||
DataPacketNode.Free;
|
||||
XMLDocument.Free;
|
||||
inherited destroy;
|
||||
end;
|
||||
|
||||
// Actually does a lot more than just loading the field defs...
|
||||
procedure TXMLRxDatapacketReader.LoadFieldDefs(AFieldDefs : TFieldDefs);
|
||||
|
||||
function GetNodeAttribute(const aNode : TDOMNode; AttName : String) : string;
|
||||
var AnAttr : TDomNode;
|
||||
begin
|
||||
AnAttr := ANode.Attributes.GetNamedItem(AttName);
|
||||
if assigned(AnAttr) then result := AnAttr.NodeValue
|
||||
else result := '';
|
||||
end;
|
||||
|
||||
var i : integer;
|
||||
AFieldDef : TFieldDef;
|
||||
iFieldType : TFieldType;
|
||||
FTString : string;
|
||||
AFieldNode : TDOMNode;
|
||||
bLoadFieldDefs : Boolean;
|
||||
|
||||
begin
|
||||
|
||||
// if we already have field defs then don't reload from the file
|
||||
bLoadFieldDefs := (AFieldDefs.Count = 0);
|
||||
|
||||
|
||||
ReadXMLFile(XMLDocument,Stream);
|
||||
DataPacketNode := XMLDocument.FindNode('DATAPACKET') as TDOMElement;
|
||||
if not assigned(DataPacketNode) then DatabaseError(sUnknownXMLDatasetFormat);
|
||||
|
||||
MetaDataNode := DataPacketNode.FindNode('METADATA');
|
||||
if not assigned(MetaDataNode) then DatabaseError(sUnknownXMLDatasetFormat);
|
||||
|
||||
FieldsNode := MetaDataNode.FindNode('FIELDS');
|
||||
if not assigned(FieldsNode) then DatabaseError(sUnknownXMLDatasetFormat);
|
||||
|
||||
if bLoadFieldDefs then
|
||||
begin
|
||||
with FieldsNode.ChildNodes do for i := 0 to Count - 1 do
|
||||
begin
|
||||
AFieldNode := item[i];
|
||||
if AFieldNode.CompareName('FIELD')=0 then
|
||||
begin
|
||||
AFieldDef := TFieldDef.create(AFieldDefs);
|
||||
AFieldDef.DisplayName:=GetNodeAttribute(AFieldNode,'fieldname');
|
||||
AFieldDef.Name:=GetNodeAttribute(AFieldNode,'attrname');
|
||||
AFieldDef.Size:=StrToIntDef(GetNodeAttribute(AFieldNode,'width'),0);
|
||||
FTString:=GetNodeAttribute(AFieldNode,'fieldtype');
|
||||
|
||||
AFieldDef.DataType:=ftUnknown;
|
||||
for iFieldType:=low(TFieldType) to high(TFieldType) do
|
||||
if SameText(XMLFieldtypenames[iFieldType],FTString) then
|
||||
begin
|
||||
AFieldDef.DataType:=iFieldType;
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
FChangeLogNode := MetaDataNode.FindNode('PARAMS');
|
||||
if assigned(FChangeLogNode) then
|
||||
FChangeLogNode := FChangeLogNode.Attributes.GetNamedItem('CHANGE_LOG');
|
||||
|
||||
FRowDataNode := DataPacketNode.FindNode('ROWDATA');
|
||||
FRecordNode := nil;
|
||||
end;
|
||||
|
||||
procedure TXMLRxDatapacketReader.StoreFieldDefs(AFieldDefs: TFieldDefs);
|
||||
|
||||
var i : integer;
|
||||
AFieldNode : TDOMElement;
|
||||
|
||||
begin
|
||||
XMLDocument := TXMLDocument.Create;
|
||||
DataPacketNode := XMLDocument.CreateElement('DATAPACKET');
|
||||
DataPacketNode.SetAttribute('Version','2.0');
|
||||
|
||||
MetaDataNode := XMLDocument.CreateElement('METADATA');
|
||||
FieldsNode := XMLDocument.CreateElement('FIELDS');
|
||||
|
||||
for i := 0 to AFieldDefs.Count -1 do with AFieldDefs[i] do
|
||||
begin
|
||||
AFieldNode := XMLDocument.CreateElement('FIELD');
|
||||
if Name <> '' then AFieldNode.SetAttribute('fieldname',Name);
|
||||
AFieldNode.SetAttribute('attrname',DisplayName);
|
||||
if size <> 0 then AFieldNode.SetAttribute('width',IntToStr(Size));
|
||||
AFieldNode.SetAttribute('fieldtype',XMLFieldtypenames[DataType]);
|
||||
case DataType of
|
||||
ftAutoInc : begin
|
||||
AFieldNode.SetAttribute('readonly','true');
|
||||
AFieldNode.SetAttribute('subtype','Autoinc');
|
||||
end;
|
||||
ftCurrency: AFieldNode.SetAttribute('subtype','Money');
|
||||
ftVarBytes,
|
||||
ftBlob : AFieldNode.SetAttribute('subtype','Binary');
|
||||
ftMemo : AFieldNode.SetAttribute('subtype','Text');
|
||||
ftTypedBinary,
|
||||
ftGraphic: AFieldNode.SetAttribute('subtype','Graphics');
|
||||
ftFmtMemo : AFieldNode.SetAttribute('subtype','Formatted');
|
||||
ftParadoxOle,
|
||||
ftDBaseOle : AFieldNode.SetAttribute('subtype','Ole');
|
||||
end; {case}
|
||||
if faReadonly in Attributes then AFieldNode.SetAttribute('readonly','true');
|
||||
|
||||
FieldsNode.AppendChild(AFieldNode);
|
||||
end;
|
||||
|
||||
MetaDataNode.AppendChild(FieldsNode);
|
||||
FParamsNode := XMLDocument.CreateElement('PARAMS');
|
||||
MetaDataNode.AppendChild(FParamsNode);
|
||||
DataPacketNode.AppendChild(MetaDataNode);
|
||||
FRowDataNode := XMLDocument.CreateElement('ROWDATA');
|
||||
setlength(FChangeLog,0);
|
||||
FEntryNr:=0;
|
||||
FLastChange:=-1;
|
||||
end;
|
||||
|
||||
procedure TXMLRxDatapacketReader.FinalizeStoreRecords;
|
||||
var ChangeLogStr : String;
|
||||
i : integer;
|
||||
begin
|
||||
ChangeLogStr:='';
|
||||
for i := 0 to length(FChangeLog)-1 do with FChangeLog[i] do
|
||||
begin
|
||||
ChangeLogStr:=ChangeLogStr+' '+inttostr(NewEntry)+' '+inttostr(OrigEntry)+' ';
|
||||
if UpdateKind=ukModify then ChangeLogStr := ChangeLogStr+'8';
|
||||
if UpdateKind=ukInsert then ChangeLogStr := ChangeLogStr+'4';
|
||||
if UpdateKind=ukDelete then ChangeLogStr := ChangeLogStr+'2';
|
||||
end;
|
||||
setlength(FChangeLog,0);
|
||||
|
||||
if ChangeLogStr<>'' then
|
||||
(FParamsNode as TDomElement).SetAttribute('CHANGE_LOG',Trim(ChangeLogStr));
|
||||
|
||||
DataPacketNode.AppendChild(FRowDataNode);
|
||||
XMLDocument.AppendChild(DataPacketNode);
|
||||
|
||||
WriteXML(XMLDocument,Stream);
|
||||
end;
|
||||
|
||||
function TXMLRxDatapacketReader.GetCurrentRecord: boolean;
|
||||
begin
|
||||
Result := assigned(FRecordNode);
|
||||
end;
|
||||
|
||||
function TXMLRxDatapacketReader.GetRecordRowState(out AUpdOrder: Integer
|
||||
): TRowState;
|
||||
var ARowStateNode : TDOmNode;
|
||||
ARowState : integer;
|
||||
i : integer;
|
||||
begin
|
||||
ARowStateNode := FRecordNode.Attributes.GetNamedItem('RowState');
|
||||
if ARowStateNode = nil then // This item is not edited
|
||||
Result := []
|
||||
else
|
||||
begin
|
||||
Result := ByteToRowState(StrToIntDef(ARowStateNode.NodeValue,0));
|
||||
if Result = [rsvOriginal] then
|
||||
begin
|
||||
for i := 0 to length(FChangeLog)-1 do
|
||||
if FChangeLog[i].NewEntry=FEntryNr then break;
|
||||
assert(FChangeLog[i].NewEntry=FEntryNr);
|
||||
end
|
||||
else
|
||||
begin
|
||||
for i := 0 to length(FChangeLog)-1 do
|
||||
if FChangeLog[i].OrigEntry=FEntryNr then break;
|
||||
assert(FChangeLog[i].OrigEntry=FEntryNr);
|
||||
end;
|
||||
AUpdOrder:=i;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TXMLRxDatapacketReader.InitLoadRecords;
|
||||
|
||||
var ChangeLogStr : String;
|
||||
i,cp : integer;
|
||||
ps : string;
|
||||
|
||||
begin
|
||||
FRecordNode := FRowDataNode.FirstChild;
|
||||
FEntryNr := 1;
|
||||
setlength(FChangeLog,0);
|
||||
if assigned(FChangeLogNode) then
|
||||
ChangeLogStr:=FChangeLogNode.NodeValue
|
||||
else
|
||||
ChangeLogStr:='';
|
||||
ps := '';
|
||||
cp := 0;
|
||||
if ChangeLogStr<>'' then for i := 1 to length(ChangeLogStr)+1 do
|
||||
begin
|
||||
if not (ChangeLogStr[i] in [' ',#0]) then
|
||||
ps := ps + ChangeLogStr[i]
|
||||
else
|
||||
begin
|
||||
case (cp mod 3) of
|
||||
0 : begin
|
||||
SetLength(FChangeLog,length(FChangeLog)+1);
|
||||
FChangeLog[cp div 3].OrigEntry:=StrToIntDef(ps,0);
|
||||
end;
|
||||
1 : FChangeLog[cp div 3].NewEntry:=StrToIntDef(ps,0);
|
||||
2 : begin
|
||||
if ps = '2' then
|
||||
FChangeLog[cp div 3].UpdateKind:=ukDelete
|
||||
else if ps = '4' then
|
||||
FChangeLog[cp div 3].UpdateKind:=ukInsert
|
||||
else if ps = '8' then
|
||||
FChangeLog[cp div 3].UpdateKind:=ukModify;
|
||||
end;
|
||||
end; {case}
|
||||
ps := '';
|
||||
inc(cp);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TXMLRxDatapacketReader.RestoreRecord(ADataset : TDataset);
|
||||
var FieldNr : integer;
|
||||
AFieldNode : TDomNode;
|
||||
begin
|
||||
with ADataset do for FieldNr:=0 to FieldCount-1 do
|
||||
begin
|
||||
AFieldNode := FRecordNode.Attributes.GetNamedItem(Fields[FieldNr].FieldName);
|
||||
if assigned(AFieldNode) then
|
||||
begin
|
||||
Fields[FieldNr].AsString := AFieldNode.NodeValue; // set it to the filterbuffer
|
||||
end
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TXMLRxDatapacketReader.StoreRecord(ADataset : TDataset; ARowState : TRowState; AUpdOrder : integer = 0);
|
||||
var FieldNr : Integer;
|
||||
ARecordNode : TDOMElement;
|
||||
begin
|
||||
inc(FEntryNr);
|
||||
ARecordNode := XMLDocument.CreateElement('ROW');
|
||||
for FieldNr := 0 to ADataset.Fields.Count-1 do
|
||||
begin
|
||||
ARecordNode.SetAttribute(ADataset.fields[FieldNr].FieldName,ADataset.fields[FieldNr].AsString);
|
||||
end;
|
||||
if ARowState<>[] then
|
||||
begin
|
||||
ARecordNode.SetAttribute('RowState',inttostr(RowStateToByte(ARowState)));
|
||||
if AUpdOrder>=length(FChangeLog) then
|
||||
setlength(FChangeLog,AUpdOrder+1);
|
||||
if (rsvOriginal in ARowState) or (rsvDeleted in ARowState) then
|
||||
FChangeLog[AUpdOrder].OrigEntry:=FEntryNr;
|
||||
if (rsvDeleted in ARowState) or (rsvUpdated in ARowState) or (rsvInserted in ARowState) then
|
||||
FChangeLog[AUpdOrder].NewEntry:=FEntryNr;
|
||||
if ARowState=[rsvUpdated] then
|
||||
FChangeLog[AUpdOrder].UpdateKind := ukModify;
|
||||
if ARowState=[rsvInserted] then
|
||||
FChangeLog[AUpdOrder].UpdateKind := ukInsert;
|
||||
if ARowState=[rsvDeleted] then
|
||||
FChangeLog[AUpdOrder].UpdateKind := ukDelete;
|
||||
end;
|
||||
FRowDataNode.AppendChild(ARecordNode);
|
||||
end;
|
||||
|
||||
class function TXMLRxDatapacketReader.RecognizeStream(AStream: TStream): boolean;
|
||||
const XmlStart = '<?xml';
|
||||
var s : string;
|
||||
len : integer;
|
||||
begin
|
||||
Len := length(XmlStart);
|
||||
setlength(s,len);
|
||||
if (AStream.Read (s[1],len) = len)
|
||||
and (s=XmlStart) then
|
||||
Result := True
|
||||
else
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
procedure TXMLRxDatapacketReader.GotoNextRecord;
|
||||
begin
|
||||
FRecordNode := FRecordNode.NextSibling;
|
||||
inc(FEntryNr);
|
||||
while assigned(FRecordNode) and (FRecordNode.CompareName('ROW')<>0) do
|
||||
FRecordNode := FRecordNode.NextSibling;
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterDatapacketReader(TXMLRxDatapacketReader,dfXML);
|
||||
end.
|
||||
|
||||
end.
|
||||
|
223
RXLib/rxdb/exsortmds.pas
Normal file
223
RXLib/rxdb/exsortmds.pas
Normal file
@@ -0,0 +1,223 @@
|
||||
{ exsortmds unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit exsortmds;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, DB, RxDBGrid;
|
||||
|
||||
type
|
||||
|
||||
{ TMemDataSetSortEngine }
|
||||
|
||||
TMemDataSetSortEngine = class(TRxDBGridSortEngine)
|
||||
public
|
||||
procedure Sort(FieldName: string; ADataSet:TDataSet; Asc:boolean; SortOptions:TRxSortEngineOptions);override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
uses memds;
|
||||
|
||||
type
|
||||
THackMDS = class(TMemDataSet)
|
||||
end;
|
||||
|
||||
procedure TMemDataSetSortEngine.Sort(FieldName: string; ADataSet: TDataSet;
|
||||
Asc: boolean; SortOptions: TRxSortEngineOptions);
|
||||
var
|
||||
MS:TMemoryStream;
|
||||
V, FRecSize, FRecCount, I, J:integer;
|
||||
BufOrign, BufTest:PChar;
|
||||
PI, PJ:PInteger;
|
||||
S1:string;
|
||||
R1:Double;
|
||||
I1:integer;
|
||||
B1:boolean;
|
||||
D1:TDateTime;
|
||||
Field:TField;
|
||||
|
||||
|
||||
function DoExch:boolean;
|
||||
begin
|
||||
Result:=false;
|
||||
ADataSet.RecNo:=J+1;
|
||||
if Asc then
|
||||
begin
|
||||
case Field.DataType of
|
||||
ftFixedChar,
|
||||
ftWideString,
|
||||
ftString:Result:=S1 > Field.AsString;
|
||||
|
||||
ftBoolean:Result:=B1 > Field.AsBoolean;
|
||||
|
||||
ftInteger,
|
||||
ftWord,
|
||||
ftSmallint,
|
||||
ftAutoInc,
|
||||
ftLargeint:
|
||||
begin
|
||||
Result:=I1 > Field.AsInteger;
|
||||
// writeln('I1=', I1, ' I2=',Field.AsInteger,' Result=', Result, ' i=',i, ' j=',j);
|
||||
end;
|
||||
|
||||
ftFloat,
|
||||
ftCurrency,
|
||||
ftBCD:Result:=R1 > Field.AsFloat;
|
||||
|
||||
ftDate,
|
||||
ftTime,
|
||||
ftDateTime,
|
||||
ftTimeStamp:Result:=D1 > Field.AsFloat;
|
||||
else
|
||||
exit;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
case Field.DataType of
|
||||
ftFixedChar,
|
||||
ftWideString,
|
||||
ftString:Result:=S1 < Field.AsString;
|
||||
|
||||
ftBoolean:Result:=B1 < Field.AsBoolean;
|
||||
|
||||
ftInteger,
|
||||
ftWord,
|
||||
ftSmallint,
|
||||
ftAutoInc,
|
||||
ftLargeint:Result:=I1 < Field.AsInteger;
|
||||
|
||||
ftFloat,
|
||||
ftCurrency,
|
||||
ftBCD:Result:=R1 < Field.AsFloat;
|
||||
|
||||
ftDate,
|
||||
ftTime,
|
||||
ftDateTime,
|
||||
ftTimeStamp:Result:=D1 < Field.AsFloat;
|
||||
else
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
{ if not Asc then
|
||||
Result:=not Result;
|
||||
Result:=true;}
|
||||
end;
|
||||
|
||||
begin
|
||||
if Assigned(ADataSet) then
|
||||
begin
|
||||
Field:=ADataSet.FieldByName(FieldName);
|
||||
ADataSet.DisableControls;
|
||||
MS:=TMemoryStream.Create;
|
||||
BufOrign:=THackMDS(ADataSet).AllocRecordBuffer;
|
||||
BufTest:=THackMDS(ADataSet).AllocRecordBuffer;
|
||||
PI:=@I;
|
||||
PJ:=@J;
|
||||
try
|
||||
THackMDS(ADataSet).SaveDataToStream(MS, true);
|
||||
MS.Seek(0, soFromBeginning);
|
||||
MS.Read(V, SizeOf(V)); // Marker
|
||||
MS.Read(V, SizeOf(V)); // Size
|
||||
FRecSize:=THackMDS(ADataSet).GetRecordSize;
|
||||
FRecCount:=V div FRecSize;
|
||||
for i:=0 to FRecCount-2 do
|
||||
begin
|
||||
MS.Seek(FRecSize*I + SizeOf(V)*2, soFromBeginning);
|
||||
MS.Read(BufOrign^, FRecSize);
|
||||
if i=0 then //fix error
|
||||
ADataSet.First
|
||||
else
|
||||
ADataSet.RecNo:=I+1;
|
||||
|
||||
case Field.DataType of
|
||||
ftFixedChar,
|
||||
ftWideString,
|
||||
ftString:S1:=Field.AsString;
|
||||
|
||||
ftBoolean:B1:=Field.AsBoolean;
|
||||
|
||||
ftInteger,
|
||||
ftWord,
|
||||
ftSmallint,
|
||||
ftAutoInc,
|
||||
ftLargeint:I1:=Field.AsInteger;
|
||||
|
||||
ftFloat,
|
||||
ftCurrency,
|
||||
ftBCD:R1:=Field.AsFloat;
|
||||
|
||||
ftDate,
|
||||
ftTime,
|
||||
ftDateTime,
|
||||
ftTimeStamp:D1:=Field.AsFloat;
|
||||
{ else
|
||||
exit;}
|
||||
end;
|
||||
|
||||
for j:=i+1 to FRecCount-1 do
|
||||
begin
|
||||
MS.Seek(FRecSize*j + SizeOf(V)*2, soFromBeginning);
|
||||
MS.Read(BufTest^, FRecSize);
|
||||
if DoExch then
|
||||
begin
|
||||
MS.Seek(FRecSize*j + SizeOf(V)*2, soFromBeginning);
|
||||
MS.Write(BufOrign^, FRecSize);
|
||||
Move(BufTest^, BufOrign^, FRecSize);
|
||||
end;
|
||||
end;
|
||||
THackMDS(ADataSet).SetBookmarkData(BufOrign, @PI);
|
||||
MS.Seek(FRecSize*I + SizeOf(V)*2, soFromBeginning);
|
||||
MS.Write(BufOrign^, FRecSize);
|
||||
MS.Seek(0, soFromBeginning);
|
||||
THackMDS(ADataSet).LoadDataFromStream(MS);
|
||||
end;
|
||||
// (ADataSet as TFBDataSet).SortOnField(Field.FieldName, Asc);}
|
||||
MS.Seek(0, soFromBeginning);
|
||||
THackMDS(ADataSet).LoadDataFromStream(MS);
|
||||
finally
|
||||
THackMDS(ADataSet).FreeRecordBuffer(BufOrign);
|
||||
THackMDS(ADataSet).FreeRecordBuffer(BufTest);
|
||||
MS.Free;
|
||||
ADataSet.EnableControls;
|
||||
end;
|
||||
THackMDS(ADataSet).First;
|
||||
end;
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterRxDBGridSortEngine(TMemDataSetSortEngine, 'TMemDataset');
|
||||
end.
|
||||
|
363
RXLib/rxdb/rxdbcolorbox.pas
Normal file
363
RXLib/rxdb/rxdbcolorbox.pas
Normal file
@@ -0,0 +1,363 @@
|
||||
{ RxDBColorBox unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs@yandex.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.
|
||||
}
|
||||
|
||||
unit RxDBColorBox;
|
||||
|
||||
{$I rx.inc}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ColorBox,
|
||||
DbCtrls, DB, LMessages, LCLType;
|
||||
|
||||
type
|
||||
|
||||
{ TRxCustomDBColorBox }
|
||||
|
||||
TRxCustomDBColorBox = class(TCustomColorBox)
|
||||
FDataLink: TFieldDataLink;
|
||||
|
||||
procedure DataChange(Sender: TObject);
|
||||
function GetDataField: string;
|
||||
function GetDataSource: TDataSource;
|
||||
function GetField: TField;
|
||||
function GetReadOnly: Boolean;
|
||||
procedure SetDataField(const AValue: string);
|
||||
procedure SetDataSource(const AValue: TDataSource);
|
||||
procedure SetReadOnly(const AValue: Boolean);
|
||||
procedure UpdateData(Sender: TObject);
|
||||
procedure FocusRequest(Sender: TObject);
|
||||
procedure ActiveChange(Sender: TObject);
|
||||
procedure LayoutChange(Sender: TObject);
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
function IsReadOnly: boolean;
|
||||
protected
|
||||
property DataField: string read GetDataField write SetDataField;
|
||||
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
|
||||
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
procedure Change; override;
|
||||
|
||||
procedure Loaded; override;
|
||||
procedure Notification(AComponent: TComponent;
|
||||
Operation: TOperation); override;
|
||||
procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS;
|
||||
procedure WMKillFocus(var Message: TLMKillFocus); message LM_KILLFOCUS;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
property Field: TField read GetField;
|
||||
published
|
||||
{ Published declarations }
|
||||
end;
|
||||
|
||||
TRxDBColorBox = class(TRxCustomDBColorBox)
|
||||
private
|
||||
{ Private declarations }
|
||||
protected
|
||||
{ Protected declarations }
|
||||
public
|
||||
{ Public declarations }
|
||||
published
|
||||
property DataField;
|
||||
property DataSource;
|
||||
property ReadOnly;
|
||||
|
||||
property DefaultColorColor;
|
||||
property NoneColorColor;
|
||||
property Selected;
|
||||
property Style;
|
||||
property OnGetColors;
|
||||
|
||||
property Align;
|
||||
property Anchors;
|
||||
property ArrowKeysTraverseList;
|
||||
property AutoComplete;
|
||||
property AutoCompleteText;
|
||||
property AutoDropDown;
|
||||
property AutoSelect;
|
||||
property AutoSize;
|
||||
property BidiMode;
|
||||
property BorderSpacing;
|
||||
property Color;
|
||||
property Constraints;
|
||||
property DragCursor;
|
||||
property DragMode;
|
||||
property DropDownCount;
|
||||
property Enabled;
|
||||
property Font;
|
||||
property ItemHeight;
|
||||
property ItemWidth;
|
||||
property OnChange;
|
||||
property OnChangeBounds;
|
||||
property OnClick;
|
||||
property OnCloseUp;
|
||||
property OnContextPopup;
|
||||
property OnDblClick;
|
||||
property OnDragDrop;
|
||||
property OnDragOver;
|
||||
property OnEndDrag;
|
||||
property OnDropDown;
|
||||
property OnEditingDone;
|
||||
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 OnStartDrag;
|
||||
property OnSelect;
|
||||
property OnUTF8KeyPress;
|
||||
property ParentBidiMode;
|
||||
property ParentColor;
|
||||
property ParentFont;
|
||||
property ParentShowHint;
|
||||
property PopupMenu;
|
||||
property ShowHint;
|
||||
property TabOrder;
|
||||
property TabStop;
|
||||
property Visible;
|
||||
end;
|
||||
|
||||
implementation
|
||||
uses
|
||||
LCLVersion;
|
||||
|
||||
type
|
||||
TFieldDataLinkHack = class(TFieldDataLink)
|
||||
end;
|
||||
|
||||
|
||||
{ TRxCustomDBColorBox }
|
||||
|
||||
procedure TRxCustomDBColorBox.DataChange(Sender: TObject);
|
||||
begin
|
||||
if Assigned(FDataLink.Field) and (FDataLink.Field.DataType in [ftString, ftInteger, ftLargeint]) then
|
||||
begin
|
||||
if FDatalink.Field.DataType in [ftString] then
|
||||
begin
|
||||
if FDatalink.Field.AsString<>'' then
|
||||
try
|
||||
Selected:=StringToColor(FDatalink.Field.AsString)
|
||||
except
|
||||
Selected:=clNone;
|
||||
end
|
||||
else
|
||||
Selected:=clNone;
|
||||
end
|
||||
else
|
||||
if FDataLink.Field.DataType in [ftInteger, ftLargeint] then
|
||||
begin
|
||||
try
|
||||
Selected:=TColor(FDatalink.Field.AsInteger);
|
||||
except
|
||||
Selected:=clNone;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Selected := clNone;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TRxCustomDBColorBox.GetDataField: string;
|
||||
begin
|
||||
Result := FDataLink.FieldName;
|
||||
end;
|
||||
|
||||
function TRxCustomDBColorBox.GetDataSource: TDataSource;
|
||||
begin
|
||||
Result := FDataLink.DataSource;
|
||||
end;
|
||||
|
||||
function TRxCustomDBColorBox.GetField: TField;
|
||||
begin
|
||||
Result := FDataLink.Field;
|
||||
end;
|
||||
|
||||
function TRxCustomDBColorBox.GetReadOnly: Boolean;
|
||||
begin
|
||||
Result := FDataLink.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.SetDataField(const AValue: string);
|
||||
begin
|
||||
FDataLink.FieldName := AValue;
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.SetDataSource(const AValue: TDataSource);
|
||||
begin
|
||||
ChangeDataSource(Self,FDataLink,AValue);
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.SetReadOnly(const AValue: Boolean);
|
||||
begin
|
||||
inherited;
|
||||
FDataLink.ReadOnly := AValue;
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.UpdateData(Sender: TObject);
|
||||
begin
|
||||
if FDataLink.Field.DataType in [ftString] then
|
||||
FDataLink.Field.AsString := ColorToString(Selected)
|
||||
else
|
||||
if FDataLink.Field.DataType in [ftInteger, ftLargeint] then
|
||||
FDataLink.Field.AsInteger := Integer(Selected);
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.FocusRequest(Sender: TObject);
|
||||
begin
|
||||
SetFocus;
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.ActiveChange(Sender: TObject);
|
||||
begin
|
||||
if FDatalink.Active then
|
||||
DataChange(Sender)
|
||||
else
|
||||
begin
|
||||
Selected := clNone;
|
||||
FDataLink.Reset;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.LayoutChange(Sender: TObject);
|
||||
begin
|
||||
DataChange(Sender);
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.CMGetDataLink(var Message: TLMessage);
|
||||
begin
|
||||
Message.Result := PtrUInt(FDataLink);
|
||||
end;
|
||||
|
||||
function TRxCustomDBColorBox.IsReadOnly: boolean;
|
||||
begin
|
||||
Result := true;
|
||||
if FDatalink.Active and (not Self.ReadOnly) then
|
||||
Result := (Field = nil) or Field.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.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_DELETE then
|
||||
begin
|
||||
if not IsReadOnly then
|
||||
FDatalink.Edit;
|
||||
end
|
||||
else
|
||||
if Key=VK_TAB then
|
||||
begin
|
||||
if FDataLink.CanModify and FDatalink.Editing then
|
||||
FDataLink.UpdateRecord;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.Change;
|
||||
begin
|
||||
FDatalink.Edit;
|
||||
FDataLink.Modified;
|
||||
inherited Change;
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.Loaded;
|
||||
begin
|
||||
inherited Loaded;
|
||||
if (csDesigning in ComponentState) then
|
||||
DataChange(Self);
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.Notification(AComponent: TComponent;
|
||||
Operation: TOperation);
|
||||
begin
|
||||
inherited Notification(AComponent, Operation);
|
||||
if (Operation=opRemove) then
|
||||
begin
|
||||
if (FDataLink<>nil) and (AComponent=DataSource) then
|
||||
DataSource:=nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.WMSetFocus(var Message: TLMSetFocus);
|
||||
begin
|
||||
inherited WMSetFocus(Message);
|
||||
if not FDatalink.Editing then
|
||||
FDatalink.Reset;
|
||||
end;
|
||||
|
||||
procedure TRxCustomDBColorBox.WMKillFocus(var Message: TLMKillFocus);
|
||||
begin
|
||||
inherited WMKillFocus(Message);
|
||||
if not FDatalink.Editing then
|
||||
FDatalink.Reset
|
||||
else
|
||||
TFieldDataLinkHack(FDatalink).UpdateData;
|
||||
end;
|
||||
|
||||
constructor TRxCustomDBColorBox.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FDataLink := TFieldDataLink.Create;
|
||||
FDataLink.Control := Self;
|
||||
FDataLink.OnDataChange := @DataChange;
|
||||
FDataLink.OnUpdateData := @UpdateData;
|
||||
FDataLink.OnActiveChange := @ActiveChange;
|
||||
{$if (lcl_major = 0) and (lcl_release <= 30)}
|
||||
FDataLink.OnLayoutChange := @LayoutChange;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
destructor TRxCustomDBColorBox.Destroy;
|
||||
begin
|
||||
FreeAndNil(FDataLink);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
end.
|
563
RXLib/rxdb/rxdbcomb.pas
Normal file
563
RXLib/rxdb/rxdbcomb.pas
Normal file
@@ -0,0 +1,563 @@
|
||||
{ rxdbcomb unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit rxdbcomb;
|
||||
|
||||
{$I rx.inc}
|
||||
|
||||
interface
|
||||
|
||||
uses LCLType, LCLProc, LCLIntf, LMessages, Menus, Graphics, Classes, Controls,
|
||||
sysutils, DB, StdCtrls, DbCtrls;
|
||||
|
||||
type
|
||||
|
||||
{ TCustomDBComboBox }
|
||||
|
||||
TCustomDBComboBox = class(TCustomComboBox)
|
||||
private
|
||||
FDataLink: TFieldDataLink;
|
||||
procedure DataChange(Sender: TObject);
|
||||
procedure EditingChange(Sender: TObject);
|
||||
function GetDataField: string;
|
||||
function GetDataSource: TDataSource;
|
||||
function GetField: TField;
|
||||
function GetReadOnly: Boolean;
|
||||
procedure SetDataField(const Value: string);
|
||||
procedure SetDataSource(Value: TDataSource);
|
||||
procedure SetEditReadOnly;
|
||||
procedure SetItems(const Value: TStrings);
|
||||
procedure SetReadOnly(Value: Boolean);
|
||||
procedure UpdateData(Sender: TObject);
|
||||
function GetComboText: string; virtual;
|
||||
procedure SetComboText(const Value: string); virtual;
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
protected
|
||||
procedure EditingDone; override;
|
||||
procedure Change; override;
|
||||
procedure Click; override;
|
||||
procedure CreateWnd; override;
|
||||
procedure DropDown; override;
|
||||
function GetPaintText: string; virtual;
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
procedure KeyPress(var Key: Char); override;
|
||||
procedure Loaded; override;
|
||||
procedure Notification(AComponent: TComponent;
|
||||
Operation: TOperation); override;
|
||||
procedure SetStyle(Value: TComboBoxStyle); override;
|
||||
procedure WndProc(var Message: TLMessage); override;
|
||||
property ComboText: string read GetComboText write SetComboText;
|
||||
property DataField: string read GetDataField write SetDataField;
|
||||
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
function ExecuteAction(AAction: TBasicAction): Boolean; override;
|
||||
function UpdateAction(AAction: TBasicAction): Boolean; override;
|
||||
function UseRightToLeftAlignment: Boolean;
|
||||
property Field: TField read GetField;
|
||||
property Items write SetItems;
|
||||
property Text;
|
||||
end;
|
||||
|
||||
{ TRxDBComboBox }
|
||||
|
||||
TRxDBComboBox = class(TCustomDBComboBox)
|
||||
private
|
||||
FValues: TStrings;
|
||||
FEnableValues: Boolean;
|
||||
procedure SetEnableValues(Value: Boolean);
|
||||
procedure SetValues(Value: TStrings);
|
||||
procedure ValuesChanged(Sender: TObject);
|
||||
protected
|
||||
procedure SetStyle(Value: TComboBoxStyle); override;
|
||||
function GetComboText: string; override;
|
||||
function GetPaintText: string; override;
|
||||
procedure SetComboText(const Value: string); override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
published
|
||||
property Anchors;
|
||||
property ArrowKeysTraverseList;
|
||||
property AutoDropDown;
|
||||
property AutoSize;
|
||||
property BorderSpacing;
|
||||
property Style; { must be published before Items }
|
||||
property Color;
|
||||
property DataField;
|
||||
property DataSource;
|
||||
property DragMode;
|
||||
property DragCursor;
|
||||
property DropDownCount;
|
||||
property Enabled;
|
||||
property EnableValues: Boolean read FEnableValues write SetEnableValues;
|
||||
property Font;
|
||||
property Constraints;
|
||||
property DragKind;
|
||||
property ItemHeight;
|
||||
property Items;
|
||||
property ItemWidth;
|
||||
property MaxLength default -1;
|
||||
property ParentColor;
|
||||
property ParentFont;
|
||||
property ParentShowHint;
|
||||
property PopupMenu;
|
||||
property ReadOnly;
|
||||
property ShowHint;
|
||||
property Sorted;
|
||||
property TabOrder;
|
||||
property TabStop;
|
||||
property Values: TStrings read FValues write SetValues;
|
||||
property Visible;
|
||||
property OnChange;
|
||||
property OnChangeBounds;
|
||||
property OnClick;
|
||||
property OnCloseUp;
|
||||
property OnDblClick;
|
||||
property OnDragDrop;
|
||||
property OnDragOver;
|
||||
property OnDrawItem;
|
||||
property OnDropDown;
|
||||
property OnEndDrag;
|
||||
property OnEnter;
|
||||
property OnExit;
|
||||
property OnKeyDown;
|
||||
property OnKeyPress;
|
||||
property OnKeyUp;
|
||||
property OnMeasureItem;
|
||||
property OnMouseDown;
|
||||
property OnMouseMove;
|
||||
property OnMouseUp;
|
||||
property OnMouseWheel;
|
||||
property OnMouseWheelDown;
|
||||
property OnMouseWheelUp;
|
||||
property OnSelect;
|
||||
property OnStartDrag;
|
||||
property OnUTF8KeyPress;
|
||||
property OnContextPopup;
|
||||
property OnEndDock;
|
||||
property OnStartDock;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses rxDBUtils, rxdconst;
|
||||
|
||||
{ TCustomDBComboBox }
|
||||
|
||||
constructor TCustomDBComboBox.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
ControlStyle := ControlStyle + [csReplicatable];
|
||||
FDataLink := TFieldDataLink.Create;
|
||||
FDataLink.Control := Self;
|
||||
FDataLink.OnDataChange := @DataChange;
|
||||
FDataLink.OnUpdateData := @UpdateData;
|
||||
FDataLink.OnEditingChange := @EditingChange;
|
||||
end;
|
||||
|
||||
destructor TCustomDBComboBox.Destroy;
|
||||
begin
|
||||
FDataLink.OnDataChange := nil;
|
||||
FDataLink.OnUpdateData := nil;
|
||||
FDataLink.Free;
|
||||
FDataLink := nil;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.Loaded;
|
||||
begin
|
||||
inherited Loaded;
|
||||
if (csDesigning in ComponentState) then DataChange(Self);
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.Notification(AComponent: TComponent;
|
||||
Operation: TOperation);
|
||||
begin
|
||||
inherited Notification(AComponent, Operation);
|
||||
if (Operation = opRemove) and (FDataLink <> nil) and
|
||||
(AComponent = DataSource) then DataSource := nil;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.CreateWnd;
|
||||
begin
|
||||
inherited CreateWnd;
|
||||
SetEditReadOnly;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.DataChange(Sender: TObject);
|
||||
begin
|
||||
if DroppedDown then Exit;
|
||||
if FDataLink.Field <> nil then ComboText := FDataLink.Field.AsString
|
||||
else if csDesigning in ComponentState then ComboText := Name
|
||||
else ComboText := '';
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.UpdateData(Sender: TObject);
|
||||
begin
|
||||
if Assigned(FDataLink.Field) then
|
||||
FDataLink.Field.AsString := ComboText
|
||||
else
|
||||
raise Exception.CreateFmt(SDBComboBoxFieldNotAssigned, [Name]);
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.SetComboText(const Value: string);
|
||||
var
|
||||
I: Integer;
|
||||
Redraw: Boolean;
|
||||
begin
|
||||
if Value <> ComboText then
|
||||
begin
|
||||
if Style <> csDropDown then
|
||||
begin
|
||||
Redraw := (Style <> csSimple) and HandleAllocated;
|
||||
// if Redraw then SendMessage(Handle, LM_SETREDRAW, 0, 0);
|
||||
try
|
||||
if Value = '' then I := -1 else I := Items.IndexOf(Value);
|
||||
ItemIndex := I;
|
||||
finally
|
||||
if Redraw then
|
||||
begin
|
||||
// SendMessage(Handle, WM_SETREDRAW, 1, 0);
|
||||
Invalidate;
|
||||
end;
|
||||
end;
|
||||
if I >= 0 then Exit;
|
||||
end;
|
||||
if Style in [csDropDown, csSimple] then Text := Value;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.CMGetDataLink(var Message: TLMessage);
|
||||
begin
|
||||
Message.Result := PtrUInt(FDataLink);
|
||||
end;
|
||||
|
||||
function TCustomDBComboBox.GetComboText: string;
|
||||
var
|
||||
I: Integer;
|
||||
begin
|
||||
if Style in [csDropDown, csSimple] then Result := Text
|
||||
else
|
||||
begin
|
||||
I := ItemIndex;
|
||||
if I < 0 then Result := '' else Result := Items[I];
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.Change;
|
||||
begin
|
||||
FDataLink.Edit;
|
||||
FDataLink.Modified;
|
||||
FDataLink.UpdateRecord;
|
||||
inherited Change;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.Click;
|
||||
begin
|
||||
FDataLink.Edit;
|
||||
inherited Click;
|
||||
FDataLink.Modified;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.DropDown;
|
||||
begin
|
||||
FDataLink.Edit;
|
||||
inherited DropDown;
|
||||
end;
|
||||
|
||||
function TCustomDBComboBox.GetDataSource: TDataSource;
|
||||
begin
|
||||
Result := FDataLink.DataSource;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.SetDataSource(Value: TDataSource);
|
||||
begin
|
||||
if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
|
||||
FDataLink.DataSource := Value;
|
||||
if Value <> nil then Value.FreeNotification(Self);
|
||||
end;
|
||||
|
||||
function TCustomDBComboBox.GetDataField: string;
|
||||
begin
|
||||
Result := FDataLink.FieldName;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.SetDataField(const Value: string);
|
||||
begin
|
||||
FDataLink.FieldName := Value;
|
||||
end;
|
||||
|
||||
function TCustomDBComboBox.GetReadOnly: Boolean;
|
||||
begin
|
||||
Result := FDataLink.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.SetReadOnly(Value: Boolean);
|
||||
begin
|
||||
FDataLink.ReadOnly := Value;
|
||||
end;
|
||||
|
||||
function TCustomDBComboBox.GetField: TField;
|
||||
begin
|
||||
Result := FDataLink.Field;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.KeyDown(var Key: Word; Shift: TShiftState);
|
||||
begin
|
||||
inherited KeyDown(Key, Shift);
|
||||
if (Key = VK_BACK) or (Key = VK_DELETE) or (Key = VK_UP) or
|
||||
(Key = VK_DOWN) or (Key in [32..255]) then
|
||||
begin
|
||||
if not FDataLink.Edit and (Key in [VK_UP, VK_DOWN]) then
|
||||
Key := 0;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.KeyPress(var Key: Char);
|
||||
begin
|
||||
inherited KeyPress(Key);
|
||||
if (Key in [#32..#255]) and (FDataLink.Field <> nil) and
|
||||
not FDataLink.Field.IsValidChar(Key) then
|
||||
begin
|
||||
// MessageBeep(0);
|
||||
Key := #0;
|
||||
end;
|
||||
case Key of
|
||||
^H, ^V, ^X, #32..#255:
|
||||
FDataLink.Edit;
|
||||
#27:
|
||||
begin
|
||||
FDataLink.Reset;
|
||||
SelectAll;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.EditingChange(Sender: TObject);
|
||||
begin
|
||||
SetEditReadOnly;
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.SetEditReadOnly;
|
||||
begin
|
||||
(* if (Style in [csDropDown, csSimple]) and HandleAllocated then
|
||||
SendMessage({$IFDEF WIN32} EditHandle {$ELSE} FEditHandle {$ENDIF},
|
||||
EM_SETREADONLY, Ord(not FDataLink.Editing), 0); *)
|
||||
end;
|
||||
|
||||
|
||||
procedure TCustomDBComboBox.WndProc(var Message: TLMessage);
|
||||
begin
|
||||
if not (csDesigning in ComponentState) then
|
||||
case Message.Msg of
|
||||
LM_COMMAND:
|
||||
if TLMCommand(Message).NotifyCode = CBN_SELCHANGE then
|
||||
if not FDataLink.Edit then begin
|
||||
{ if Style <> csSimple then
|
||||
PostMessage(Handle, LB_SHOWDROPDOWN, 0, 0);}
|
||||
Exit;
|
||||
end;
|
||||
{ CB_SHOWDROPDOWN:
|
||||
if Message.WParam <> 0 then FDataLink.Edit
|
||||
else if not FDataLink.Editing then DataChange(Self); }{Restore text}
|
||||
{$IFDEF WIN32}
|
||||
{ LM_CREATE,
|
||||
WM_WINDOWPOSCHANGED,
|
||||
CM_FONTCHANGED:
|
||||
FPaintControl.DestroyHandle;}
|
||||
{$ENDIF}
|
||||
end;
|
||||
inherited WndProc(Message);
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.EditingDone;
|
||||
begin
|
||||
if Assigned(FDataLink.DataSet) and (FDataLink.DataSet.State in [dsinsert,dsedit]) then
|
||||
begin
|
||||
try
|
||||
FDataLink.UpdateRecord;
|
||||
except
|
||||
SelectAll;
|
||||
if CanFocus then SetFocus;
|
||||
raise;
|
||||
end;
|
||||
inherited EditingDone;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function TCustomDBComboBox.GetPaintText: string;
|
||||
begin
|
||||
if FDataLink.Field <> nil then Result := FDataLink.Field.Text
|
||||
else Result := '';
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.SetItems(const Value: TStrings);
|
||||
begin
|
||||
Items.Assign(Value);
|
||||
DataChange(Self);
|
||||
end;
|
||||
|
||||
procedure TCustomDBComboBox.SetStyle(Value: TComboBoxStyle);
|
||||
begin
|
||||
if (Value = csSimple) and Assigned(FDatalink) and FDatalink.DatasourceFixed then
|
||||
_DBError('SNotReplicatable');
|
||||
inherited SetStyle(Value);
|
||||
end;
|
||||
|
||||
function TCustomDBComboBox.UseRightToLeftAlignment: Boolean;
|
||||
begin
|
||||
// Result := DBUseRightToLeftAlignment(Self, Field);
|
||||
end;
|
||||
|
||||
function TCustomDBComboBox.ExecuteAction(AAction: TBasicAction): Boolean;
|
||||
begin
|
||||
{ Result := inherited ExecuteAction(AAction) or (FDataLink <> nil) and
|
||||
FDataLink.ExecuteAction(AAction);}
|
||||
end;
|
||||
|
||||
function TCustomDBComboBox.UpdateAction(AAction: TBasicAction): Boolean;
|
||||
begin
|
||||
{ Result := inherited UpdateAction(AAction) or (FDataLink <> nil) and
|
||||
FDataLink.UpdateAction(AAction);}
|
||||
end;
|
||||
|
||||
{ TRxDBComboBox }
|
||||
|
||||
constructor TRxDBComboBox.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FValues := TStringList.Create;
|
||||
TStringList(FValues).OnChange := @ValuesChanged;
|
||||
EnableValues := False;
|
||||
end;
|
||||
|
||||
destructor TRxDBComboBox.Destroy;
|
||||
begin
|
||||
TStringList(FValues).OnChange := nil;
|
||||
FValues.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TRxDBComboBox.ValuesChanged(Sender: TObject);
|
||||
begin
|
||||
if FEnableValues then DataChange(Self);
|
||||
end;
|
||||
|
||||
function TRxDBComboBox.GetPaintText: string;
|
||||
var
|
||||
I: Integer;
|
||||
begin
|
||||
Result := '';
|
||||
if FDataLink.Field <> nil then begin
|
||||
if FEnableValues then begin
|
||||
I := Values.IndexOf(FDataLink.Field.Text);
|
||||
if I >= 0 then Result := Items.Strings[I]
|
||||
end
|
||||
else Result := FDataLink.Field.Text;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TRxDBComboBox.GetComboText: string;
|
||||
var
|
||||
I: Integer;
|
||||
begin
|
||||
if (Style in [csDropDown, csSimple]) and (not FEnableValues) then
|
||||
Result := Text
|
||||
else begin
|
||||
I := ItemIndex;
|
||||
if (I < 0) or (FEnableValues and (FValues.Count < I + 1)) then
|
||||
Result := ''
|
||||
else
|
||||
if FEnableValues then Result := FValues[I]
|
||||
else Result := Items[I];
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRxDBComboBox.SetComboText(const Value: string);
|
||||
var
|
||||
I: Integer;
|
||||
Redraw: Boolean;
|
||||
begin
|
||||
if Value <> ComboText then
|
||||
begin
|
||||
if Style <> csDropDown then
|
||||
begin
|
||||
Redraw := (Style <> csSimple) and HandleAllocated;
|
||||
// if Redraw then SendMessage(Handle, WM_SETREDRAW, 0, 0);
|
||||
try
|
||||
if Value = '' then I := -1
|
||||
else
|
||||
if FEnableValues then I := Values.IndexOf(Value)
|
||||
else I := Items.IndexOf(Value);
|
||||
if I >= Items.Count then I := -1;
|
||||
ItemIndex := I;
|
||||
finally
|
||||
if Redraw then
|
||||
begin
|
||||
// SendMessage(Handle, WM_SETREDRAW, 1, 0);
|
||||
// Invalidate;
|
||||
end;
|
||||
end;
|
||||
if I >= 0 then Exit;
|
||||
end;
|
||||
if Style in [csDropDown, csSimple] then Text := Value;
|
||||
Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRxDBComboBox.SetEnableValues(Value: Boolean);
|
||||
begin
|
||||
if FEnableValues <> Value then
|
||||
begin
|
||||
if Value and (Style in [csDropDown, csSimple]) then
|
||||
Style := csDropDownList;
|
||||
FEnableValues := Value;
|
||||
DataChange(Self);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRxDBComboBox.SetValues(Value: TStrings);
|
||||
begin
|
||||
FValues.Assign(Value);
|
||||
end;
|
||||
|
||||
procedure TRxDBComboBox.SetStyle(Value: TComboboxStyle);
|
||||
begin
|
||||
if (Value in [csSimple, csDropDown]) and FEnableValues then
|
||||
Value := csDropDownList;
|
||||
inherited SetStyle(Value);
|
||||
end;
|
||||
|
||||
end.
|
472
RXLib/rxdb/rxdbctrls.pas
Normal file
472
RXLib/rxdb/rxdbctrls.pas
Normal file
@@ -0,0 +1,472 @@
|
||||
{ RxDBCtrls unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit RxDBCtrls;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, ComCtrls, DB, DbCtrls, LMessages, LCLType;
|
||||
|
||||
type
|
||||
|
||||
{ TCustomRxDBProgressBar }
|
||||
|
||||
TCustomRxDBProgressBar = class(TCustomProgressBar)
|
||||
private
|
||||
FDataLink: TFieldDataLink;
|
||||
function GetDataField: string;
|
||||
function GetDataSource: TDataSource;
|
||||
function GetField: TField;
|
||||
procedure SetDataField(const AValue: string);
|
||||
procedure SetDataSource(const AValue: TDataSource);
|
||||
procedure DataChange(Sender: TObject);
|
||||
procedure ActiveChange(Sender: TObject);
|
||||
procedure LayoutChange(Sender: TObject);
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
protected
|
||||
property DataField: string read GetDataField write SetDataField;
|
||||
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
property Field: TField read GetField;
|
||||
end;
|
||||
|
||||
TRxDBProgressBar = class(TCustomRxDBProgressBar)
|
||||
published
|
||||
property DataField;
|
||||
property DataSource;
|
||||
property Align;
|
||||
property Anchors;
|
||||
property BorderSpacing;
|
||||
property BorderWidth;
|
||||
property Constraints;
|
||||
property DragCursor;
|
||||
property DragKind;
|
||||
property DragMode;
|
||||
property Enabled;
|
||||
property Hint;
|
||||
property Max;
|
||||
property Min;
|
||||
property OnContextPopup;
|
||||
property OnDragDrop;
|
||||
property OnDragOver;
|
||||
property OnEndDrag;
|
||||
property OnEnter;
|
||||
property OnExit;
|
||||
property OnMouseDown;
|
||||
property OnMouseMove;
|
||||
property OnMouseUp;
|
||||
property OnMouseWheel;
|
||||
property OnMouseWheelDown;
|
||||
property OnMouseWheelUp;
|
||||
property OnStartDock;
|
||||
property OnStartDrag;
|
||||
property Orientation;
|
||||
property ParentShowHint;
|
||||
property PopupMenu;
|
||||
property ShowHint;
|
||||
property Smooth;
|
||||
property Step;
|
||||
property TabOrder;
|
||||
property TabStop;
|
||||
property Visible;
|
||||
property BarShowText;
|
||||
end;
|
||||
|
||||
type
|
||||
|
||||
{ TCustomRxDBTrackBar }
|
||||
|
||||
TCustomRxDBTrackBar = class(TCustomTrackBar)
|
||||
private
|
||||
FDataLink: TFieldDataLink;
|
||||
FInScrollEvent:boolean;
|
||||
function GetDataField: string;
|
||||
function GetDataSource: TDataSource;
|
||||
function GetField: TField;
|
||||
procedure SetDataField(const AValue: string);
|
||||
procedure SetDataSource(const AValue: TDataSource);
|
||||
procedure DataChange(Sender: TObject);
|
||||
procedure ActiveChange(Sender: TObject);
|
||||
procedure LayoutChange(Sender: TObject);
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS;
|
||||
procedure WMKillFocus(var Message: TLMKillFocus); message LM_KILLFOCUS;
|
||||
function GetReadOnly: Boolean;
|
||||
procedure SetReadOnly(const AValue: Boolean);
|
||||
function IsReadOnly: boolean;
|
||||
procedure UpdateData(Sender: TObject);
|
||||
protected
|
||||
property DataField: string read GetDataField write SetDataField;
|
||||
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
|
||||
procedure DoChange(var msg); message LM_CHANGED;
|
||||
// procedure Change; override;
|
||||
procedure Loaded; override;
|
||||
procedure Notification(AComponent: TComponent;
|
||||
Operation: TOperation); override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
property Field: TField read GetField;
|
||||
end;
|
||||
|
||||
TRxDBTrackBar = class(TCustomRxDBTrackBar)
|
||||
published
|
||||
property DataField;
|
||||
property DataSource;
|
||||
property ReadOnly;
|
||||
|
||||
property Align;
|
||||
property Anchors;
|
||||
property BorderSpacing;
|
||||
property Constraints;
|
||||
property DragCursor;
|
||||
property DragMode;
|
||||
property Enabled;
|
||||
property Frequency;
|
||||
property Hint;
|
||||
property LineSize;
|
||||
property Max;
|
||||
property Min;
|
||||
property OnChange;
|
||||
property OnChangeBounds;
|
||||
property OnClick;
|
||||
property OnContextPopup;
|
||||
property OnDragDrop;
|
||||
property OnDragOver;
|
||||
property OnEndDrag;
|
||||
property OnEnter;
|
||||
property OnExit;
|
||||
property OnMouseDown;
|
||||
property OnMouseEnter;
|
||||
property OnMouseLeave;
|
||||
property OnMouseMove;
|
||||
property OnMouseUp;
|
||||
property OnMouseWheel;
|
||||
property OnMouseWheelDown;
|
||||
property OnMouseWheelUp;
|
||||
property OnKeyDown;
|
||||
property OnKeyPress;
|
||||
property OnKeyUp;
|
||||
property OnResize;
|
||||
property OnStartDrag;
|
||||
property OnUTF8KeyPress;
|
||||
property Orientation;
|
||||
property PageSize;
|
||||
property ParentShowHint;
|
||||
property PopupMenu;
|
||||
property ScalePos;
|
||||
property ShowHint;
|
||||
property TabOrder;
|
||||
property TabStop;
|
||||
property TickMarks;
|
||||
property TickStyle;
|
||||
property Visible;
|
||||
end;
|
||||
|
||||
type
|
||||
|
||||
{ TRxDBRadioGroup }
|
||||
|
||||
TRxDBRadioGroup = class(TDBRadioGroup)
|
||||
private
|
||||
function GetItemEnabled(Index: integer): boolean;
|
||||
procedure SetItemEnabled(Index: integer; AValue: boolean);
|
||||
public
|
||||
property ItemEnabled[Index: integer]: boolean read GetItemEnabled write SetItemEnabled;
|
||||
published
|
||||
property AutoSize;
|
||||
end;
|
||||
|
||||
implementation
|
||||
uses rxdbutils, LCLVersion, rxlclutils, StdCtrls;
|
||||
|
||||
{ TRxDBRadioGroup }
|
||||
|
||||
function TRxDBRadioGroup.GetItemEnabled(Index: integer): boolean;
|
||||
var
|
||||
R:TRadioButton;
|
||||
begin
|
||||
if (Index < -1) or (Index >= Items.Count) then
|
||||
RaiseIndexOutOfBounds(Self, Items, Index);
|
||||
R:=FindComponent('RadioButton'+IntToStr(Index)) as TRadioButton;
|
||||
if Assigned(R) then
|
||||
Result:=R.Enabled
|
||||
else
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
procedure TRxDBRadioGroup.SetItemEnabled(Index: integer; AValue: boolean);
|
||||
var
|
||||
R:TRadioButton;
|
||||
begin
|
||||
if (Index < -1) or (Index >= Items.Count) then
|
||||
RaiseIndexOutOfBounds(Self, Items, Index);
|
||||
R:=FindComponent('RadioButton'+IntToStr(Index)) as TRadioButton;
|
||||
if Assigned(R) then
|
||||
R.Enabled:=AValue;
|
||||
end;
|
||||
|
||||
{ TCustomRxDBProgressBar }
|
||||
|
||||
function TCustomRxDBProgressBar.GetDataField: string;
|
||||
begin
|
||||
Result := FDataLink.FieldName;
|
||||
end;
|
||||
|
||||
function TCustomRxDBProgressBar.GetDataSource: TDataSource;
|
||||
begin
|
||||
Result := FDataLink.DataSource;
|
||||
end;
|
||||
|
||||
function TCustomRxDBProgressBar.GetField: TField;
|
||||
begin
|
||||
Result := FDataLink.Field;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBProgressBar.ActiveChange(Sender: TObject);
|
||||
begin
|
||||
if FDatalink.Active then
|
||||
DataChange(Sender)
|
||||
else
|
||||
begin
|
||||
Text := '';
|
||||
FDataLink.Reset;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBProgressBar.LayoutChange(Sender: TObject);
|
||||
begin
|
||||
DataChange(Sender);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBProgressBar.CMGetDataLink(var Message: TLMessage);
|
||||
begin
|
||||
Message.Result := PtrUInt(FDataLink);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBProgressBar.SetDataField(const AValue: string);
|
||||
begin
|
||||
FDataLink.FieldName := AValue;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBProgressBar.SetDataSource(const AValue: TDataSource);
|
||||
begin
|
||||
ChangeDataSource(Self,FDataLink,AValue);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBProgressBar.DataChange(Sender: TObject);
|
||||
begin
|
||||
if Assigned(FDataLink.Field) and (FDataLink.Field.DataType in IntegerDataTypes) then
|
||||
Self.Position:=FDatalink.Field.AsInteger
|
||||
else
|
||||
Position:=Min
|
||||
end;
|
||||
|
||||
constructor TCustomRxDBProgressBar.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FDataLink := TFieldDataLink.Create;
|
||||
FDataLink.Control := Self;
|
||||
FDataLink.OnDataChange := @DataChange;
|
||||
FDataLink.OnActiveChange := @ActiveChange;
|
||||
{$if (lcl_major = 0) and (lcl_release <= 30)}
|
||||
FDataLink.OnLayoutChange := @LayoutChange;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
destructor TCustomRxDBProgressBar.Destroy;
|
||||
begin
|
||||
FreeAndNil(FDataLink);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{ TCustomRxDBTrackBar }
|
||||
|
||||
function TCustomRxDBTrackBar.GetDataField: string;
|
||||
begin
|
||||
Result := FDataLink.FieldName;
|
||||
end;
|
||||
|
||||
function TCustomRxDBTrackBar.GetDataSource: TDataSource;
|
||||
begin
|
||||
Result := FDataLink.DataSource;
|
||||
end;
|
||||
|
||||
function TCustomRxDBTrackBar.GetField: TField;
|
||||
begin
|
||||
Result := FDataLink.Field;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTrackBar.SetDataField(const AValue: string);
|
||||
begin
|
||||
FDataLink.FieldName := AValue;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTrackBar.SetDataSource(const AValue: TDataSource);
|
||||
begin
|
||||
ChangeDataSource(Self,FDataLink,AValue);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTrackBar.DataChange(Sender: TObject);
|
||||
begin
|
||||
FInScrollEvent:=true;
|
||||
if Assigned(FDataLink.Field) and (FDataLink.Field.DataType in IntegerDataTypes) then
|
||||
Self.Position:=FDatalink.Field.AsInteger
|
||||
else
|
||||
Self.Position:=0;
|
||||
FInScrollEvent:=false;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTrackBar.ActiveChange(Sender: TObject);
|
||||
begin
|
||||
if FDatalink.Active then
|
||||
DataChange(Sender)
|
||||
else
|
||||
begin
|
||||
Position:=0;
|
||||
FDataLink.Reset;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTrackBar.LayoutChange(Sender: TObject);
|
||||
begin
|
||||
DataChange(Sender);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTrackBar.CMGetDataLink(var Message: TLMessage);
|
||||
begin
|
||||
Message.Result := PtrUInt(FDataLink);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTrackBar.WMSetFocus(var Message: TLMSetFocus);
|
||||
begin
|
||||
inherited WMSetFocus(Message);
|
||||
if not FDatalink.Editing then
|
||||
FDatalink.Reset;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTrackBar.WMKillFocus(var Message: TLMKillFocus);
|
||||
begin
|
||||
inherited WMKillFocus(Message);
|
||||
if not FDatalink.Editing then
|
||||
FDatalink.Reset
|
||||
else
|
||||
FDatalink.UpdateRecord;
|
||||
end;
|
||||
|
||||
function TCustomRxDBTrackBar.GetReadOnly: Boolean;
|
||||
begin
|
||||
Result := FDataLink.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTrackBar.SetReadOnly(const AValue: Boolean);
|
||||
begin
|
||||
inherited;
|
||||
FDataLink.ReadOnly := AValue;
|
||||
end;
|
||||
|
||||
function TCustomRxDBTrackBar.IsReadOnly: boolean;
|
||||
begin
|
||||
result := true;
|
||||
if FDatalink.Active and not Self.ReadOnly then
|
||||
result := (Field=nil) or Field.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTrackBar.UpdateData(Sender: TObject);
|
||||
begin
|
||||
if Assigned(FDataLink.Field) and (FDataLink.Field.DataType in IntegerDataTypes) then
|
||||
FDataLink.Field.AsInteger := Self.Position;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTrackBar.DoChange(var msg);
|
||||
begin
|
||||
inherited DoChange(Msg);
|
||||
if not FInScrollEvent then
|
||||
begin
|
||||
FDatalink.Edit;
|
||||
FDataLink.Modified;
|
||||
end;
|
||||
end;
|
||||
|
||||
{
|
||||
procedure TCustomRxDBTrackBar.Change;
|
||||
begin
|
||||
FDatalink.Edit;
|
||||
FDataLink.Modified;
|
||||
inherited Change;
|
||||
end;
|
||||
}
|
||||
procedure TCustomRxDBTrackBar.Loaded;
|
||||
begin
|
||||
inherited Loaded;
|
||||
if (csDesigning in ComponentState) then
|
||||
DataChange(Self);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTrackBar.Notification(AComponent: TComponent;
|
||||
Operation: TOperation);
|
||||
begin
|
||||
inherited Notification(AComponent, Operation);
|
||||
if (Operation=opRemove) then
|
||||
begin
|
||||
if (FDataLink<>nil) and (AComponent=DataSource) then
|
||||
DataSource:=nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TCustomRxDBTrackBar.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FInScrollEvent:=false;
|
||||
FDataLink := TFieldDataLink.Create;
|
||||
FDataLink.Control := Self;
|
||||
FDataLink.OnDataChange := @DataChange;
|
||||
FDataLink.OnUpdateData := @UpdateData;
|
||||
FDataLink.OnActiveChange := @ActiveChange;
|
||||
{$if (lcl_major = 0) and (lcl_release <= 30)}
|
||||
FDataLink.OnLayoutChange := @LayoutChange;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
destructor TCustomRxDBTrackBar.Destroy;
|
||||
begin
|
||||
FreeAndNil(FDataLink);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
256
RXLib/rxdb/rxdbcurredit.pas
Normal file
256
RXLib/rxdb/rxdbcurredit.pas
Normal file
@@ -0,0 +1,256 @@
|
||||
{ dbcurredit unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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 rxdbcurredit;
|
||||
|
||||
{$I rx.inc}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, LMessages, LCLType, Controls, Graphics,
|
||||
DB, DbCtrls, rxcurredit ;
|
||||
|
||||
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);
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
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.CMGetDataLink(var Message: TLMessage);
|
||||
begin
|
||||
Message.Result := PtrUInt(FDataLink);
|
||||
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.
|
||||
|
490
RXLib/rxdb/rxdbdateedit.pas
Normal file
490
RXLib/rxdb/rxdbdateedit.pas
Normal file
@@ -0,0 +1,490 @@
|
||||
{ dbdateedit unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit rxdbdateedit;
|
||||
|
||||
{$I rx.inc}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, LMessages, LCLType, Controls, Graphics,
|
||||
DB, DbCtrls, EditBtn, rxtooledit;
|
||||
|
||||
type
|
||||
|
||||
{ TRxDBDateEdit }
|
||||
TRxDBDateEdit = class(TRxDateEdit)
|
||||
private
|
||||
FDataLink:TFieldDataLink;
|
||||
FDefaultToday: Boolean;
|
||||
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);
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
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 ButtonClick; override;
|
||||
procedure EditChange; override;
|
||||
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||
procedure EditingDone; override;
|
||||
Procedure RunDialog; virtual;
|
||||
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;
|
||||
property DefaultToday: Boolean read FDefaultToday write FDefaultToday
|
||||
default False;
|
||||
end;
|
||||
|
||||
|
||||
{ TRxDBCalcEdit }
|
||||
|
||||
TRxDBCalcEdit = class(TCalcEdit)
|
||||
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);
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
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 EditChange; override;
|
||||
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||
procedure EditingDone; override;
|
||||
Procedure RunDialog; 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 rxdateutil;
|
||||
|
||||
{ TRxDBDateEdit }
|
||||
|
||||
procedure TRxDBDateEdit.DoCheckEnable;
|
||||
begin
|
||||
Enabled:=FDataLink.Active and (FDataLink.Field<>nil) and (not FDataLink.Field.ReadOnly);
|
||||
end;
|
||||
|
||||
function TRxDBDateEdit.GetDataField: string;
|
||||
begin
|
||||
Result:=FDataLink.FieldName;
|
||||
end;
|
||||
|
||||
function TRxDBDateEdit.GetDataSource: TDataSource;
|
||||
begin
|
||||
Result:=FDataLink.DataSource;
|
||||
end;
|
||||
|
||||
function TRxDBDateEdit.GetReadOnly: Boolean;
|
||||
begin
|
||||
Result:=FDataLink.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.SetDataField(const AValue: string);
|
||||
begin
|
||||
try
|
||||
FDataLink.FieldName:=AValue;
|
||||
finally
|
||||
DoCheckEnable;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.SetDataSource(const AValue: TDataSource);
|
||||
begin
|
||||
FDataLink.DataSource:=AValue;
|
||||
DoCheckEnable;
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.SetReadOnly(const AValue: Boolean);
|
||||
begin
|
||||
inherited ReadOnly:=AValue;
|
||||
FDataLink.ReadOnly:=AValue;
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.CMGetDataLink(var Message: TLMessage);
|
||||
begin
|
||||
Message.Result := PtrUInt(FDataLink);
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.CMExit(var Message: TLMessage);
|
||||
begin
|
||||
try
|
||||
FDataLink.UpdateRecord;
|
||||
except
|
||||
SetFocus;
|
||||
SelectAll;
|
||||
raise;
|
||||
end;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.LMCut(var Message: TLMessage);
|
||||
begin
|
||||
FDataLink.Edit;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.LMPaste(var Message: TLMessage);
|
||||
begin
|
||||
FDataLink.Edit;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.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 TRxDBDateEdit.EditChange;
|
||||
begin
|
||||
if Assigned(FDataLink) then
|
||||
FDataLink.Modified;
|
||||
inherited EditChange;
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.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 TRxDBDateEdit.EditingDone;
|
||||
begin
|
||||
inherited EditingDone;
|
||||
if FDataLink.CanModify then
|
||||
FDataLink.UpdateRecord;
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.RunDialog;
|
||||
begin
|
||||
if FDataLink.CanModify then
|
||||
FDataLink.UpdateRecord;
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.ButtonClick;
|
||||
begin
|
||||
inherited ButtonClick;
|
||||
RunDialog;
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.ActiveChange(Sender: TObject);
|
||||
begin
|
||||
DoCheckEnable;
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.DataChange(Sender: TObject);
|
||||
begin
|
||||
if Assigned(FDataLink.Field) and
|
||||
(FDataLink.Field is TDateTimeField) then
|
||||
begin
|
||||
if FDataLink.Field.IsNull then
|
||||
Text:=''
|
||||
else
|
||||
Date:=FDataLink.Field.AsDateTime
|
||||
end
|
||||
else Text:='';
|
||||
end;
|
||||
|
||||
procedure TRxDBDateEdit.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 TRxDBDateEdit.UpdateData(Sender: TObject);
|
||||
var
|
||||
D: TDateTime;
|
||||
begin
|
||||
if Assigned(FDataLink.Field) then
|
||||
begin
|
||||
D := Self.Date;
|
||||
if (D <> NullDate) then
|
||||
FDataLink.Field.AsDateTime := D + Frac(FDataLink.Field.AsDateTime)
|
||||
else
|
||||
FDataLink.Field.Clear;
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TRxDBDateEdit.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FDataLink:=TFieldDataLink.Create;
|
||||
FDataLink.Control:=Self;
|
||||
FDataLink.OnActiveChange:=@ActiveChange;
|
||||
FDataLink.OnDataChange:=@DataChange;
|
||||
FDataLink.OnUpdateData:=@UpdateData;
|
||||
Text:='';
|
||||
//UpdateMask;
|
||||
end;
|
||||
|
||||
destructor TRxDBDateEdit.Destroy;
|
||||
begin
|
||||
FreeAndNil(FDataLink);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
|
||||
{ TRxDBCalcEdit }
|
||||
|
||||
procedure TRxDBCalcEdit.DoCheckEnable;
|
||||
begin
|
||||
Enabled:=FDataLink.Active and (FDataLink.Field<>nil) and (not FDataLink.Field.ReadOnly);
|
||||
end;
|
||||
|
||||
function TRxDBCalcEdit.GetDataField: string;
|
||||
begin
|
||||
Result:=FDataLink.FieldName;
|
||||
end;
|
||||
|
||||
function TRxDBCalcEdit.GetDataSource: TDataSource;
|
||||
begin
|
||||
Result:=FDataLink.DataSource;
|
||||
end;
|
||||
|
||||
function TRxDBCalcEdit.GetReadOnly: Boolean;
|
||||
begin
|
||||
Result:=FDataLink.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.SetDataField(const AValue: string);
|
||||
begin
|
||||
try
|
||||
FDataLink.FieldName:=AValue;
|
||||
finally
|
||||
DoCheckEnable;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.SetDataSource(const AValue: TDataSource);
|
||||
begin
|
||||
FDataLink.DataSource:=AValue;
|
||||
DoCheckEnable;
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.SetReadOnly(const AValue: Boolean);
|
||||
begin
|
||||
FDataLink.ReadOnly:=AValue;
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.CMGetDataLink(var Message: TLMessage);
|
||||
begin
|
||||
Message.Result := PtrUInt(FDataLink);
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.ActiveChange(Sender: TObject);
|
||||
begin
|
||||
DoCheckEnable;
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.DataChange(Sender: TObject);
|
||||
begin
|
||||
if Assigned(FDataLink.Field) and
|
||||
(FDataLink.Field is TNumericField) then
|
||||
begin
|
||||
if FDataLink.Field.IsNull then
|
||||
Text:=''
|
||||
else
|
||||
Self.AsFloat:=FDataLink.Field.AsFloat;
|
||||
end
|
||||
else Text:='';
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.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 TRxDBCalcEdit.UpdateData(Sender: TObject);
|
||||
begin
|
||||
if Assigned(FDataLink.Field) and FDataLink.Edit then
|
||||
begin
|
||||
if Self.Text<>'' then
|
||||
FDataLink.Field.AsFloat := Self.AsFloat
|
||||
else
|
||||
FDataLink.Field.Clear;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.CMExit(var Message: TLMessage);
|
||||
begin
|
||||
try
|
||||
FDataLink.UpdateRecord;
|
||||
except
|
||||
SetFocus;
|
||||
SelectAll;
|
||||
raise;
|
||||
end;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.LMCut(var Message: TLMessage);
|
||||
begin
|
||||
FDataLink.Edit;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.LMPaste(var Message: TLMessage);
|
||||
begin
|
||||
FDataLink.Edit;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.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 TRxDBCalcEdit.EditChange;
|
||||
begin
|
||||
FDataLink.Modified;
|
||||
inherited EditChange;
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.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 TRxDBCalcEdit.EditingDone;
|
||||
begin
|
||||
inherited EditingDone;
|
||||
if FDataLink.CanModify then
|
||||
FDataLink.UpdateRecord;
|
||||
end;
|
||||
|
||||
procedure TRxDBCalcEdit.RunDialog;
|
||||
begin
|
||||
inherited RunDialog;
|
||||
if FDataLink.CanModify then
|
||||
FDataLink.UpdateRecord;
|
||||
end;
|
||||
|
||||
constructor TRxDBCalcEdit.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FDataLink:=TFieldDataLink.Create;
|
||||
FDataLink.Control:=Self;
|
||||
FDataLink.OnActiveChange:=@ActiveChange;
|
||||
FDataLink.OnDataChange:=@DataChange;
|
||||
FDataLink.OnUpdateData:=@UpdateData;
|
||||
end;
|
||||
|
||||
destructor TRxDBCalcEdit.Destroy;
|
||||
begin
|
||||
FreeAndNil(FDataLink);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
end.
|
7806
RXLib/rxdb/rxdbgrid.pas
Normal file
7806
RXLib/rxdb/rxdbgrid.pas
Normal file
File diff suppressed because it is too large
Load Diff
214
RXLib/rxdb/rxdbgrid_columsunit.lfm
Normal file
214
RXLib/rxdb/rxdbgrid_columsunit.lfm
Normal file
@@ -0,0 +1,214 @@
|
||||
object rxDBGridColumsForm: TrxDBGridColumsForm
|
||||
Left = 489
|
||||
Height = 505
|
||||
Top = 248
|
||||
Width = 481
|
||||
Caption = 'Grid colums'
|
||||
ClientHeight = 505
|
||||
ClientWidth = 481
|
||||
OnCreate = FormCreate
|
||||
Position = poScreenCenter
|
||||
ShowHint = True
|
||||
LCLVersion = '1.3'
|
||||
object ButtonPanel1: TButtonPanel
|
||||
Left = 6
|
||||
Height = 41
|
||||
Top = 458
|
||||
Width = 469
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
HelpButton.Name = 'HelpButton'
|
||||
HelpButton.DefaultCaption = True
|
||||
CloseButton.Name = 'CloseButton'
|
||||
CloseButton.DefaultCaption = True
|
||||
CancelButton.Name = 'CancelButton'
|
||||
CancelButton.DefaultCaption = True
|
||||
TabOrder = 0
|
||||
ShowButtons = [pbOK, pbCancel, pbHelp]
|
||||
object sbDown: TSpeedButton
|
||||
AnchorSideLeft.Control = sbUp
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = sbUp
|
||||
AnchorSideBottom.Control = sbUp
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 516
|
||||
Height = 33
|
||||
Top = 0
|
||||
Width = 23
|
||||
Anchors = [akTop, akLeft, akBottom]
|
||||
BorderSpacing.Left = 6
|
||||
Glyph.Data = {
|
||||
36040000424D3604000000000000360000002800000010000000100000000100
|
||||
2000000000000004000064000000640000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000FF0000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000FF808000FF0000
|
||||
00FF000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000FF808000FF808000FF8080
|
||||
00FF000000FF0000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000FF808000FF808000FF808000FF8080
|
||||
00FF808000FF000000FF00000000000000000000000000000000000000000000
|
||||
00000000000000000000000000FF808000FF808000FF808000FF808000FF8080
|
||||
00FF808000FF808000FF000000FF000000000000000000000000000000000000
|
||||
000000000000000000FF000000FF000000FF000000FF808000FF808000FF8080
|
||||
00FF000000FF000000FF000000FF000000FF0000000000000000000000000000
|
||||
000000000000000000000000000000000000000000FF808000FF808000FF8080
|
||||
00FF000000FF0000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000FF808000FF808000FF8080
|
||||
00FF000000FF0000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000FF808000FF808000FF8080
|
||||
00FF000000FF0000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000FF000000FF000000FF0000
|
||||
00FF000000FF0000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000
|
||||
}
|
||||
OnClick = sbDownClick
|
||||
end
|
||||
object sbUp: TSpeedButton
|
||||
AnchorSideLeft.Control = ButtonPanel1
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = ButtonPanel1
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 487
|
||||
Height = 33
|
||||
Top = 0
|
||||
Width = 23
|
||||
Anchors = [akTop, akLeft, akBottom]
|
||||
BorderSpacing.Left = 18
|
||||
Glyph.Data = {
|
||||
36040000424D3604000000000000360000002800000010000000100000000100
|
||||
2000000000000004000064000000640000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000FF000000FF000000FF0000
|
||||
00FF000000FF0000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000FF808000FF808000FF8080
|
||||
00FF000000FF0000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000FF808000FF808000FF8080
|
||||
00FF000000FF0000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000FF808000FF808000FF8080
|
||||
00FF000000FF0000000000000000000000000000000000000000000000000000
|
||||
000000000000000000FF000000FF000000FF000000FF808000FF808000FF8080
|
||||
00FF000000FF000000FF000000FF000000FF0000000000000000000000000000
|
||||
00000000000000000000000000FF808000FF808000FF808000FF808000FF8080
|
||||
00FF808000FF808000FF000000FF000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000FF808000FF808000FF808000FF8080
|
||||
00FF808000FF000000FF00000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000FF808000FF808000FF8080
|
||||
00FF000000FF0000000000000000000000000000000000000000000000000000
|
||||
00000000000000000000000000000000000000000000000000FF808000FF0000
|
||||
00FF000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000FF0000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000
|
||||
}
|
||||
OnClick = sbUpClick
|
||||
end
|
||||
object btnApply: TBitBtn
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = -205
|
||||
Height = 30
|
||||
Top = 0
|
||||
Width = 71
|
||||
Anchors = [akTop, akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Right = 6
|
||||
Caption = 'btnApply'
|
||||
OnClick = btnApplyClick
|
||||
TabOrder = 4
|
||||
end
|
||||
end
|
||||
object StringGrid1: TStringGrid
|
||||
Left = 6
|
||||
Height = 446
|
||||
Top = 6
|
||||
Width = 469
|
||||
Align = alClient
|
||||
AlternateColor = clCream
|
||||
AutoFillColumns = True
|
||||
BorderSpacing.Around = 6
|
||||
ColCount = 3
|
||||
Columns = <
|
||||
item
|
||||
ButtonStyle = cbsCheckboxColumn
|
||||
SizePriority = 0
|
||||
Title.Alignment = taCenter
|
||||
Title.Caption = '...'
|
||||
Width = 30
|
||||
end
|
||||
item
|
||||
ButtonStyle = cbsNone
|
||||
ReadOnly = True
|
||||
Title.Caption = 'Caption'
|
||||
Width = 377
|
||||
end
|
||||
item
|
||||
Alignment = taRightJustify
|
||||
SizePriority = 0
|
||||
Title.Alignment = taCenter
|
||||
Title.Caption = 'Width'
|
||||
Width = 60
|
||||
end>
|
||||
FixedCols = 0
|
||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goEditing, goRowSelect, goRowHighlight]
|
||||
TabOrder = 1
|
||||
TitleStyle = tsNative
|
||||
OnClick = StringGrid1Click
|
||||
OnValidateEntry = StringGrid1ValidateEntry
|
||||
ColWidths = (
|
||||
30
|
||||
377
|
||||
60
|
||||
)
|
||||
Cells = (
|
||||
9
|
||||
0
|
||||
2
|
||||
'1'
|
||||
0
|
||||
4
|
||||
'1'
|
||||
1
|
||||
1
|
||||
'1'
|
||||
1
|
||||
2
|
||||
'2'
|
||||
1
|
||||
3
|
||||
'3'
|
||||
1
|
||||
4
|
||||
'4'
|
||||
2
|
||||
2
|
||||
'11'
|
||||
2
|
||||
3
|
||||
'11'
|
||||
2
|
||||
4
|
||||
'11'
|
||||
)
|
||||
end
|
||||
end
|
230
RXLib/rxdb/rxdbgrid_columsunit.pas
Normal file
230
RXLib/rxdb/rxdbgrid_columsunit.pas
Normal file
@@ -0,0 +1,230 @@
|
||||
{ rxdbgrid_columsunit unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit rxdbgrid_columsunit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, CheckLst,
|
||||
StdCtrls, Buttons, ButtonPanel, Grids, rxdbgrid;
|
||||
|
||||
type
|
||||
|
||||
{ TrxDBGridColumsForm }
|
||||
|
||||
TrxDBGridColumsForm = class(TForm)
|
||||
btnApply: TBitBtn;
|
||||
ButtonPanel1: TButtonPanel;
|
||||
sbUp: TSpeedButton;
|
||||
sbDown: TSpeedButton;
|
||||
StringGrid1: TStringGrid;
|
||||
procedure btnApplyClick(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure sbUpClick(Sender: TObject);
|
||||
procedure sbDownClick(Sender: TObject);
|
||||
procedure StringGrid1Click(Sender: TObject);
|
||||
procedure StringGrid1ValidateEntry(sender: TObject; aCol, aRow: Integer;
|
||||
const OldValue: string; var NewValue: String);
|
||||
private
|
||||
FGrid:TRxDBGrid;
|
||||
procedure SetGrid(AGrid:TRxDBGrid);
|
||||
procedure SetGridColumnsParams;
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
|
||||
procedure ShowRxDBGridColumsForm(Grid:TRxDBGrid);
|
||||
implementation
|
||||
uses rxdconst, math;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
procedure ShowRxDBGridColumsForm(Grid: TRxDBGrid);
|
||||
var
|
||||
rxDBGridColumsForm: TrxDBGridColumsForm;
|
||||
begin
|
||||
rxDBGridColumsForm:=TrxDBGridColumsForm.Create(Application);
|
||||
rxDBGridColumsForm.SetGrid(Grid);
|
||||
if rxDBGridColumsForm.ShowModal = mrOk then
|
||||
begin
|
||||
if Assigned(Grid) then
|
||||
rxDBGridColumsForm.SetGridColumnsParams;
|
||||
end;
|
||||
rxDBGridColumsForm.Free;
|
||||
end;
|
||||
|
||||
{ TrxDBGridColumsForm }
|
||||
|
||||
procedure TrxDBGridColumsForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
sbUp.AnchorSideLeft.Control:=ButtonPanel1.HelpButton;
|
||||
sbUp.AnchorSideTop.Control:=ButtonPanel1.HelpButton;
|
||||
sbUp.AnchorSideBottom.Control:=ButtonPanel1.HelpButton;
|
||||
|
||||
btnApply.AnchorSideTop.Control:=ButtonPanel1.OKButton;
|
||||
btnApply.AnchorSideBottom.Control:=ButtonPanel1.OKButton;
|
||||
|
||||
{$IFDEF UNIX}
|
||||
btnApply.AnchorSideRight.Control:=ButtonPanel1.CancelButton;
|
||||
{$ELSE}
|
||||
btnApply.AnchorSideRight.Control:=ButtonPanel1.OKButton;
|
||||
{$ENDIF}
|
||||
|
||||
Caption:=sRxDbGridSelColCaption;
|
||||
sbUp.Hint:=sRxDbGridSelColHint1;
|
||||
sbDown.Hint:=sRxDbGridSelColHint2;
|
||||
|
||||
btnApply.Caption:=sRxDbGridSelApplyCaption;
|
||||
btnApply.Hint:=sRxDbGridSelApplyHint;
|
||||
end;
|
||||
|
||||
procedure TrxDBGridColumsForm.btnApplyClick(Sender: TObject);
|
||||
begin
|
||||
SetGridColumnsParams;
|
||||
end;
|
||||
|
||||
procedure TrxDBGridColumsForm.sbUpClick(Sender: TObject);
|
||||
var
|
||||
S, W, C:string;
|
||||
begin
|
||||
if (StringGrid1.RowCount > 1) and (StringGrid1.Row > 1) then
|
||||
begin
|
||||
C:=StringGrid1.Cells[0, StringGrid1.Row-1];
|
||||
S:=StringGrid1.Cells[1, StringGrid1.Row-1];
|
||||
W:=StringGrid1.Cells[2, StringGrid1.Row-1];
|
||||
|
||||
StringGrid1.Cells[0, StringGrid1.Row-1]:=StringGrid1.Cells[0, StringGrid1.Row];
|
||||
StringGrid1.Cells[1, StringGrid1.Row-1]:=StringGrid1.Cells[1, StringGrid1.Row];
|
||||
StringGrid1.Cells[2, StringGrid1.Row-1]:=StringGrid1.Cells[2, StringGrid1.Row];
|
||||
|
||||
StringGrid1.Cells[0, StringGrid1.Row]:=C;
|
||||
StringGrid1.Cells[1, StringGrid1.Row]:=S;
|
||||
StringGrid1.Cells[2, StringGrid1.Row]:=W;
|
||||
|
||||
StringGrid1.Row:=StringGrid1.Row-1;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TrxDBGridColumsForm.sbDownClick(Sender: TObject);
|
||||
var
|
||||
S, W, C:string;
|
||||
i:integer;
|
||||
begin
|
||||
if (StringGrid1.RowCount > 1) and (StringGrid1.Row < StringGrid1.RowCount - 1) then
|
||||
begin
|
||||
C:=StringGrid1.Cells[0, StringGrid1.Row+1];
|
||||
S:=StringGrid1.Cells[1, StringGrid1.Row+1];
|
||||
W:=StringGrid1.Cells[2, StringGrid1.Row+1];
|
||||
|
||||
StringGrid1.Cells[0, StringGrid1.Row+1]:=StringGrid1.Cells[0, StringGrid1.Row];
|
||||
StringGrid1.Cells[1, StringGrid1.Row+1]:=StringGrid1.Cells[1, StringGrid1.Row];
|
||||
StringGrid1.Cells[2, StringGrid1.Row+1]:=StringGrid1.Cells[2, StringGrid1.Row];
|
||||
|
||||
StringGrid1.Cells[0, StringGrid1.Row]:=C;
|
||||
StringGrid1.Cells[1, StringGrid1.Row]:=S;
|
||||
StringGrid1.Cells[2, StringGrid1.Row]:=W;
|
||||
|
||||
StringGrid1.Row:=StringGrid1.Row+1;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TrxDBGridColumsForm.StringGrid1Click(Sender: TObject);
|
||||
var
|
||||
i:integer;
|
||||
C:TRxColumn;
|
||||
begin
|
||||
i:=StringGrid1.Row;
|
||||
|
||||
C:=FGrid.ColumnByCaption(StringGrid1.Cells[1, i]);
|
||||
if coCustomizeVisible in C.Options then
|
||||
StringGrid1.Options:=StringGrid1.Options + [goEditing]
|
||||
else
|
||||
StringGrid1.Options:=StringGrid1.Options - [goEditing]
|
||||
;
|
||||
end;
|
||||
|
||||
procedure TrxDBGridColumsForm.StringGrid1ValidateEntry(sender: TObject; aCol,
|
||||
aRow: Integer; const OldValue: string; var NewValue: String);
|
||||
begin
|
||||
if aCol = 2 then
|
||||
NewValue:=IntToStr(Max(StrToIntDef(NewValue, StrToIntDef(OldValue, 0)), 0));
|
||||
end;
|
||||
|
||||
procedure TrxDBGridColumsForm.SetGrid(AGrid: TRxDBGrid);
|
||||
var
|
||||
i:integer;
|
||||
C:TRxColumn;
|
||||
begin
|
||||
if AGrid=FGrid then exit;
|
||||
FGrid:=AGrid;
|
||||
if Assigned(AGrid) then
|
||||
begin
|
||||
StringGrid1.RowCount:=AGrid.Columns.Count + 1;
|
||||
|
||||
for i:=0 to AGrid.Columns.Count-1 do
|
||||
begin
|
||||
C:=AGrid.Columns[i] as TRxColumn;
|
||||
|
||||
StringGrid1.Cells[0, i + 1]:=BoolToStr(C.Visible, '1', '0');
|
||||
StringGrid1.Cells[1, i + 1]:=C.Title.Caption;
|
||||
if C.Width = 0 then
|
||||
StringGrid1.Cells[2, i + 1]:=IntToStr(AGrid.DefaultColWidth)
|
||||
else
|
||||
StringGrid1.Cells[2, i + 1]:=IntToStr(C.Width);
|
||||
end;
|
||||
end
|
||||
else
|
||||
StringGrid1.RowCount:=1;
|
||||
end;
|
||||
|
||||
procedure TrxDBGridColumsForm.SetGridColumnsParams;
|
||||
var
|
||||
i:integer;
|
||||
Col:TRxColumn;
|
||||
begin
|
||||
for i:=1 to StringGrid1.RowCount-1 do
|
||||
begin
|
||||
Col:=FGrid.ColumnByCaption(StringGrid1.Cells[1, i]);
|
||||
if Assigned(Col) then
|
||||
begin
|
||||
Col.Visible:=StringGrid1.Cells[0, i] = '1';
|
||||
Col.Index:=i-1;
|
||||
Col.Width:=StrToIntDef(StringGrid1.Cells[2, i], 65);
|
||||
end
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
185
RXLib/rxdb/rxdbgrid_findunit.lfm
Normal file
185
RXLib/rxdb/rxdbgrid_findunit.lfm
Normal file
@@ -0,0 +1,185 @@
|
||||
object rxDBGridFindForm: TrxDBGridFindForm
|
||||
Left = 688
|
||||
Height = 260
|
||||
Top = 327
|
||||
Width = 493
|
||||
ActiveControl = Edit1
|
||||
Caption = 'Find'
|
||||
ClientHeight = 260
|
||||
ClientWidth = 493
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '1.5'
|
||||
object Label1: TLabel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Owner
|
||||
AnchorSideBottom.Control = Edit1
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 21
|
||||
Top = 6
|
||||
Width = 75
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Text to find'
|
||||
FocusControl = Edit1
|
||||
ParentColor = False
|
||||
end
|
||||
object Label2: TLabel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Edit1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideBottom.Control = ComboBox1
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 21
|
||||
Top = 70
|
||||
Width = 75
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Find at filed'
|
||||
ParentColor = False
|
||||
end
|
||||
object BtnFind: TButton
|
||||
AnchorSideRight.Control = Button2
|
||||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 340
|
||||
Height = 41
|
||||
Top = 213
|
||||
Width = 84
|
||||
Anchors = [akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
BorderSpacing.InnerBorder = 4
|
||||
Caption = 'Find more'
|
||||
Default = True
|
||||
OnClick = BtnFindClick
|
||||
TabOrder = 2
|
||||
end
|
||||
object Button2: TButton
|
||||
AnchorSideTop.Control = BtnFind
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 430
|
||||
Height = 41
|
||||
Top = 213
|
||||
Width = 57
|
||||
Anchors = [akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Top = 8
|
||||
BorderSpacing.Around = 6
|
||||
BorderSpacing.InnerBorder = 4
|
||||
Cancel = True
|
||||
Caption = 'Close'
|
||||
OnClick = Button2Click
|
||||
TabOrder = 3
|
||||
end
|
||||
object Edit1: TEdit
|
||||
AnchorSideLeft.Control = ComboBox1
|
||||
AnchorSideTop.Control = Label1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 18
|
||||
Height = 31
|
||||
Top = 33
|
||||
Width = 469
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
TabOrder = 0
|
||||
end
|
||||
object ComboBox1: TComboBox
|
||||
AnchorSideLeft.Control = Label2
|
||||
AnchorSideTop.Control = Label2
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 12
|
||||
Height = 35
|
||||
Top = 97
|
||||
Width = 475
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
Style = csDropDownList
|
||||
TabOrder = 1
|
||||
end
|
||||
object RadioGroup1: TRadioGroup
|
||||
AnchorSideLeft.Control = Panel1
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = ComboBox1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = Panel1
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 148
|
||||
Height = 70
|
||||
Top = 138
|
||||
Width = 339
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
AutoFill = True
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Right = 6
|
||||
Caption = 'Direction'
|
||||
ChildSizing.LeftRightSpacing = 6
|
||||
ChildSizing.TopBottomSpacing = 6
|
||||
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
|
||||
ChildSizing.EnlargeVertical = crsHomogenousChildResize
|
||||
ChildSizing.ShrinkHorizontal = crsScaleChilds
|
||||
ChildSizing.ShrinkVertical = crsScaleChilds
|
||||
ChildSizing.Layout = cclLeftToRightThenTopToBottom
|
||||
ChildSizing.ControlsPerLine = 3
|
||||
ClientHeight = 47
|
||||
ClientWidth = 335
|
||||
Columns = 3
|
||||
Items.Strings = (
|
||||
'All'
|
||||
'Forward'
|
||||
'Backward'
|
||||
)
|
||||
TabOrder = 4
|
||||
end
|
||||
object Panel1: TPanel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = ComboBox1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 70
|
||||
Top = 138
|
||||
Width = 136
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
ClientHeight = 70
|
||||
ClientWidth = 136
|
||||
TabOrder = 5
|
||||
object CheckBox2: TCheckBox
|
||||
AnchorSideLeft.Control = Panel1
|
||||
AnchorSideTop.Control = CheckBox1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 7
|
||||
Height = 25
|
||||
Top = 38
|
||||
Width = 92
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Partial key'
|
||||
TabOrder = 0
|
||||
end
|
||||
object CheckBox1: TCheckBox
|
||||
AnchorSideLeft.Control = Panel1
|
||||
AnchorSideTop.Control = Panel1
|
||||
Left = 7
|
||||
Height = 25
|
||||
Top = 7
|
||||
Width = 122
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Case sensetive'
|
||||
TabOrder = 1
|
||||
end
|
||||
end
|
||||
end
|
193
RXLib/rxdb/rxdbgrid_findunit.pas
Normal file
193
RXLib/rxdb/rxdbgrid_findunit.pas
Normal file
@@ -0,0 +1,193 @@
|
||||
{ rxdbgrid_findunit unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit rxdbgrid_findunit;
|
||||
|
||||
{$I rx.inc}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons,
|
||||
StdCtrls, ExtCtrls, rxdbgrid, DB;
|
||||
|
||||
type
|
||||
|
||||
{ TrxDBGridFindForm }
|
||||
|
||||
TrxDBGridFindForm = class(TForm)
|
||||
BtnFind: TButton;
|
||||
Button2: TButton;
|
||||
CheckBox1: TCheckBox;
|
||||
CheckBox2: TCheckBox;
|
||||
ComboBox1: TComboBox;
|
||||
Edit1: TEdit;
|
||||
Label1: TLabel;
|
||||
Label2: TLabel;
|
||||
Panel1: TPanel;
|
||||
RadioGroup1: TRadioGroup;
|
||||
procedure BtnFindClick(Sender: TObject);
|
||||
procedure Button2Click(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormShow(Sender: TObject);
|
||||
private
|
||||
FGrid:TRxDBGrid;
|
||||
FDataSet:TDataSet;
|
||||
procedure SetGrid(AGrid:TRxDBGrid);
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
procedure ShowRxDBGridFindForm(Grid:TRxDBGrid);
|
||||
|
||||
implementation
|
||||
uses rxdbutils, DBGrids, rxdconst, LCLStrConsts;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
procedure ShowRxDBGridFindForm(Grid: TRxDBGrid);
|
||||
var
|
||||
rxDBGridFindForm: TrxDBGridFindForm;
|
||||
begin
|
||||
rxDBGridFindForm:=TrxDBGridFindForm.Create(Application);
|
||||
rxDBGridFindForm.SetGrid(Grid);
|
||||
rxDBGridFindForm.ShowModal;
|
||||
rxDBGridFindForm.Free;
|
||||
end;
|
||||
|
||||
{ TrxDBGridFindForm }
|
||||
|
||||
procedure TrxDBGridFindForm.Button2Click(Sender: TObject);
|
||||
begin
|
||||
Close;
|
||||
end;
|
||||
|
||||
procedure TrxDBGridFindForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
Caption:=sRxDbGridFindCaption;
|
||||
Label1.Caption:=sRxDbGridFindText;
|
||||
Label2.Caption:=sRxDbGridFindOnField;
|
||||
CheckBox1.Caption:=sRxDbGridFindCaseSens;
|
||||
CheckBox2.Caption:=sRxDbGridFindPartial;
|
||||
RadioGroup1.Caption:=sRxDbGridFindDirecion;
|
||||
RadioGroup1.Items.Clear;
|
||||
RadioGroup1.Items.Add(sRxDbGridFindRangeAll);
|
||||
RadioGroup1.Items.Add(sRxDbGridFindRangeForw);
|
||||
RadioGroup1.Items.Add(sRxDbGridFindRangeBack);
|
||||
BtnFind.Caption:=sRxFindMore;
|
||||
Button2.Caption:=rsMbClose;
|
||||
|
||||
RadioGroup1.ItemIndex:=0;
|
||||
end;
|
||||
|
||||
procedure TrxDBGridFindForm.FormShow(Sender: TObject);
|
||||
begin
|
||||
Edit1.SetFocus;
|
||||
end;
|
||||
|
||||
procedure TrxDBGridFindForm.BtnFindClick(Sender: TObject);
|
||||
var
|
||||
FieldName:string;
|
||||
LOptions: TLocateOptions;
|
||||
SearchOrigin:TRxSearchDirection;
|
||||
P:TBookMark;
|
||||
R:boolean;
|
||||
begin
|
||||
{ TODO -oalexs : Необходимо переделать поиск по колонке - искать всегда по строковому представлению. Иначе не ищет по дате-времени }
|
||||
if Edit1.Text<>'' then
|
||||
begin
|
||||
try
|
||||
|
||||
FieldName:=FGrid.Columns[ComboBox1.ItemIndex].FieldName;
|
||||
LOptions:=[];
|
||||
if not CheckBox1.Checked then
|
||||
LOptions:=LOptions+[loCaseInsensitive];
|
||||
|
||||
if CheckBox2.Checked then
|
||||
LOptions:=LOptions+[loPartialKey];
|
||||
|
||||
SearchOrigin:=TRxSearchDirection(RadioGroup1.ItemIndex);
|
||||
{$IFDEF NoAutomatedBookmark}
|
||||
P:=FDataSet.GetBookmark;
|
||||
{$ELSE}
|
||||
P:=FDataSet.Bookmark;
|
||||
{$ENDIF}
|
||||
if SearchOrigin = rsdForward then
|
||||
FDataSet.Next
|
||||
else
|
||||
if SearchOrigin = rsdBackward then
|
||||
FDataSet.Prior;
|
||||
R:=DataSetLocateThrough(FDataSet, FieldName, Edit1.Text, LOptions, SearchOrigin);
|
||||
finally
|
||||
{$IFDEF NoAutomatedBookmark}
|
||||
if not R then
|
||||
FDataSet.GotoBookmark(P);
|
||||
FDataSet.FreeBookmark(P);
|
||||
{$ELSE}
|
||||
if not R then
|
||||
FDataSet.Bookmark:=P;
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
{
|
||||
type
|
||||
THckGrid = class(TCustomDBGrid)
|
||||
end;
|
||||
}
|
||||
procedure TrxDBGridFindForm.SetGrid(AGrid: TRxDBGrid);
|
||||
var
|
||||
i:integer;
|
||||
begin
|
||||
if AGrid=FGrid then exit;
|
||||
FGrid:=AGrid;
|
||||
ComboBox1.Items.Clear;
|
||||
if Assigned(AGrid) then
|
||||
begin
|
||||
for i:=0 to AGrid.Columns.Count-1 do
|
||||
begin
|
||||
if not (coDisableDialogFind in AGrid.Columns[i].Options) then
|
||||
ComboBox1.Items.Add(AGrid.Columns[i].Title.Caption);
|
||||
end;
|
||||
|
||||
ComboBox1.ItemIndex:=ComboBox1.Items.IndexOf(AGrid.SelectedColumn.Title.Caption);
|
||||
end;
|
||||
|
||||
FDataSet:=nil;
|
||||
if Assigned(FGrid) and Assigned(FGrid.DataSource) then
|
||||
FDataSet:=FGrid.DataSource.DataSet;
|
||||
{ if Assigned(FGrid) and Assigned(THckGrid(FGrid).DataSource) then
|
||||
FDataSet:=THckGrid(FGrid).DataSource.DataSet;}
|
||||
BtnFind.Enabled:=Assigned(FDataSet) and FDataSet.Active
|
||||
end;
|
||||
|
||||
end.
|
||||
|
318
RXLib/rxdb/rxdbgrid_popupfilterunit.lfm
Normal file
318
RXLib/rxdb/rxdbgrid_popupfilterunit.lfm
Normal file
@@ -0,0 +1,318 @@
|
||||
object RxDBGrid_PopUpFilterForm: TRxDBGrid_PopUpFilterForm
|
||||
Left = 525
|
||||
Height = 448
|
||||
Top = 284
|
||||
Width = 279
|
||||
Caption = 'RxDBGrid_PopUpFilterForm'
|
||||
ClientHeight = 448
|
||||
ClientWidth = 279
|
||||
KeyPreview = True
|
||||
OnClose = FormClose
|
||||
OnKeyDown = FormKeyDown
|
||||
ShowHint = True
|
||||
LCLVersion = '1.9.0.0'
|
||||
object SpeedButton1: TSpeedButton
|
||||
Tag = 1
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = DividerBevel1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 24
|
||||
Top = 20
|
||||
Width = 279
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
Caption = 'Ascending'
|
||||
Flat = True
|
||||
OnClick = SpeedButton1Click
|
||||
end
|
||||
object SpeedButton2: TSpeedButton
|
||||
Tag = -1
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = SpeedButton1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 22
|
||||
Top = 44
|
||||
Width = 279
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
Caption = 'Descending'
|
||||
Flat = True
|
||||
OnClick = SpeedButton1Click
|
||||
end
|
||||
object DividerBevel1: TDividerBevel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Owner
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 20
|
||||
Top = 0
|
||||
Width = 279
|
||||
Caption = 'Sorting'
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
Font.Style = [fsBold]
|
||||
ParentFont = False
|
||||
end
|
||||
object DividerBevel2: TDividerBevel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = SpeedButton2
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 20
|
||||
Top = 66
|
||||
Width = 279
|
||||
Caption = 'Quick Filter'
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
Font.Style = [fsBold]
|
||||
ParentFont = False
|
||||
end
|
||||
object SpeedButton3: TSpeedButton
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = DividerBevel2
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 24
|
||||
Top = 86
|
||||
Width = 279
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
Caption = 'Clear filter'
|
||||
Flat = True
|
||||
OnClick = SpeedButton3Click
|
||||
end
|
||||
object SpeedButton4: TSpeedButton
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = SpeedButton3
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 24
|
||||
Top = 110
|
||||
Width = 279
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
Caption = 'Empty values'
|
||||
Flat = True
|
||||
OnClick = SpeedButton4Click
|
||||
end
|
||||
object SpeedButton5: TSpeedButton
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = SpeedButton4
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 24
|
||||
Top = 134
|
||||
Width = 279
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
Caption = 'Not empty'
|
||||
Flat = True
|
||||
OnClick = SpeedButton5Click
|
||||
end
|
||||
object DividerBevel3: TDividerBevel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = SpeedButton5
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 20
|
||||
Top = 158
|
||||
Width = 279
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
Font.Style = [fsBold]
|
||||
ParentFont = False
|
||||
end
|
||||
object SpeedButton6: TSpeedButton
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = DividerBevel3
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 24
|
||||
Top = 178
|
||||
Width = 279
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
Caption = 'Standart filter'
|
||||
Flat = True
|
||||
OnClick = SpeedButton6Click
|
||||
end
|
||||
object CheckListBox1: TCheckListBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = SpeedButton6
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = SpeedButton8
|
||||
Left = 0
|
||||
Height = 150
|
||||
Top = 202
|
||||
Width = 279
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
BorderSpacing.Bottom = 6
|
||||
ItemHeight = 0
|
||||
OnClickCheck = CheckListBox1ClickCheck
|
||||
PopupMenu = PopupMenu1
|
||||
TabOrder = 0
|
||||
TopIndex = -1
|
||||
end
|
||||
object ButtonPanel1: TButtonPanel
|
||||
Left = 6
|
||||
Height = 46
|
||||
Top = 396
|
||||
Width = 267
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
HelpButton.Name = 'HelpButton'
|
||||
HelpButton.DefaultCaption = True
|
||||
CloseButton.Name = 'CloseButton'
|
||||
CloseButton.DefaultCaption = True
|
||||
CancelButton.Name = 'CancelButton'
|
||||
CancelButton.DefaultCaption = True
|
||||
TabOrder = 1
|
||||
ShowButtons = [pbOK, pbCancel]
|
||||
end
|
||||
object SpeedButton8: TSpeedButton
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = ButtonPanel1
|
||||
Left = 241
|
||||
Height = 32
|
||||
Hint = 'Hide only current item'
|
||||
Top = 358
|
||||
Width = 32
|
||||
Anchors = [akRight, akBottom]
|
||||
BorderSpacing.Right = 6
|
||||
Glyph.Data = {
|
||||
36040000424D3604000000000000360000002800000010000000100000000100
|
||||
2000000000000004000064000000640000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000BDBF
|
||||
BFFF8F9392FFC2C5C4FF00000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000969B
|
||||
99FFB9BCBBFF8D918FFFC4C6C5FF000000000000000000000000B2B5B4FF858A
|
||||
88FF858A88FF858A88FF858A88FF858A88FF858A88FFB0B2B1FF000000000000
|
||||
000000000000C6C8C8FFB5B8B7FF000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000C1C4
|
||||
C3FF8F9392FFC7CAC9FF00000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000969A
|
||||
99FFB9BCBBFF8D918FFFC9CBCBFF000000000000000000000000B5B7B6FF858A
|
||||
88FF858A88FF858A88FF858A88FF858A88FF858A88FFB2B4B3FF000000000000
|
||||
000000000000C9CCCBFFB6B9B8FF000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000196B
|
||||
D0FF005CCEFF1B6CD0FF000000000000000000000000000000006B9BD7FF0A62
|
||||
CFFF005CCEFF005CCEFF005CCEFF005CCEFF0961CFFF6598D7FF00000000065F
|
||||
CEFF00000000005CCEFF00000000000000000000000000000000055FCEFFBECE
|
||||
E0FF00000000000000000000000000000000C4D1E0FF045FCFFF00000000196B
|
||||
D0FF005CCEFF1B6DD1FF000000000000000000000000000000006B9CD8FF0A62
|
||||
CFFF005CCEFF005CCEFF005CCEFF005CCEFF0961CFFF6598D7FF000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000
|
||||
}
|
||||
OnClick = SpeedButton9Click
|
||||
end
|
||||
object SpeedButton9: TSpeedButton
|
||||
Tag = 1
|
||||
AnchorSideTop.Control = SpeedButton8
|
||||
AnchorSideRight.Control = SpeedButton8
|
||||
AnchorSideBottom.Control = SpeedButton8
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 203
|
||||
Height = 32
|
||||
Hint = 'Show only current item'
|
||||
Top = 358
|
||||
Width = 32
|
||||
Anchors = [akTop, akRight, akBottom]
|
||||
BorderSpacing.Right = 6
|
||||
Glyph.Data = {
|
||||
36040000424D3604000000000000360000002800000010000000100000000100
|
||||
2000000000000004000064000000640000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000009195
|
||||
93FF878C8AFF919593FF00000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000878C
|
||||
8AFFDADBDBFF878C8AFF00000000000000000000000000000000969A98FF858A
|
||||
88FF858A88FF858A88FF858A88FF858A88FF858A88FF929695FF000000008F95
|
||||
93FF878C8AFF8F9593FF00000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000009296
|
||||
94FF878C8AFF929694FF00000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000878C
|
||||
8AFFDEDFDFFF878C8AFF00000000000000000000000000000000979B99FF858A
|
||||
88FF858A88FF858A88FF858A88FF858A88FF858A88FF939796FF000000009095
|
||||
93FF878C8AFF909593FF00000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000B7C9
|
||||
DEFF2874D2FF9DB9DBFF00000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000BCCCDFFF1D77
|
||||
D9FF47ACF5FF207DDCFFA2BDDCFF0000000000000000000000006499D8FF0661
|
||||
CFFF005CCEFF005CCEFF005CCEFF005CCEFF0B64D0FF7DA7DAFF72A9E0FF45AF
|
||||
F8FF95CAEFFF48B0F9FF1F7BDBFFA8C0DDFF00000000D6DCE2FF045FCFFF35A3
|
||||
F5FF3EAFFCFF3EAFFCFF3EAFFCFF3EAFFCFF2D98EFFF0E66D0FF99CCEEFFB3D4
|
||||
EAFF00000000BDD7E8FF48B0F9FF1E79DAFFABC2DEFF000000005D96D9FF0560
|
||||
D0FF005CCEFF005CCEFF005CCEFF005CCEFF0962D0FF77A4DAFF000000000000
|
||||
00000000000000000000BCD7E9FF49B1F9FF6FA8E1FF00000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000BBD8EBFF65BCF7FF00000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000
|
||||
}
|
||||
OnClick = SpeedButton9Click
|
||||
end
|
||||
object CheckBox1: TCheckBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = SpeedButton9
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 6
|
||||
Height = 24
|
||||
Top = 362
|
||||
Width = 88
|
||||
BorderSpacing.Left = 6
|
||||
Caption = 'All values'
|
||||
OnChange = CheckBox1Change
|
||||
TabOrder = 2
|
||||
end
|
||||
object PopupMenu1: TPopupMenu
|
||||
Left = 64
|
||||
Top = 272
|
||||
object MenuItem1: TMenuItem
|
||||
Tag = 1
|
||||
Caption = 'Check all'
|
||||
OnClick = MenuItem1Click
|
||||
end
|
||||
object MenuItem3: TMenuItem
|
||||
Caption = '-'
|
||||
end
|
||||
object MenuItem2: TMenuItem
|
||||
Caption = 'Unchec all'
|
||||
OnClick = MenuItem1Click
|
||||
end
|
||||
end
|
||||
end
|
295
RXLib/rxdb/rxdbgrid_popupfilterunit.pas
Normal file
295
RXLib/rxdb/rxdbgrid_popupfilterunit.pas
Normal file
@@ -0,0 +1,295 @@
|
||||
{ rxdbgrid unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
{$I rx.inc}
|
||||
|
||||
unit RxDBGrid_PopUpFilterUnit;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, DividerBevel, ListFilterEdit, Forms, Controls,
|
||||
Graphics, Dialogs, Buttons, ComCtrls, CheckLst, ButtonPanel, StdCtrls, Menus,
|
||||
rxdbgrid;
|
||||
|
||||
type
|
||||
|
||||
{ TRxDBGrid_PopUpFilterForm }
|
||||
|
||||
TRxDBGrid_PopUpFilterForm = class(TForm)
|
||||
ButtonPanel1: TButtonPanel;
|
||||
CheckBox1: TCheckBox;
|
||||
CheckListBox1: TCheckListBox;
|
||||
DividerBevel1: TDividerBevel;
|
||||
DividerBevel2: TDividerBevel;
|
||||
DividerBevel3: TDividerBevel;
|
||||
MenuItem1: TMenuItem;
|
||||
MenuItem2: TMenuItem;
|
||||
MenuItem3: TMenuItem;
|
||||
PopupMenu1: TPopupMenu;
|
||||
SpeedButton1: TSpeedButton;
|
||||
SpeedButton2: TSpeedButton;
|
||||
SpeedButton3: TSpeedButton;
|
||||
SpeedButton4: TSpeedButton;
|
||||
SpeedButton5: TSpeedButton;
|
||||
SpeedButton6: TSpeedButton;
|
||||
SpeedButton8: TSpeedButton;
|
||||
SpeedButton9: TSpeedButton;
|
||||
procedure CheckBox1Change(Sender: TObject);
|
||||
procedure CheckListBox1ClickCheck(Sender: TObject);
|
||||
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
||||
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
procedure MenuItem1Click(Sender: TObject);
|
||||
procedure SpeedButton1Click(Sender: TObject);
|
||||
procedure SpeedButton3Click(Sender: TObject);
|
||||
procedure SpeedButton4Click(Sender: TObject);
|
||||
procedure SpeedButton5Click(Sender: TObject);
|
||||
procedure SpeedButton6Click(Sender: TObject);
|
||||
procedure SpeedButton9Click(Sender: TObject);
|
||||
private
|
||||
FRxDBGrid:TRxDBGrid;
|
||||
FRxColumn: TRxColumn;
|
||||
procedure UpdateChList;
|
||||
procedure Localize;
|
||||
public
|
||||
constructor CreatePopUpFilterForm(ARxColumn: TRxColumn);
|
||||
end;
|
||||
|
||||
implementation
|
||||
uses LCLType, rxdconst;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TRxDBGrid_PopUpFilterForm }
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.SpeedButton1Click(Sender: TObject);
|
||||
begin
|
||||
if TComponent(Sender).Tag > 0 then
|
||||
FRxColumn.SortOrder:=smUp
|
||||
else
|
||||
if TComponent(Sender).Tag < 0 then
|
||||
FRxColumn.SortOrder:=smDown
|
||||
else
|
||||
FRxColumn.SortOrder:=smNone;
|
||||
FRxDBGrid.SetSort([FRxColumn.FieldName], [FRxColumn.SortOrder], true);
|
||||
Close;
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.SpeedButton3Click(Sender: TObject);
|
||||
begin
|
||||
FRxColumn.Filter.State:=rxfsAll;
|
||||
FRxColumn.Filter.CurrentValues.Clear;
|
||||
FRxDBGrid.DataSource.DataSet.Filtered := True;
|
||||
FRxDBGrid.DataSource.DataSet.First;
|
||||
Close;
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.SpeedButton4Click(Sender: TObject);
|
||||
begin
|
||||
FRxColumn.Filter.State:=rxfsEmpty;
|
||||
FRxDBGrid.DataSource.DataSet.Filtered := True;
|
||||
FRxDBGrid.DataSource.DataSet.First;
|
||||
Close;
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.SpeedButton5Click(Sender: TObject);
|
||||
begin
|
||||
FRxColumn.Filter.State:=rxfsNonEmpty;
|
||||
FRxDBGrid.DataSource.DataSet.Filtered := True;
|
||||
FRxDBGrid.DataSource.DataSet.First;
|
||||
Close;
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.SpeedButton6Click(Sender: TObject);
|
||||
begin
|
||||
Hide;
|
||||
Close;
|
||||
FRxDBGrid.ShowFilterDialog;
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.SpeedButton9Click(Sender: TObject);
|
||||
var
|
||||
K, i: Integer;
|
||||
begin
|
||||
K:=CheckListBox1.ItemIndex;
|
||||
if K < 0 then
|
||||
K:=0;
|
||||
|
||||
for i:=0 to CheckListBox1.Items.Count-1 do
|
||||
if i = k then
|
||||
CheckListBox1.Checked[i]:=TComponent(Sender).Tag > 0
|
||||
else
|
||||
CheckListBox1.Checked[i]:=TComponent(Sender).Tag = 0;
|
||||
CheckListBox1ClickCheck(nil);
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.UpdateChList;
|
||||
var
|
||||
i, Cnt: Integer;
|
||||
S: String;
|
||||
begin
|
||||
CheckListBox1.Items.BeginUpdate;
|
||||
CheckListBox1.Items.Clear;
|
||||
Cnt:=FRxColumn.Filter.ValueList.Count - 1;
|
||||
{
|
||||
if FRxColumn.Filter.Style = rxfstBoth then
|
||||
Dec(Cnt);
|
||||
}
|
||||
for i:=0 to Cnt do
|
||||
begin
|
||||
S:=FRxColumn.Filter.ValueList[i];
|
||||
if (S <> FRxColumn.Filter.AllValue) and (S <> FRxColumn.Filter.EmptyValue) then
|
||||
CheckListBox1.Checked[CheckListBox1.Items.Add(S)]:=FRxColumn.Filter.CurrentValues.IndexOf(S) >= 0;
|
||||
end;
|
||||
|
||||
CheckListBox1ClickCheck(nil);
|
||||
|
||||
CheckListBox1.Items.EndUpdate;
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.Localize;
|
||||
begin
|
||||
DividerBevel1.Caption:=sSorting;
|
||||
SpeedButton1.Caption:=sAscending;
|
||||
SpeedButton2.Caption:=sDescending;
|
||||
DividerBevel2.Caption:=sQuickFilter;
|
||||
SpeedButton3.Caption:=sClearFilter;
|
||||
SpeedButton4.Caption:=sEmptyValues;
|
||||
SpeedButton5.Caption:=sNotEmpty;
|
||||
SpeedButton6.Caption:=sStandartFilter;
|
||||
CheckBox1.Caption:=sAllValues;
|
||||
SpeedButton9.Hint:=sHintShowOnlyCurrentItem;
|
||||
SpeedButton8.Hint:=sHintHideOnlyCurrentItem;
|
||||
end;
|
||||
|
||||
constructor TRxDBGrid_PopUpFilterForm.CreatePopUpFilterForm(ARxColumn: TRxColumn
|
||||
);
|
||||
begin
|
||||
inherited Create(ARxColumn.Grid);
|
||||
BorderStyle:=bsNone;
|
||||
FRxColumn:=ARxColumn;
|
||||
FRxDBGrid:=FRxColumn.Grid as TRxDBGrid;
|
||||
Localize;
|
||||
UpdateChList;
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.FormKeyDown(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState);
|
||||
begin
|
||||
if Key = VK_ESCAPE then
|
||||
ModalResult:=mrCancel;
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.MenuItem1Click(Sender: TObject);
|
||||
begin
|
||||
CheckBox1.Checked:=TComponent(Sender).Tag = 1;
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.CheckBox1Change(Sender: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
CheckListBox1.OnClickCheck:=nil;
|
||||
for i:=0 to CheckListBox1.Items.Count - 1 do
|
||||
CheckListBox1.Checked[i]:=CheckBox1.Checked;
|
||||
CheckListBox1.OnClickCheck:=@CheckListBox1ClickCheck;
|
||||
// CheckListBox1ClickCheck(nil);
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.CheckListBox1ClickCheck(Sender: TObject);
|
||||
var
|
||||
AC, AU: Boolean;
|
||||
i: Integer;
|
||||
begin
|
||||
AC:=true;
|
||||
AU:=true;
|
||||
for i:=0 to CheckListBox1.Items.Count-1 do
|
||||
begin
|
||||
if not CheckListBox1.Checked[i] then
|
||||
AC:=false;
|
||||
if CheckListBox1.Checked[i] then
|
||||
AU:=false;
|
||||
end;
|
||||
|
||||
CheckBox1.OnChange:=nil;
|
||||
if AC then
|
||||
CheckBox1.Checked:=true
|
||||
else
|
||||
if AU then
|
||||
CheckBox1.Checked:=false
|
||||
else
|
||||
CheckBox1.State:=cbGrayed;
|
||||
CheckBox1.OnChange:=@CheckBox1Change;
|
||||
end;
|
||||
|
||||
procedure TRxDBGrid_PopUpFilterForm.FormClose(Sender: TObject;
|
||||
var CloseAction: TCloseAction);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
if ModalResult = mrOk then
|
||||
begin
|
||||
FRxDBGrid.DataSource.DataSet.DisableControls;
|
||||
FRxDBGrid.DataSource.DataSet.Filtered := false;
|
||||
if CheckBox1.Checked then
|
||||
begin
|
||||
FRxColumn.Filter.State:=rxfsAll;
|
||||
FRxColumn.Filter.CurrentValues.Assign(CheckListBox1.Items);
|
||||
end
|
||||
else
|
||||
if CheckBox1.State = cbUnchecked then
|
||||
begin
|
||||
FRxColumn.Filter.State:=rxfsAll;
|
||||
FRxColumn.Filter.CurrentValues.Clear;
|
||||
end
|
||||
else
|
||||
begin
|
||||
FRxColumn.Filter.CurrentValues.BeginUpdate;
|
||||
FRxColumn.Filter.CurrentValues.Clear;
|
||||
for i:=0 to CheckListBox1.Items.Count-1 do
|
||||
if CheckListBox1.Checked[i] then
|
||||
FRxColumn.Filter.CurrentValues.Add(CheckListBox1.Items[i]);
|
||||
FRxColumn.Filter.CurrentValues.EndUpdate;
|
||||
if (FRxColumn.Filter.CurrentValues.Count > 0) then
|
||||
FRxColumn.Filter.State:=rxfsFilter
|
||||
else
|
||||
FRxColumn.Filter.State:=rxfsAll;
|
||||
end;
|
||||
FRxDBGrid.DataSource.DataSet.Filtered := True;
|
||||
FRxDBGrid.DataSource.DataSet.First;
|
||||
FRxDBGrid.DataSource.DataSet.EnableControls;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
|
1054
RXLib/rxdb/rxdbgridexportpdf.pas
Normal file
1054
RXLib/rxdb/rxdbgridexportpdf.pas
Normal file
File diff suppressed because it is too large
Load Diff
332
RXLib/rxdb/rxdbgridexportpdfsetupunit.lfm
Normal file
332
RXLib/rxdb/rxdbgridexportpdfsetupunit.lfm
Normal file
@@ -0,0 +1,332 @@
|
||||
object RxDBGridExportPdfSetupForm: TRxDBGridExportPdfSetupForm
|
||||
Left = 544
|
||||
Height = 416
|
||||
Top = 316
|
||||
Width = 522
|
||||
Caption = 'Export params'
|
||||
ClientHeight = 416
|
||||
ClientWidth = 522
|
||||
OnCreate = FormCreate
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '1.9.0.0'
|
||||
object Label1: TLabel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Owner
|
||||
Left = 6
|
||||
Height = 13
|
||||
Top = 6
|
||||
Width = 78
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Export file name'
|
||||
FocusControl = FileNameEdit1
|
||||
ParentColor = False
|
||||
end
|
||||
object FileNameEdit1: TFileNameEdit
|
||||
AnchorSideLeft.Control = Label1
|
||||
AnchorSideTop.Control = Label1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 12
|
||||
Height = 21
|
||||
Top = 25
|
||||
Width = 504
|
||||
Filter = 'All files (*.*)|*.*|LibreOffice/OpenOffice (*.ods)|*.ods|Excell 97-2003|*.xls|Excell 2007-2013|*.xlxs'
|
||||
FilterIndex = 0
|
||||
HideDirectories = False
|
||||
ButtonWidth = 23
|
||||
NumGlyphs = 1
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
MaxLength = 0
|
||||
Spacing = 0
|
||||
TabOrder = 0
|
||||
end
|
||||
object ButtonPanel1: TButtonPanel
|
||||
Left = 6
|
||||
Height = 34
|
||||
Top = 376
|
||||
Width = 510
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
HelpButton.Name = 'HelpButton'
|
||||
HelpButton.DefaultCaption = True
|
||||
CloseButton.Name = 'CloseButton'
|
||||
CloseButton.DefaultCaption = True
|
||||
CancelButton.Name = 'CancelButton'
|
||||
CancelButton.DefaultCaption = True
|
||||
TabOrder = 1
|
||||
ShowButtons = [pbOK, pbCancel, pbHelp]
|
||||
end
|
||||
object GroupBox1: TGroupBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = FileNameEdit1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 117
|
||||
Top = 52
|
||||
Width = 510
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Global'
|
||||
ClientHeight = 99
|
||||
ClientWidth = 506
|
||||
TabOrder = 2
|
||||
object ColorBox1: TColorBox
|
||||
AnchorSideLeft.Control = Label5
|
||||
AnchorSideTop.Control = Label5
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = GroupBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 265
|
||||
Height = 22
|
||||
Top = 71
|
||||
Width = 235
|
||||
Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbIncludeDefault, cbCustomColor, cbPrettyNames, cbCustomColors]
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 16
|
||||
TabOrder = 0
|
||||
end
|
||||
object Label5: TLabel
|
||||
AnchorSideLeft.Control = Label3
|
||||
AnchorSideTop.Control = CheckBox6
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 259
|
||||
Height = 13
|
||||
Top = 52
|
||||
Width = 46
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Title color'
|
||||
ParentColor = False
|
||||
end
|
||||
object CheckBox6: TCheckBox
|
||||
AnchorSideLeft.Control = Label3
|
||||
AnchorSideTop.Control = cbOverwriteExisting
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 259
|
||||
Height = 17
|
||||
Top = 29
|
||||
Width = 86
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Export images'
|
||||
TabOrder = 1
|
||||
end
|
||||
object cbOverwriteExisting: TCheckBox
|
||||
AnchorSideLeft.Control = Label3
|
||||
AnchorSideTop.Control = GroupBox1
|
||||
Left = 259
|
||||
Height = 17
|
||||
Top = 6
|
||||
Width = 123
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Overwrite existing file'
|
||||
Enabled = False
|
||||
TabOrder = 2
|
||||
end
|
||||
object cbOpenAfterExport: TCheckBox
|
||||
AnchorSideLeft.Control = GroupBox1
|
||||
AnchorSideTop.Control = GroupBox1
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 6
|
||||
Width = 106
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Open after export'
|
||||
TabOrder = 3
|
||||
end
|
||||
object cbExportColumnHeader: TCheckBox
|
||||
AnchorSideLeft.Control = GroupBox1
|
||||
AnchorSideTop.Control = cbOpenAfterExport
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 29
|
||||
Width = 123
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Export column header'
|
||||
TabOrder = 4
|
||||
end
|
||||
object cbExportColumnFooter: TCheckBox
|
||||
AnchorSideLeft.Control = GroupBox1
|
||||
AnchorSideTop.Control = cbExportColumnHeader
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 52
|
||||
Width = 119
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Export column footer'
|
||||
TabOrder = 5
|
||||
end
|
||||
object cbExportCellColors: TCheckBox
|
||||
AnchorSideLeft.Control = GroupBox1
|
||||
AnchorSideTop.Control = cbExportColumnFooter
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 75
|
||||
Width = 99
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Export cell colors'
|
||||
TabOrder = 6
|
||||
end
|
||||
object Label3: TLabel
|
||||
AnchorSideLeft.Control = GroupBox1
|
||||
AnchorSideLeft.Side = asrCenter
|
||||
AnchorSideTop.Control = GroupBox1
|
||||
Left = 253
|
||||
Height = 1
|
||||
Top = 0
|
||||
Width = 1
|
||||
ParentColor = False
|
||||
end
|
||||
end
|
||||
object GroupBox2: TGroupBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = GroupBox1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 139
|
||||
Top = 175
|
||||
Width = 510
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'PDF Options'
|
||||
ClientHeight = 121
|
||||
ClientWidth = 506
|
||||
TabOrder = 3
|
||||
object CheckBox1: TCheckBox
|
||||
AnchorSideTop.Control = GroupBox2
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 6
|
||||
Width = 55
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Out line'
|
||||
TabOrder = 0
|
||||
end
|
||||
object CheckBox2: TCheckBox
|
||||
AnchorSideLeft.Control = GroupBox2
|
||||
AnchorSideTop.Control = CheckBox1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 29
|
||||
Width = 88
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Compress text'
|
||||
TabOrder = 1
|
||||
end
|
||||
object CheckBox3: TCheckBox
|
||||
AnchorSideLeft.Control = GroupBox2
|
||||
AnchorSideTop.Control = CheckBox2
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 52
|
||||
Width = 93
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Compress fonts'
|
||||
TabOrder = 2
|
||||
end
|
||||
object CheckBox4: TCheckBox
|
||||
AnchorSideLeft.Control = GroupBox2
|
||||
AnchorSideTop.Control = CheckBox3
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 75
|
||||
Width = 101
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Compress images'
|
||||
TabOrder = 3
|
||||
end
|
||||
object CheckBox5: TCheckBox
|
||||
AnchorSideLeft.Control = GroupBox2
|
||||
AnchorSideTop.Control = CheckBox4
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 98
|
||||
Width = 84
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Use raw JPEG'
|
||||
TabOrder = 4
|
||||
end
|
||||
object Label2: TLabel
|
||||
AnchorSideLeft.Control = Label4
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = GroupBox2
|
||||
Left = 260
|
||||
Height = 13
|
||||
Top = 6
|
||||
Width = 53
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Paper type'
|
||||
ParentColor = False
|
||||
end
|
||||
object ComboBox1: TComboBox
|
||||
AnchorSideLeft.Control = Label2
|
||||
AnchorSideTop.Control = Label2
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = GroupBox2
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 266
|
||||
Height = 21
|
||||
Top = 25
|
||||
Width = 234
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 13
|
||||
Style = csDropDownList
|
||||
TabOrder = 5
|
||||
end
|
||||
object RadioGroup1: TRadioGroup
|
||||
AnchorSideLeft.Control = Label4
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = ComboBox1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = GroupBox2
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 260
|
||||
Height = 52
|
||||
Top = 52
|
||||
Width = 240
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoFill = True
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Orientation'
|
||||
ChildSizing.LeftRightSpacing = 6
|
||||
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
|
||||
ChildSizing.EnlargeVertical = crsHomogenousChildResize
|
||||
ChildSizing.ShrinkHorizontal = crsScaleChilds
|
||||
ChildSizing.ShrinkVertical = crsScaleChilds
|
||||
ChildSizing.Layout = cclLeftToRightThenTopToBottom
|
||||
ChildSizing.ControlsPerLine = 1
|
||||
ClientHeight = 34
|
||||
ClientWidth = 236
|
||||
Items.Strings = (
|
||||
'Portrait'
|
||||
'Landscape'
|
||||
)
|
||||
TabOrder = 6
|
||||
end
|
||||
object Label4: TLabel
|
||||
AnchorSideLeft.Control = GroupBox2
|
||||
AnchorSideLeft.Side = asrCenter
|
||||
AnchorSideTop.Control = GroupBox2
|
||||
Left = 253
|
||||
Height = 1
|
||||
Top = 0
|
||||
Width = 1
|
||||
ParentColor = False
|
||||
end
|
||||
end
|
||||
end
|
138
RXLib/rxdb/rxdbgridexportpdfsetupunit.pas
Normal file
138
RXLib/rxdb/rxdbgridexportpdfsetupunit.pas
Normal file
@@ -0,0 +1,138 @@
|
||||
{ TPdfExportOptions unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit RxDBGridExportPdfSetupUnit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
{$IF (FPC_FULLVERSION >= 30004)}
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
||||
EditBtn, ButtonPanel, ExtCtrls, ComCtrls, ColorBox, fpPDF;
|
||||
|
||||
type
|
||||
|
||||
{ TRxDBGridExportPdfSetupForm }
|
||||
|
||||
TRxDBGridExportPdfSetupForm = class(TForm)
|
||||
ButtonPanel1: TButtonPanel;
|
||||
cbExportCellColors: TCheckBox;
|
||||
cbExportColumnFooter: TCheckBox;
|
||||
cbExportColumnHeader: TCheckBox;
|
||||
cbOpenAfterExport: TCheckBox;
|
||||
cbOverwriteExisting: TCheckBox;
|
||||
CheckBox1: TCheckBox;
|
||||
CheckBox2: TCheckBox;
|
||||
CheckBox3: TCheckBox;
|
||||
CheckBox4: TCheckBox;
|
||||
CheckBox5: TCheckBox;
|
||||
CheckBox6: TCheckBox;
|
||||
ColorBox1: TColorBox;
|
||||
ComboBox1: TComboBox;
|
||||
FileNameEdit1: TFileNameEdit;
|
||||
GroupBox1: TGroupBox;
|
||||
GroupBox2: TGroupBox;
|
||||
Label1: TLabel;
|
||||
Label2: TLabel;
|
||||
Label3: TLabel;
|
||||
Label4: TLabel;
|
||||
Label5: TLabel;
|
||||
RadioGroup1: TRadioGroup;
|
||||
procedure FormCreate(Sender: TObject);
|
||||
private
|
||||
{ private declarations }
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
RxDBGridExportPdfSetupForm: TRxDBGridExportPdfSetupForm;
|
||||
|
||||
const
|
||||
pdfPaperNames : array [TPDFPaperType] of string =
|
||||
('Custom', //ptCustom
|
||||
'A4', //ptA4
|
||||
'A5', //ptA5
|
||||
'Letter', // ptLetter
|
||||
'Legal', // ptLegal
|
||||
'Executive', // ptExecutive
|
||||
'Comm10', // ptComm10
|
||||
'Monarch', // ptMonarch
|
||||
'DL', // ptDL
|
||||
'C5', // ptC5
|
||||
'B5' // ptB5
|
||||
);
|
||||
|
||||
{$ENDIF}
|
||||
implementation
|
||||
{$IF (FPC_FULLVERSION >= 30004)}
|
||||
uses rxdconst, LCLIntf;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TRxDBGridExportPdfSetupForm }
|
||||
|
||||
procedure TRxDBGridExportPdfSetupForm.FormCreate(Sender: TObject);
|
||||
var
|
||||
c: TPDFPaperType;
|
||||
begin
|
||||
Caption:=sExportParams;
|
||||
GroupBox1.Caption:=sGlobal;
|
||||
GroupBox2.Caption:=sPDFOptions;
|
||||
Label1.Caption:=sExportFileName;
|
||||
cbOpenAfterExport.Caption:=sOpenAfterExport;
|
||||
cbExportColumnHeader.Caption:=sExportColumnHeader;
|
||||
cbExportColumnFooter.Caption:=sExportColumnFooter;
|
||||
cbExportCellColors.Caption:=sExportCellColors;
|
||||
cbOverwriteExisting.Caption:=sOverwriteExisting;
|
||||
CheckBox6.Caption:=sExportImages;
|
||||
Label2.Caption:=sPaperType;
|
||||
Label5.Caption:=sTitleColor;
|
||||
CheckBox1.Caption:=sOutLine;
|
||||
CheckBox2.Caption:=sCompressText;
|
||||
CheckBox3.Caption:=sCompressFonts;
|
||||
CheckBox4.Caption:=sCompressImages;
|
||||
CheckBox5.Caption:=sUseRawJPEG;
|
||||
|
||||
RadioGroup1.Caption:=sOrientation;
|
||||
RadioGroup1.Items[0]:=sPortrait;
|
||||
RadioGroup1.Items[1]:=sLandscape;
|
||||
|
||||
ComboBox1.Items.Clear;
|
||||
for C:=ptA4 to High(TPDFPaperType) do
|
||||
ComboBox1.Items.Add(pdfPaperNames[C]);
|
||||
end;
|
||||
|
||||
{$ENDIF}
|
||||
end.
|
||||
|
139
RXLib/rxdb/rxdbgridfootertools.pas
Normal file
139
RXLib/rxdb/rxdbgridfootertools.pas
Normal file
@@ -0,0 +1,139 @@
|
||||
{ RxDBGridPrintGrid unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit RxDBGridFooterTools;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, rxdbgrid, Graphics, Grids, Controls, Menus;
|
||||
|
||||
type
|
||||
|
||||
{ TRxDBGridFooterTools }
|
||||
|
||||
TRxDBGridFooterTools = class(TRxDBGridAbstractTools)
|
||||
private
|
||||
FFooterColor: TColor;
|
||||
FFooterRowCount: integer;
|
||||
procedure SetFooterColor(AValue: TColor);
|
||||
procedure SetFooterRowCount(AValue: integer);
|
||||
protected
|
||||
function DoExecTools:boolean;override;
|
||||
function DoSetupTools:boolean; override;
|
||||
function MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer):boolean; override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
published
|
||||
property FooterRowCount:integer read FFooterRowCount write SetFooterRowCount default 1;
|
||||
property FooterColor:TColor read FFooterColor write SetFooterColor default clYellow;
|
||||
end;
|
||||
|
||||
implementation
|
||||
uses Forms, Dialogs, rxdbgridfootertools_setup, rxdconst;
|
||||
|
||||
{ TRxDBGridFooterTools }
|
||||
|
||||
procedure TRxDBGridFooterTools.SetFooterRowCount(AValue: integer);
|
||||
begin
|
||||
if FFooterRowCount=AValue then Exit;
|
||||
FFooterRowCount:=AValue;
|
||||
end;
|
||||
|
||||
procedure TRxDBGridFooterTools.SetFooterColor(AValue: TColor);
|
||||
begin
|
||||
if FFooterColor=AValue then Exit;
|
||||
FFooterColor:=AValue;
|
||||
end;
|
||||
|
||||
function TRxDBGridFooterTools.DoExecTools: boolean;
|
||||
begin
|
||||
Result:=false;
|
||||
if (RxDBGrid = nil) or (RxDBGrid.DataSource = nil) or (RxDBGrid.DataSource.Dataset = nil) then
|
||||
Exit;
|
||||
|
||||
if RxDBGrid.FooterOptions.Active then
|
||||
RxDBGrid.FooterOptions.Active:=false
|
||||
else
|
||||
begin
|
||||
if RxDBGrid.FooterOptions.RowCount = 0 then
|
||||
RxDBGrid.FooterOptions.RowCount:=FFooterRowCount;
|
||||
|
||||
if RxDBGrid.FooterOptions.Color = clNone then
|
||||
RxDBGrid.FooterOptions.Color:=FFooterColor;
|
||||
RxDBGrid.FooterOptions.Active:=true
|
||||
end;
|
||||
end;
|
||||
|
||||
function TRxDBGridFooterTools.DoSetupTools: boolean;
|
||||
begin
|
||||
RxDBGridFooterTools_SetupForm:=TRxDBGridFooterTools_SetupForm.Create(Application);
|
||||
RxDBGridFooterTools_SetupForm.InitData(RxDBGrid);
|
||||
Result:=RxDBGridFooterTools_SetupForm.ShowModal = mrOk;
|
||||
if Result then
|
||||
begin
|
||||
RxDBGridFooterTools_SetupForm.SetData;
|
||||
RxDBGrid.CalcStatTotals;
|
||||
end;
|
||||
RxDBGridFooterTools_SetupForm.Free;
|
||||
end;
|
||||
|
||||
type
|
||||
THackRxDBGrid = class(TRxDBGrid);
|
||||
|
||||
function TRxDBGridFooterTools.MouseDown(Button: TMouseButton;
|
||||
Shift: TShiftState; X, Y: integer): boolean;
|
||||
begin
|
||||
Result:=(Y > THackRxDBGrid(RxDBGrid).GCache.ClientHeight - (RxDBGrid.DefaultRowHeight * RxDBGrid.FooterOptions.RowCount));
|
||||
if Result and (ssDouble in Shift) then
|
||||
DoSetupTools;
|
||||
end;
|
||||
|
||||
constructor TRxDBGridFooterTools.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FCaption:=sRxDBGridToolsCaption;
|
||||
FToolsEvents:=[rxteMouseDown];
|
||||
ShowSetupForm:=false;
|
||||
FFooterColor:=clYellow;
|
||||
FFooterRowCount:=1;
|
||||
end;
|
||||
|
||||
destructor TRxDBGridFooterTools.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
116
RXLib/rxdb/rxdbgridfootertools_setup.lfm
Normal file
116
RXLib/rxdb/rxdbgridfootertools_setup.lfm
Normal file
@@ -0,0 +1,116 @@
|
||||
object RxDBGridFooterTools_SetupForm: TRxDBGridFooterTools_SetupForm
|
||||
Left = 789
|
||||
Height = 290
|
||||
Top = 366
|
||||
Width = 341
|
||||
Caption = 'Setup footer row'
|
||||
ClientHeight = 290
|
||||
ClientWidth = 341
|
||||
OnCreate = FormCreate
|
||||
Position = poScreenCenter
|
||||
ShowHint = True
|
||||
LCLVersion = '1.7'
|
||||
object ButtonPanel1: TButtonPanel
|
||||
Left = 6
|
||||
Height = 42
|
||||
Top = 242
|
||||
Width = 329
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
HelpButton.Name = 'HelpButton'
|
||||
HelpButton.DefaultCaption = True
|
||||
CloseButton.Name = 'CloseButton'
|
||||
CloseButton.DefaultCaption = True
|
||||
CancelButton.Name = 'CancelButton'
|
||||
CancelButton.DefaultCaption = True
|
||||
TabOrder = 0
|
||||
ShowButtons = [pbOK, pbCancel, pbHelp]
|
||||
end
|
||||
object PageControl1: TPageControl
|
||||
Left = 0
|
||||
Height = 236
|
||||
Top = 0
|
||||
Width = 341
|
||||
ActivePage = TabSheet2
|
||||
Align = alClient
|
||||
TabIndex = 1
|
||||
TabOrder = 1
|
||||
object TabSheet1: TTabSheet
|
||||
Caption = 'Functions'
|
||||
ClientHeight = 198
|
||||
ClientWidth = 335
|
||||
object StringGrid1: TStringGrid
|
||||
Left = 0
|
||||
Height = 198
|
||||
Top = 0
|
||||
Width = 335
|
||||
Align = alClient
|
||||
AutoFillColumns = True
|
||||
ColCount = 2
|
||||
Columns = <
|
||||
item
|
||||
ReadOnly = True
|
||||
Title.Alignment = taCenter
|
||||
Title.Caption = 'Collumn name'
|
||||
Width = 166
|
||||
end
|
||||
item
|
||||
PickList.Strings = (
|
||||
'fvtNon'
|
||||
'fvtSum'
|
||||
'fvtAvg'
|
||||
'fvtCount'
|
||||
'fvtFieldValue'
|
||||
'fvtStaticText'
|
||||
'fvtMax'
|
||||
'fvtMin'
|
||||
'fvtRecNo'
|
||||
)
|
||||
Title.Alignment = taCenter
|
||||
Title.Caption = 'Function'
|
||||
Width = 167
|
||||
end>
|
||||
FixedCols = 0
|
||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing, goSmoothScroll]
|
||||
TabOrder = 0
|
||||
TitleStyle = tsNative
|
||||
ColWidths = (
|
||||
166
|
||||
167
|
||||
)
|
||||
end
|
||||
end
|
||||
object TabSheet2: TTabSheet
|
||||
Caption = 'Other options'
|
||||
ClientHeight = 198
|
||||
ClientWidth = 335
|
||||
object Label1: TLabel
|
||||
AnchorSideLeft.Control = TabSheet2
|
||||
AnchorSideTop.Control = TabSheet2
|
||||
Left = 6
|
||||
Height = 20
|
||||
Top = 6
|
||||
Width = 108
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Footer row color'
|
||||
ParentColor = False
|
||||
end
|
||||
object ColorBox1: TColorBox
|
||||
AnchorSideLeft.Control = Label1
|
||||
AnchorSideTop.Control = Label1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = TabSheet2
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 12
|
||||
Height = 34
|
||||
Top = 32
|
||||
Width = 317
|
||||
Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbCustomColor, cbPrettyNames, cbCustomColors]
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
TabOrder = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
148
RXLib/rxdb/rxdbgridfootertools_setup.pas
Normal file
148
RXLib/rxdb/rxdbgridfootertools_setup.pas
Normal file
@@ -0,0 +1,148 @@
|
||||
{ RxDBGridPrintGrid unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit rxdbgridfootertools_setup;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
|
||||
ButtonPanel, ComCtrls, StdCtrls, ColorBox, rxdbgrid, rxdconst;
|
||||
|
||||
type
|
||||
|
||||
{ TRxDBGridFooterTools_SetupForm }
|
||||
|
||||
TRxDBGridFooterTools_SetupForm = class(TForm)
|
||||
ButtonPanel1: TButtonPanel;
|
||||
ColorBox1: TColorBox;
|
||||
Label1: TLabel;
|
||||
PageControl1: TPageControl;
|
||||
StringGrid1: TStringGrid;
|
||||
TabSheet1: TTabSheet;
|
||||
TabSheet2: TTabSheet;
|
||||
procedure FormCreate(Sender: TObject);
|
||||
private
|
||||
FRxDBGrid:TRxDBGrid;
|
||||
public
|
||||
procedure InitData(ARxDBGrid:TRxDBGrid);
|
||||
procedure SetData;
|
||||
end;
|
||||
|
||||
var
|
||||
RxDBGridFooterTools_SetupForm: TRxDBGridFooterTools_SetupForm;
|
||||
|
||||
const
|
||||
rxFooterFunctionNames : array [TFooterValueType] of string =
|
||||
(sfvtNon, sfvtSum, sfvtAvg, sfvtCount, sfvtFieldValue, sfvtStaticText, sfvtMax, sfvtMin, sfvtRecNo);
|
||||
implementation
|
||||
uses rxdbutils;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TRxDBGridFooterTools_SetupForm }
|
||||
|
||||
procedure TRxDBGridFooterTools_SetupForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
PageControl1.ActivePageIndex:=0;
|
||||
Caption:=sSetupTotalRow;
|
||||
TabSheet1.Caption:=sFunction;
|
||||
TabSheet2.Caption:=sOtherOptions;
|
||||
Label1.Caption:=sFooterRowColor;
|
||||
StringGrid1.Columns[0].Title.Caption:=sCollumnName;
|
||||
StringGrid1.Columns[1].Title.Caption:=sFunction;
|
||||
end;
|
||||
|
||||
procedure TRxDBGridFooterTools_SetupForm.InitData(ARxDBGrid: TRxDBGrid);
|
||||
var
|
||||
i: Integer;
|
||||
c: TFooterValueType;
|
||||
begin
|
||||
FRxDBGrid:=ARxDBGrid;
|
||||
if not Assigned(FRxDBGrid) then exit;
|
||||
StringGrid1.TitleStyle:=FRxDBGrid.TitleStyle;
|
||||
|
||||
StringGrid1.Columns[1].PickList.Clear;
|
||||
for c:=Low(TFooterValueType) to High(TFooterValueType) do
|
||||
StringGrid1.Columns[1].PickList.Add(rxFooterFunctionNames[c]);
|
||||
|
||||
|
||||
StringGrid1.RowCount:=FRxDBGrid.Columns.Count+1;
|
||||
|
||||
for i:=0 to FRxDBGrid.Columns.Count-1 do
|
||||
begin
|
||||
StringGrid1.Cells[0, i+1]:=FRxDBGrid.Columns[i].Title.Caption;
|
||||
if FRxDBGrid.Columns[i].Footer.ValueType <> fvtNon then
|
||||
StringGrid1.Cells[1, i+1]:=rxFooterFunctionNames[FRxDBGrid.Columns[i].Footer.ValueType];
|
||||
end;
|
||||
ColorBox1.Selected:=FRxDBGrid.FooterOptions.Color;
|
||||
end;
|
||||
|
||||
procedure TRxDBGridFooterTools_SetupForm.SetData;
|
||||
var
|
||||
B,C: TFooterValueType;
|
||||
Col: TRxColumn;
|
||||
i: Integer;
|
||||
begin
|
||||
for i:=1 to StringGrid1.RowCount-1 do
|
||||
begin
|
||||
Col:=FRxDBGrid.ColumnByCaption(StringGrid1.Cells[0, i]);
|
||||
B:=fvtNon;
|
||||
for c:=Low(TFooterValueType) to High(TFooterValueType) do
|
||||
if StringGrid1.Cells[1, i] = rxFooterFunctionNames[c] then
|
||||
begin
|
||||
B:=C;
|
||||
break;
|
||||
end;
|
||||
|
||||
if B<>fvtNon then
|
||||
begin
|
||||
if not (Col.Field.DataType in NumericDataTypes) then
|
||||
if not (B in [fvtCount, fvtFieldValue, fvtStaticText, fvtRecNo]) then
|
||||
B:=fvtNon;
|
||||
|
||||
if B<>fvtNon then
|
||||
begin
|
||||
Col.Footer.FieldName:=Col.FieldName;
|
||||
Col.Footer.Alignment:=Col.Alignment;
|
||||
Col.Footer.DisplayFormat:=Col.DisplayFormat;
|
||||
end;
|
||||
end;
|
||||
|
||||
Col.Footer.ValueType:=B;
|
||||
end;
|
||||
FRxDBGrid.FooterOptions.Color:=ColorBox1.Selected;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
319
RXLib/rxdb/rxdbspinedit.pas
Normal file
319
RXLib/rxdb/rxdbspinedit.pas
Normal file
@@ -0,0 +1,319 @@
|
||||
{ RxDBSpinEdit unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit RxDBSpinEdit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Spin,
|
||||
DbCtrls, DB, LMessages, LCLType, LCLVersion;
|
||||
|
||||
|
||||
type
|
||||
|
||||
{ TCustomRxDBSpinEdit }
|
||||
|
||||
TCustomRxDBSpinEdit = class(TCustomFloatSpinEdit)
|
||||
private
|
||||
FDataLink: TFieldDataLink;
|
||||
|
||||
procedure DataChange(Sender: TObject);
|
||||
function GetDataField: string;
|
||||
function GetDataSource: TDataSource;
|
||||
function GetField: TField;
|
||||
procedure SetDataField(const AValue: string);
|
||||
procedure SetDataSource(const AValue: TDataSource);
|
||||
procedure UpdateData(Sender: TObject);
|
||||
procedure FocusRequest(Sender: TObject);
|
||||
procedure ActiveChange(Sender: TObject);
|
||||
procedure LayoutChange(Sender: TObject);
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
function IsReadOnly: boolean;
|
||||
protected
|
||||
function GetReadOnly: Boolean;override;
|
||||
procedure SetReadOnly(AValue: Boolean);override;
|
||||
property DataField: string read GetDataField write SetDataField;
|
||||
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||
//property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
|
||||
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
procedure Change; override;
|
||||
|
||||
procedure Loaded; override;
|
||||
procedure Notification(AComponent: TComponent;
|
||||
Operation: TOperation); override;
|
||||
procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS;
|
||||
procedure WMKillFocus(var Message: TLMKillFocus); message LM_KILLFOCUS;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
property Field: TField read GetField;
|
||||
published
|
||||
{ Published declarations }
|
||||
end;
|
||||
|
||||
TRxDBSpinEdit = class(TCustomRxDBSpinEdit)
|
||||
published
|
||||
property DataField;
|
||||
property DataSource;
|
||||
property ReadOnly;
|
||||
|
||||
property Align;
|
||||
property Anchors;
|
||||
property AutoSelect;
|
||||
property AutoSize;
|
||||
property BorderSpacing;
|
||||
property Constraints;
|
||||
property DecimalPlaces;
|
||||
property Enabled;
|
||||
property Font;
|
||||
property Increment;
|
||||
property MaxValue;
|
||||
property MinValue;
|
||||
property OnChange;
|
||||
property OnChangeBounds;
|
||||
property OnClick;
|
||||
property OnEditingDone;
|
||||
property OnEnter;
|
||||
property OnExit;
|
||||
property OnKeyDown;
|
||||
property OnKeyPress;
|
||||
property OnKeyUp;
|
||||
property OnMouseDown;
|
||||
property OnMouseMove;
|
||||
property OnMouseUp;
|
||||
property OnMouseWheel;
|
||||
property OnMouseWheelDown;
|
||||
property OnMouseWheelUp;
|
||||
property OnResize;
|
||||
property OnUTF8KeyPress;
|
||||
property ParentFont;
|
||||
property ParentShowHint;
|
||||
property PopupMenu;
|
||||
property ShowHint;
|
||||
property TabStop;
|
||||
property TabOrder;
|
||||
property Value;
|
||||
property Visible;
|
||||
end;
|
||||
|
||||
implementation
|
||||
uses rxdbutils;
|
||||
|
||||
type
|
||||
TFieldDataLinkHack = class(TFieldDataLink)
|
||||
end;
|
||||
|
||||
{ TCustomRxDBSpinEdit }
|
||||
|
||||
procedure TCustomRxDBSpinEdit.DataChange(Sender: TObject);
|
||||
begin
|
||||
if Assigned(FDataLink.Field) and (FDataLink.Field.DataType in NumericDataTypes) then
|
||||
begin
|
||||
if (FDataLink.Field.DataType in IntegerDataTypes) then
|
||||
DecimalPlaces:=0
|
||||
else
|
||||
begin
|
||||
if FDataLink.Field.DataType = ftBCD then
|
||||
DecimalPlaces:=(FDatalink.Field as TBCDField).Precision
|
||||
else
|
||||
DecimalPlaces:=(FDatalink.Field as TFloatField).Precision;
|
||||
end;
|
||||
Value:=FDatalink.Field.AsFloat;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Text := '';
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCustomRxDBSpinEdit.GetDataField: string;
|
||||
begin
|
||||
Result := FDataLink.FieldName;
|
||||
end;
|
||||
|
||||
function TCustomRxDBSpinEdit.GetDataSource: TDataSource;
|
||||
begin
|
||||
Result := FDataLink.DataSource;
|
||||
end;
|
||||
|
||||
function TCustomRxDBSpinEdit.GetField: TField;
|
||||
begin
|
||||
Result := FDataLink.Field;
|
||||
end;
|
||||
|
||||
function TCustomRxDBSpinEdit.GetReadOnly: Boolean;
|
||||
begin
|
||||
Result := FDataLink.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.SetDataField(const AValue: string);
|
||||
begin
|
||||
FDataLink.FieldName := AValue;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.SetDataSource(const AValue: TDataSource);
|
||||
begin
|
||||
ChangeDataSource(Self,FDataLink,AValue);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.SetReadOnly(AValue: Boolean);
|
||||
begin
|
||||
inherited;
|
||||
FDataLink.ReadOnly := AValue;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.UpdateData(Sender: TObject);
|
||||
begin
|
||||
FDataLink.Field.Value := Value;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.FocusRequest(Sender: TObject);
|
||||
begin
|
||||
SetFocus;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.ActiveChange(Sender: TObject);
|
||||
begin
|
||||
if FDatalink.Active then
|
||||
DataChange(Sender)
|
||||
else
|
||||
begin
|
||||
Text := '';
|
||||
FDataLink.Reset;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.LayoutChange(Sender: TObject);
|
||||
begin
|
||||
DataChange(Sender);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.CMGetDataLink(var Message: TLMessage);
|
||||
begin
|
||||
Message.Result := PtrUInt(FDataLink);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.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_DELETE then
|
||||
begin
|
||||
if not IsReadOnly then
|
||||
FDatalink.Edit;
|
||||
end
|
||||
else
|
||||
if Key=VK_TAB then
|
||||
begin
|
||||
if FDataLink.CanModify and FDatalink.Editing then
|
||||
FDataLink.UpdateRecord;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.Change;
|
||||
begin
|
||||
FDatalink.Edit;
|
||||
FDataLink.Modified;
|
||||
inherited Change;
|
||||
end;
|
||||
|
||||
function TCustomRxDBSpinEdit.IsReadOnly: boolean;
|
||||
begin
|
||||
Result := true;
|
||||
if FDatalink.Active and (not Self.ReadOnly) then
|
||||
Result := (Field = nil) or Field.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.Loaded;
|
||||
begin
|
||||
inherited Loaded;
|
||||
if (csDesigning in ComponentState) then
|
||||
DataChange(Self);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.Notification(AComponent: TComponent;
|
||||
Operation: TOperation);
|
||||
begin
|
||||
inherited Notification(AComponent, Operation);
|
||||
if (Operation=opRemove) then
|
||||
begin
|
||||
if (FDataLink<>nil) and (AComponent=DataSource) then
|
||||
DataSource:=nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.WMSetFocus(var Message: TLMSetFocus);
|
||||
begin
|
||||
inherited WMSetFocus(Message);
|
||||
if not FDatalink.Editing then
|
||||
FDatalink.Reset;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBSpinEdit.WMKillFocus(var Message: TLMKillFocus);
|
||||
begin
|
||||
inherited WMKillFocus(Message);
|
||||
if not FDatalink.Editing then
|
||||
FDatalink.Reset
|
||||
else
|
||||
TFieldDataLinkHack(FDatalink).UpdateData;
|
||||
end;
|
||||
|
||||
constructor TCustomRxDBSpinEdit.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FDataLink := TFieldDataLink.Create;
|
||||
FDataLink.Control := Self;
|
||||
FDataLink.OnDataChange := @DataChange;
|
||||
FDataLink.OnUpdateData := @UpdateData;
|
||||
FDataLink.OnActiveChange := @ActiveChange;
|
||||
{$if (lcl_major = 0) and (lcl_release <= 30)}
|
||||
FDataLink.OnLayoutChange := @LayoutChange;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
destructor TCustomRxDBSpinEdit.Destroy;
|
||||
begin
|
||||
FreeAndNil(FDataLink);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
end.
|
324
RXLib/rxdb/rxdbtimeedit.pas
Normal file
324
RXLib/rxdb/rxdbtimeedit.pas
Normal file
@@ -0,0 +1,324 @@
|
||||
{ RxDBTimeEdit unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit RxDBTimeEdit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
RxTimeEdit, DB, DbCtrls, LMessages, LCLType;
|
||||
|
||||
type
|
||||
|
||||
{ TCustomRxDBTimeEdit }
|
||||
|
||||
TCustomRxDBTimeEdit = class(TCustomRxTimeEdit)
|
||||
private
|
||||
FDataLink: TFieldDataLink;
|
||||
|
||||
procedure DataChange(Sender: TObject);
|
||||
function GetDataField: string;
|
||||
function GetDataSource: TDataSource;
|
||||
function GetField: TField;
|
||||
procedure SetDataField(const AValue: string);
|
||||
procedure SetDataSource(const AValue: TDataSource);
|
||||
|
||||
procedure UpdateData(Sender: TObject);
|
||||
procedure FocusRequest(Sender: TObject);
|
||||
procedure ActiveChange(Sender: TObject);
|
||||
procedure LayoutChange(Sender: TObject);
|
||||
procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK;
|
||||
function IsReadOnly: boolean;
|
||||
procedure WMSetFocus(var Message: TLMSetFocus); message LM_SETFOCUS;
|
||||
procedure WMKillFocus(var Message: TLMKillFocus); message LM_KILLFOCUS;
|
||||
protected
|
||||
function GetReadOnly: Boolean;override;
|
||||
procedure SetReadOnly(AValue: Boolean);override;
|
||||
property DataField: string read GetDataField write SetDataField;
|
||||
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
procedure Change; override;
|
||||
|
||||
procedure Loaded; override;
|
||||
procedure Notification(AComponent: TComponent;
|
||||
Operation: TOperation); override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
property Field: TField read GetField;
|
||||
end;
|
||||
|
||||
TRxDBTimeEdit = class(TCustomRxDBTimeEdit)
|
||||
published
|
||||
property DataField;
|
||||
property DataSource;
|
||||
property ReadOnly;
|
||||
|
||||
property AutoSize;
|
||||
property AutoSelect;
|
||||
property Align;
|
||||
property Anchors;
|
||||
property BorderSpacing;
|
||||
property ButtonOnlyWhenFocused;
|
||||
property ButtonHint;
|
||||
property CharCase;
|
||||
property Color;
|
||||
// property DirectInput;
|
||||
property DragCursor;
|
||||
property DragMode;
|
||||
property EchoMode;
|
||||
property Enabled;
|
||||
// property Flat;
|
||||
property Font;
|
||||
// property Glyph;
|
||||
property MaxLength;
|
||||
// property NumGlyphs;
|
||||
property OnButtonClick;
|
||||
property OnChange;
|
||||
property OnClick;
|
||||
property OnDblClick;
|
||||
property OnDragDrop;
|
||||
property OnDragOver;
|
||||
property OnEditingDone;
|
||||
property OnEndDrag;
|
||||
property OnEnter;
|
||||
property OnExit;
|
||||
property OnKeyDown;
|
||||
property OnKeyPress;
|
||||
property OnKeyUp;
|
||||
property OnMouseDown;
|
||||
property OnMouseMove;
|
||||
property OnMouseUp;
|
||||
property OnMouseWheel;
|
||||
property OnMouseWheelDown;
|
||||
property OnMouseWheelUp;
|
||||
property OnStartDrag;
|
||||
property OnUTF8KeyPress;
|
||||
property ParentColor;
|
||||
property ParentFont;
|
||||
property ParentShowHint;
|
||||
property PasswordChar;
|
||||
property PopupMenu;
|
||||
property ShowHint;
|
||||
property TabOrder;
|
||||
property TabStop;
|
||||
property Visible;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
uses rxdbutils, LCLVersion;
|
||||
|
||||
type
|
||||
TFieldDataLinkHack = class(TFieldDataLink)
|
||||
end;
|
||||
|
||||
{ TCustomRxDBTimeEdit }
|
||||
|
||||
procedure TCustomRxDBTimeEdit.DataChange(Sender: TObject);
|
||||
begin
|
||||
if Assigned(FDataLink.Field) and (FDataLink.Field.DataType in DataTimeTypes) then
|
||||
Self.Time:=FDatalink.Field.AsDateTime
|
||||
else
|
||||
Text := '';
|
||||
end;
|
||||
|
||||
function TCustomRxDBTimeEdit.GetDataField: string;
|
||||
begin
|
||||
Result := FDataLink.FieldName;
|
||||
end;
|
||||
|
||||
function TCustomRxDBTimeEdit.GetDataSource: TDataSource;
|
||||
begin
|
||||
Result := FDataLink.DataSource;
|
||||
end;
|
||||
|
||||
function TCustomRxDBTimeEdit.GetField: TField;
|
||||
begin
|
||||
Result := FDataLink.Field;
|
||||
end;
|
||||
|
||||
function TCustomRxDBTimeEdit.GetReadOnly: Boolean;
|
||||
begin
|
||||
Result := FDataLink.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.SetDataField(const AValue: string);
|
||||
begin
|
||||
FDataLink.FieldName := AValue;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.SetDataSource(const AValue: TDataSource);
|
||||
begin
|
||||
ChangeDataSource(Self,FDataLink,AValue);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.SetReadOnly(AValue: Boolean);
|
||||
begin
|
||||
inherited SetReadOnly(AValue);
|
||||
FDataLink.ReadOnly := AValue;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.UpdateData(Sender: TObject);
|
||||
var
|
||||
D: Int64;
|
||||
begin
|
||||
if Assigned(FDataLink.Field) and (FDataLink.Field.DataType in DataTimeTypes) then
|
||||
begin
|
||||
D:=trunc(FDataLink.Field.AsDateTime);
|
||||
FDataLink.Field.AsDateTime := D + Self.Time;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.FocusRequest(Sender: TObject);
|
||||
begin
|
||||
SetFocus;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.ActiveChange(Sender: TObject);
|
||||
begin
|
||||
if FDatalink.Active then
|
||||
DataChange(Sender)
|
||||
else
|
||||
begin
|
||||
Text := '';
|
||||
FDataLink.Reset;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.LayoutChange(Sender: TObject);
|
||||
begin
|
||||
DataChange(Sender);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.CMGetDataLink(var Message: TLMessage);
|
||||
begin
|
||||
Message.Result := PtrUInt(FDataLink);
|
||||
end;
|
||||
|
||||
function TCustomRxDBTimeEdit.IsReadOnly: boolean;
|
||||
begin
|
||||
result := true;
|
||||
if FDatalink.Active and not Self.ReadOnly then
|
||||
result := (Field=nil) or Field.ReadOnly;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.WMSetFocus(var Message: TLMSetFocus);
|
||||
begin
|
||||
inherited WMSetFocus(Message);
|
||||
if not FDatalink.Editing then
|
||||
FDatalink.Reset;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.WMKillFocus(var Message: TLMKillFocus);
|
||||
begin
|
||||
inherited WMKillFocus(Message);
|
||||
if not FDatalink.Editing then
|
||||
FDatalink.Reset
|
||||
else
|
||||
TFieldDataLinkHack(FDatalink).UpdateData;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.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_DELETE then
|
||||
begin
|
||||
if not IsReadOnly then
|
||||
FDatalink.Edit;
|
||||
end
|
||||
else
|
||||
if Key=VK_TAB then
|
||||
begin
|
||||
if FDataLink.CanModify and FDatalink.Editing then
|
||||
FDataLink.UpdateRecord;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.Change;
|
||||
begin
|
||||
if Assigned(FDatalink) then
|
||||
begin
|
||||
//FDatalink.Edit;
|
||||
FDataLink.Modified;
|
||||
end;
|
||||
inherited Change;
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.Loaded;
|
||||
begin
|
||||
inherited Loaded;
|
||||
if (csDesigning in ComponentState) then
|
||||
DataChange(Self);
|
||||
end;
|
||||
|
||||
procedure TCustomRxDBTimeEdit.Notification(AComponent: TComponent;
|
||||
Operation: TOperation);
|
||||
begin
|
||||
inherited Notification(AComponent, Operation);
|
||||
if (Operation=opRemove) then
|
||||
begin
|
||||
if (FDataLink<>nil) and (AComponent=DataSource) then
|
||||
DataSource:=nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TCustomRxDBTimeEdit.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FDataLink := TFieldDataLink.Create;
|
||||
FDataLink.Control := Self;
|
||||
FDataLink.OnDataChange := @DataChange;
|
||||
FDataLink.OnUpdateData := @UpdateData;
|
||||
FDataLink.OnActiveChange := @ActiveChange;
|
||||
{$if (lcl_major = 0) and (lcl_release <= 30)}
|
||||
FDataLink.OnLayoutChange := @LayoutChange;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
destructor TCustomRxDBTimeEdit.Destroy;
|
||||
begin
|
||||
FreeAndNil(FDataLink);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
end.
|
1112
RXLib/rxdb/rxdbutils.pas
Normal file
1112
RXLib/rxdb/rxdbutils.pas
Normal file
File diff suppressed because it is too large
Load Diff
1709
RXLib/rxdb/rxdbverticalgrid.pas
Normal file
1709
RXLib/rxdb/rxdbverticalgrid.pas
Normal file
File diff suppressed because it is too large
Load Diff
783
RXLib/rxdb/rxfilterby.lfm
Normal file
783
RXLib/rxdb/rxfilterby.lfm
Normal file
@@ -0,0 +1,783 @@
|
||||
object rxFilterByForm: TrxFilterByForm
|
||||
Left = 464
|
||||
Height = 498
|
||||
Top = 115
|
||||
Width = 644
|
||||
Caption = 'Filter conditions'
|
||||
ClientHeight = 498
|
||||
ClientWidth = 644
|
||||
OnCreate = FormCreate
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '1.9.0.0'
|
||||
object Label1: TLabel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Owner
|
||||
Left = 6
|
||||
Height = 20
|
||||
Top = 6
|
||||
Width = 212
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Select filter expression for data'
|
||||
Font.Style = [fsBold]
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
end
|
||||
object Label2: TLabel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Label1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 20
|
||||
Top = 32
|
||||
Width = 58
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'On field:'
|
||||
Font.Color = clRed
|
||||
Font.Style = [fsBold]
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
end
|
||||
object Label3: TLabel
|
||||
AnchorSideTop.Control = Label1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 168
|
||||
Height = 20
|
||||
Top = 32
|
||||
Width = 74
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Operation :'
|
||||
Font.Color = clRed
|
||||
Font.Style = [fsBold]
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
end
|
||||
object Label4: TLabel
|
||||
AnchorSideTop.Control = Label1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 271
|
||||
Height = 20
|
||||
Top = 32
|
||||
Width = 80
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Conditions :'
|
||||
Font.Color = clRed
|
||||
Font.Style = [fsBold]
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
end
|
||||
object Label5: TLabel
|
||||
AnchorSideLeft.Control = ComboBox3
|
||||
AnchorSideTop.Control = Label1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 533
|
||||
Height = 20
|
||||
Top = 32
|
||||
Width = 65
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Operand :'
|
||||
Font.Color = clRed
|
||||
Font.Style = [fsBold]
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
end
|
||||
object Label6: TLabel
|
||||
AnchorSideLeft.Control = ComboBox3
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideBottom.Control = ComboBox25
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 527
|
||||
Height = 20
|
||||
Top = 426
|
||||
Width = 29
|
||||
Anchors = [akLeft, akBottom]
|
||||
Caption = 'End.'
|
||||
Font.Color = clRed
|
||||
Font.Style = [fsBold]
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
end
|
||||
object ComboBox1: TComboBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Label2
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 36
|
||||
Top = 58
|
||||
Width = 153
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
Style = csDropDownList
|
||||
TabOrder = 0
|
||||
end
|
||||
object ComboBox2: TComboBox
|
||||
AnchorSideTop.Control = Label2
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 168
|
||||
Height = 36
|
||||
Top = 58
|
||||
Width = 96
|
||||
BorderSpacing.Around = 6
|
||||
DropDownCount = 9
|
||||
ItemHeight = 0
|
||||
OnChange = ComboBoxChange
|
||||
Style = csDropDownList
|
||||
TabOrder = 1
|
||||
end
|
||||
object ComboBox3: TComboBox
|
||||
AnchorSideTop.Control = Label2
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 527
|
||||
Height = 32
|
||||
Top = 58
|
||||
Width = 111
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
Items.Strings = (
|
||||
'And'
|
||||
'Or'
|
||||
)
|
||||
Style = csDropDownList
|
||||
TabOrder = 2
|
||||
end
|
||||
object ComboBox4: TComboBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = ComboBox1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 8
|
||||
Height = 36
|
||||
Top = 102
|
||||
Width = 149
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Around = 2
|
||||
ItemHeight = 0
|
||||
Style = csDropDownList
|
||||
TabOrder = 3
|
||||
end
|
||||
object ComboBox5: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideTop.Control = ComboBox1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox2
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 168
|
||||
Height = 36
|
||||
Top = 100
|
||||
Width = 96
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
DropDownCount = 9
|
||||
ItemHeight = 0
|
||||
OnChange = ComboBoxChange
|
||||
Style = csDropDownList
|
||||
TabOrder = 4
|
||||
end
|
||||
object ComboBox6: TComboBox
|
||||
AnchorSideTop.Control = ComboBox1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 527
|
||||
Height = 32
|
||||
Top = 100
|
||||
Width = 111
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
Items.Strings = (
|
||||
'And'
|
||||
'Or'
|
||||
)
|
||||
Style = csDropDownList
|
||||
TabOrder = 5
|
||||
end
|
||||
object ComboBox7: TComboBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = ComboBox4
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 8
|
||||
Height = 36
|
||||
Top = 146
|
||||
Width = 149
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Around = 2
|
||||
ItemHeight = 0
|
||||
Style = csDropDownList
|
||||
TabOrder = 6
|
||||
end
|
||||
object ComboBox8: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideTop.Control = ComboBox4
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox2
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 168
|
||||
Height = 36
|
||||
Top = 144
|
||||
Width = 96
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
DropDownCount = 9
|
||||
ItemHeight = 0
|
||||
OnChange = ComboBoxChange
|
||||
Style = csDropDownList
|
||||
TabOrder = 7
|
||||
end
|
||||
object ComboBox9: TComboBox
|
||||
AnchorSideTop.Control = ComboBox4
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 527
|
||||
Height = 32
|
||||
Top = 144
|
||||
Width = 111
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
Items.Strings = (
|
||||
'And'
|
||||
'Or'
|
||||
)
|
||||
Style = csDropDownList
|
||||
TabOrder = 8
|
||||
end
|
||||
object ComboBox10: TComboBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = ComboBox7
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 8
|
||||
Height = 36
|
||||
Top = 190
|
||||
Width = 149
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Around = 2
|
||||
ItemHeight = 0
|
||||
Style = csDropDownList
|
||||
TabOrder = 9
|
||||
end
|
||||
object ComboBox11: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideTop.Control = ComboBox7
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox2
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 168
|
||||
Height = 36
|
||||
Top = 188
|
||||
Width = 96
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
DropDownCount = 9
|
||||
ItemHeight = 0
|
||||
OnChange = ComboBoxChange
|
||||
Style = csDropDownList
|
||||
TabOrder = 10
|
||||
end
|
||||
object ComboBox12: TComboBox
|
||||
AnchorSideTop.Control = ComboBox7
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 527
|
||||
Height = 32
|
||||
Top = 188
|
||||
Width = 111
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
Items.Strings = (
|
||||
'And'
|
||||
'Or'
|
||||
)
|
||||
Style = csDropDownList
|
||||
TabOrder = 11
|
||||
end
|
||||
object ComboBox13: TComboBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = ComboBox10
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 8
|
||||
Height = 36
|
||||
Top = 234
|
||||
Width = 149
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Around = 2
|
||||
ItemHeight = 0
|
||||
Style = csDropDownList
|
||||
TabOrder = 12
|
||||
end
|
||||
object ComboBox14: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideTop.Control = ComboBox10
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox2
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 168
|
||||
Height = 36
|
||||
Top = 232
|
||||
Width = 96
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
DropDownCount = 9
|
||||
ItemHeight = 0
|
||||
OnChange = ComboBoxChange
|
||||
Style = csDropDownList
|
||||
TabOrder = 13
|
||||
end
|
||||
object ComboBox15: TComboBox
|
||||
AnchorSideTop.Control = ComboBox10
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 527
|
||||
Height = 32
|
||||
Top = 232
|
||||
Width = 111
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
Items.Strings = (
|
||||
'And'
|
||||
'Or'
|
||||
)
|
||||
Style = csDropDownList
|
||||
TabOrder = 14
|
||||
end
|
||||
object ComboBox16: TComboBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = ComboBox13
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 8
|
||||
Height = 36
|
||||
Top = 278
|
||||
Width = 149
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Around = 2
|
||||
ItemHeight = 0
|
||||
Style = csDropDownList
|
||||
TabOrder = 15
|
||||
end
|
||||
object ComboBox17: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideTop.Control = ComboBox13
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox2
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 168
|
||||
Height = 36
|
||||
Top = 276
|
||||
Width = 96
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
DropDownCount = 9
|
||||
ItemHeight = 0
|
||||
OnChange = ComboBoxChange
|
||||
Style = csDropDownList
|
||||
TabOrder = 16
|
||||
end
|
||||
object ComboBox18: TComboBox
|
||||
AnchorSideTop.Control = ComboBox13
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 527
|
||||
Height = 32
|
||||
Top = 276
|
||||
Width = 111
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
Items.Strings = (
|
||||
'And'
|
||||
'Or'
|
||||
)
|
||||
Style = csDropDownList
|
||||
TabOrder = 17
|
||||
end
|
||||
object ComboBox19: TComboBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = ComboBox16
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 8
|
||||
Height = 36
|
||||
Top = 322
|
||||
Width = 149
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Around = 2
|
||||
ItemHeight = 0
|
||||
Style = csDropDownList
|
||||
TabOrder = 18
|
||||
end
|
||||
object ComboBox20: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideTop.Control = ComboBox16
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox2
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 168
|
||||
Height = 36
|
||||
Top = 320
|
||||
Width = 96
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
DropDownCount = 9
|
||||
ItemHeight = 0
|
||||
OnChange = ComboBoxChange
|
||||
Style = csDropDownList
|
||||
TabOrder = 19
|
||||
end
|
||||
object ComboBox21: TComboBox
|
||||
AnchorSideTop.Control = ComboBox16
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 527
|
||||
Height = 32
|
||||
Top = 320
|
||||
Width = 111
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
Items.Strings = (
|
||||
'And'
|
||||
'Or'
|
||||
)
|
||||
Style = csDropDownList
|
||||
TabOrder = 20
|
||||
end
|
||||
object ComboBox22: TComboBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = ComboBox19
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 8
|
||||
Height = 36
|
||||
Top = 366
|
||||
Width = 149
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Around = 2
|
||||
ItemHeight = 0
|
||||
Style = csDropDownList
|
||||
TabOrder = 21
|
||||
end
|
||||
object ComboBox23: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideTop.Control = ComboBox19
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox2
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 168
|
||||
Height = 36
|
||||
Top = 364
|
||||
Width = 96
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
DropDownCount = 9
|
||||
ItemHeight = 0
|
||||
OnChange = ComboBoxChange
|
||||
Style = csDropDownList
|
||||
TabOrder = 22
|
||||
end
|
||||
object ComboBox24: TComboBox
|
||||
AnchorSideTop.Control = ComboBox19
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 527
|
||||
Height = 32
|
||||
Top = 364
|
||||
Width = 111
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
Items.Strings = (
|
||||
'And'
|
||||
'Or'
|
||||
)
|
||||
Style = csDropDownList
|
||||
TabOrder = 23
|
||||
end
|
||||
object ComboBox25: TComboBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = ComboBox22
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 8
|
||||
Height = 36
|
||||
Top = 410
|
||||
Width = 149
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Around = 2
|
||||
ItemHeight = 0
|
||||
Style = csDropDownList
|
||||
TabOrder = 24
|
||||
end
|
||||
object ComboBox26: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideTop.Control = ComboBox22
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox2
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 168
|
||||
Height = 36
|
||||
Top = 408
|
||||
Width = 96
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
DropDownCount = 9
|
||||
ItemHeight = 0
|
||||
OnChange = ComboBoxChange
|
||||
Style = csDropDownList
|
||||
TabOrder = 25
|
||||
end
|
||||
object ComboBox27: TComboBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 32
|
||||
Top = 460
|
||||
Width = 58
|
||||
Anchors = [akLeft, akBottom]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
Items.Strings = (
|
||||
'And'
|
||||
'Or'
|
||||
)
|
||||
Style = csDropDownList
|
||||
TabOrder = 26
|
||||
Visible = False
|
||||
end
|
||||
object Button1: TButton
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 586
|
||||
Height = 36
|
||||
Top = 456
|
||||
Width = 52
|
||||
Anchors = [akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Apply'
|
||||
Default = True
|
||||
OnClick = Button1Click
|
||||
TabOrder = 27
|
||||
end
|
||||
object Button2: TButton
|
||||
AnchorSideRight.Control = Button1
|
||||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 521
|
||||
Height = 36
|
||||
Top = 456
|
||||
Width = 59
|
||||
Anchors = [akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Cancel = True
|
||||
Caption = 'Cancel'
|
||||
OnClick = Button2Click
|
||||
TabOrder = 28
|
||||
end
|
||||
object Button3: TButton
|
||||
AnchorSideRight.Control = Button2
|
||||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 432
|
||||
Height = 36
|
||||
Top = 456
|
||||
Width = 83
|
||||
Anchors = [akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Clear filter'
|
||||
OnClick = Button3Click
|
||||
TabOrder = 29
|
||||
end
|
||||
object Edit1: TComboBox
|
||||
AnchorSideTop.Control = Label2
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox3
|
||||
Left = 271
|
||||
Height = 37
|
||||
Top = 58
|
||||
Width = 250
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
OnChange = EditChange
|
||||
TabOrder = 30
|
||||
end
|
||||
object Edit2: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = ComboBox1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox3
|
||||
Left = 270
|
||||
Height = 37
|
||||
Top = 100
|
||||
Width = 251
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
ItemHeight = 0
|
||||
OnChange = EditChange
|
||||
TabOrder = 31
|
||||
end
|
||||
object Edit3: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = ComboBox4
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox3
|
||||
Left = 270
|
||||
Height = 37
|
||||
Top = 144
|
||||
Width = 251
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
ItemHeight = 0
|
||||
OnChange = EditChange
|
||||
TabOrder = 32
|
||||
end
|
||||
object Edit4: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = ComboBox7
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox3
|
||||
Left = 270
|
||||
Height = 37
|
||||
Top = 188
|
||||
Width = 251
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
ItemHeight = 0
|
||||
OnChange = EditChange
|
||||
TabOrder = 33
|
||||
end
|
||||
object Edit5: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = ComboBox10
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox3
|
||||
Left = 270
|
||||
Height = 37
|
||||
Top = 232
|
||||
Width = 251
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
ItemHeight = 0
|
||||
OnChange = EditChange
|
||||
TabOrder = 34
|
||||
end
|
||||
object Edit6: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = ComboBox13
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox3
|
||||
Left = 270
|
||||
Height = 37
|
||||
Top = 276
|
||||
Width = 251
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
ItemHeight = 0
|
||||
OnChange = EditChange
|
||||
TabOrder = 35
|
||||
end
|
||||
object Edit7: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = ComboBox16
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox3
|
||||
Left = 270
|
||||
Height = 37
|
||||
Top = 320
|
||||
Width = 251
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
ItemHeight = 0
|
||||
OnChange = EditChange
|
||||
TabOrder = 36
|
||||
end
|
||||
object Edit8: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = ComboBox19
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox3
|
||||
Left = 270
|
||||
Height = 37
|
||||
Top = 364
|
||||
Width = 251
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
ItemHeight = 0
|
||||
OnChange = EditChange
|
||||
TabOrder = 37
|
||||
end
|
||||
object Edit9: TComboBox
|
||||
AnchorSideLeft.Control = ComboBox2
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = ComboBox22
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = ComboBox3
|
||||
Left = 270
|
||||
Height = 37
|
||||
Top = 408
|
||||
Width = 251
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 6
|
||||
ItemHeight = 0
|
||||
OnChange = EditChange
|
||||
TabOrder = 38
|
||||
end
|
||||
end
|
408
RXLib/rxdb/rxfilterby.pas
Normal file
408
RXLib/rxdb/rxfilterby.pas
Normal file
@@ -0,0 +1,408 @@
|
||||
{ rxfilterby unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit rxfilterby;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, rxdbgrid, LResources, Forms, Controls, Graphics,
|
||||
Dialogs, StdCtrls, db;
|
||||
|
||||
type
|
||||
|
||||
{ TrxFilterByForm }
|
||||
|
||||
TrxFilterByForm = class(TForm)
|
||||
Button1: TButton;
|
||||
Button2: TButton;
|
||||
Button3: TButton;
|
||||
ComboBox1: TComboBox;
|
||||
ComboBox10: TComboBox;
|
||||
ComboBox11: TComboBox;
|
||||
ComboBox12: TComboBox;
|
||||
ComboBox13: TComboBox;
|
||||
ComboBox14: TComboBox;
|
||||
ComboBox15: TComboBox;
|
||||
ComboBox16: TComboBox;
|
||||
ComboBox17: TComboBox;
|
||||
ComboBox18: TComboBox;
|
||||
ComboBox19: TComboBox;
|
||||
ComboBox2: TComboBox;
|
||||
ComboBox20: TComboBox;
|
||||
ComboBox21: TComboBox;
|
||||
ComboBox22: TComboBox;
|
||||
ComboBox23: TComboBox;
|
||||
ComboBox24: TComboBox;
|
||||
ComboBox25: TComboBox;
|
||||
ComboBox26: TComboBox;
|
||||
ComboBox27: TComboBox;
|
||||
ComboBox3: TComboBox;
|
||||
ComboBox4: TComboBox;
|
||||
ComboBox5: TComboBox;
|
||||
ComboBox6: TComboBox;
|
||||
ComboBox7: TComboBox;
|
||||
ComboBox8: TComboBox;
|
||||
ComboBox9: TComboBox;
|
||||
Edit1: TComboBox;
|
||||
Edit2: TComboBox;
|
||||
Edit3: TComboBox;
|
||||
Edit4: TComboBox;
|
||||
Edit5: TComboBox;
|
||||
Edit6: TComboBox;
|
||||
Edit7: TComboBox;
|
||||
Edit8: TComboBox;
|
||||
Edit9: TComboBox;
|
||||
Label1: TLabel;
|
||||
Label2: TLabel;
|
||||
Label3: TLabel;
|
||||
Label4: TLabel;
|
||||
Label5: TLabel;
|
||||
Label6: TLabel;
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure Button2Click(Sender: TObject);
|
||||
procedure Button3Click(Sender: TObject);
|
||||
procedure ComboBoxChange(Sender: TObject);
|
||||
procedure EditChange(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
private
|
||||
Combo_1 : Array[1..9] of TComboBox;
|
||||
Combo_2 : Array[1..9] of TComboBox;
|
||||
Edit_1 : Array[1..9] of TComboBox;
|
||||
Combo_3 : Array[1..9] of TComboBox;
|
||||
|
||||
FGrid : TRxDBGrid;
|
||||
procedure ClearALL(AGrid : TRxDBGrid);
|
||||
function FindCombo(CB:TComboBox):Integer;
|
||||
function FindEdit(ED: TComboBox): Integer;
|
||||
public
|
||||
function Execute(AGrid : TRxDBGrid; var FilterStr : String; var LastFilter : TstringList):Boolean;
|
||||
end;
|
||||
|
||||
var
|
||||
rxFilterByForm: TrxFilterByForm;
|
||||
|
||||
implementation
|
||||
uses rxdconst, rxstrutils, DBGrids;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TrxFilterByForm }
|
||||
|
||||
procedure TrxFilterByForm.Button2Click(Sender: TObject);
|
||||
begin
|
||||
ModalResult := mrCancel;
|
||||
end;
|
||||
|
||||
procedure TrxFilterByForm.Button3Click(Sender: TObject);
|
||||
begin
|
||||
ClearALL(FGrid);
|
||||
end;
|
||||
|
||||
procedure TrxFilterByForm.ComboBoxChange(Sender: TObject);
|
||||
var
|
||||
CBN : Integer;
|
||||
CB : TComboBox;
|
||||
begin
|
||||
CB := (Sender AS TComboBox);
|
||||
CBN := FindCombo(CB);
|
||||
if CBN=0 Then Exit;
|
||||
if (CB.Text=' IS NULL ') Or (CB.Text=' IS NOT NULL ') Then
|
||||
begin
|
||||
Edit_1[CBN].Text := '';
|
||||
Edit_1[CBN].Enabled := False;
|
||||
Edit_1[CBN].Color := clInactiveCaption;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Edit_1[CBN].Enabled := True;
|
||||
Edit_1[CBN].Color := clWindow;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TrxFilterByForm.EditChange(Sender: TObject);
|
||||
var
|
||||
EDN : Integer;
|
||||
ED : TComboBox;
|
||||
begin
|
||||
ED := (Sender AS TComboBox);
|
||||
EDN := FindEdit(ED);
|
||||
if EDN=0 Then Exit;
|
||||
if ED.Text='' Then Combo_1[EDN].ItemIndex:=-1;
|
||||
end;
|
||||
|
||||
procedure TrxFilterByForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
Label1.Caption:=sRxFilterFormSelectExp;
|
||||
Label2.Caption:=sRxFilterFormOnField;
|
||||
Label3.Caption:=sRxFilterFormOperaion;
|
||||
Label4.Caption:=sRxFilterFormCondition;
|
||||
Label5.Caption:=sRxFilterFormOperand;
|
||||
Label6.Caption:=sRxFilterFormEnd;
|
||||
Button3.Caption:=sRxFilterFormClear;
|
||||
Button2.Caption:=sRxFilterFormCancel;
|
||||
Button1.Caption:=sRxFilterFormApply;
|
||||
end;
|
||||
|
||||
procedure TrxFilterByForm.Button1Click(Sender: TObject);
|
||||
begin
|
||||
ModalResult := mrOK;
|
||||
end;
|
||||
|
||||
procedure TrxFilterByForm.ClearALL(AGrid: TRxDBGrid);
|
||||
var
|
||||
i , wsb, w, wt: Integer;
|
||||
begin
|
||||
//*****************************************************************************
|
||||
Combo_1[1].Items.Clear;
|
||||
Combo_1[1].Items.Add('');
|
||||
|
||||
wsb:= 30; //ширина скроллбара
|
||||
w := Combo_1[1].Width - wsb;
|
||||
for i := 0 To AGrid.Columns.Count-1 do
|
||||
begin
|
||||
if Assigned(AGrid.Columns[i].Field) and (AGrid.Columns[i].Field.FieldKind=fkData) and (AGrid.Columns[i].Visible) then
|
||||
begin
|
||||
Combo_1[1].Items.AddObject(AGrid.Columns[i].Title.Caption, AGrid.Columns[i].Field);
|
||||
Edit_1[1].Items.AddObject(AGrid.Columns[i].Title.Caption, AGrid.Columns[i].Field);
|
||||
|
||||
wt := Canvas.TextWidth(AGrid.Columns[i].Title.Caption);
|
||||
if wt > w then
|
||||
w := wt;
|
||||
end;
|
||||
end;
|
||||
|
||||
Combo_1[1].ItemIndex := 0;
|
||||
Combo_1[1].ItemWidth := w + wsb;
|
||||
|
||||
for i := 2 To 9 do
|
||||
begin
|
||||
Combo_1[i].Items.Assign(Combo_1[1].Items);
|
||||
Combo_1[i].ItemIndex := 0;
|
||||
Combo_1[i].ItemWidth := w + wsb;
|
||||
end;
|
||||
|
||||
Combo_2[1].Items.Clear;
|
||||
Combo_2[1].Items.Add(' = ');
|
||||
Combo_2[1].Items.Add(' > ');
|
||||
Combo_2[1].Items.Add(' < ');
|
||||
Combo_2[1].Items.Add(' >= ');
|
||||
Combo_2[1].Items.Add(' <= ');
|
||||
Combo_2[1].Items.Add(' <> ');
|
||||
Combo_2[1].Items.Add(' LIKE ');
|
||||
Combo_2[1].Items.Add(' IS NULL ');
|
||||
Combo_2[1].Items.Add(' IS NOT NULL ');
|
||||
Combo_2[1].ItemIndex := 0;
|
||||
for i := 2 To 9 do
|
||||
begin
|
||||
Combo_2[i].Items.Assign(Combo_2[1].Items);
|
||||
Combo_2[i].ItemIndex := 0;
|
||||
end;
|
||||
for i := 1 To 9 do
|
||||
begin
|
||||
Combo_3[i].ItemIndex := 0;
|
||||
end;
|
||||
for i := 1 To 9 do Edit_1[i].Text := '';
|
||||
//*****************************************************************************
|
||||
end;
|
||||
|
||||
function TrxFilterByForm.Execute(AGrid: TRxDBGrid; var FilterStr: String;
|
||||
var LastFilter: TstringList): Boolean;
|
||||
var
|
||||
X : Integer;
|
||||
P : Integer;
|
||||
S, S1 : String;
|
||||
SD : String;
|
||||
C : TColumn;
|
||||
C1: TRxColumn;
|
||||
begin
|
||||
Result := False;
|
||||
//*****************************************************************************
|
||||
Combo_1[1]:= ComboBox1;
|
||||
Combo_1[2]:= ComboBox4;
|
||||
Combo_1[3]:= ComboBox7;
|
||||
Combo_1[4]:= ComboBox10;
|
||||
Combo_1[5]:= ComboBox13;
|
||||
Combo_1[6]:= ComboBox16;
|
||||
Combo_1[7]:= ComboBox19;
|
||||
Combo_1[8]:= ComboBox22;
|
||||
Combo_1[9]:= ComboBox25;
|
||||
|
||||
Combo_2[1]:= ComboBox2;
|
||||
Combo_2[2]:= ComboBox5;
|
||||
Combo_2[3]:= ComboBox8;
|
||||
Combo_2[4]:= ComboBox11;
|
||||
Combo_2[5]:= ComboBox14;
|
||||
Combo_2[6]:= ComboBox17;
|
||||
Combo_2[7]:= ComboBox20;
|
||||
Combo_2[8]:= ComboBox23;
|
||||
Combo_2[9]:= ComboBox26;
|
||||
|
||||
Combo_3[1]:= ComboBox3;
|
||||
Combo_3[2]:= ComboBox6;
|
||||
Combo_3[3]:= ComboBox9;
|
||||
Combo_3[4]:= ComboBox12;
|
||||
Combo_3[5]:= ComboBox15;
|
||||
Combo_3[6]:= ComboBox18;
|
||||
Combo_3[7]:= ComboBox21;
|
||||
Combo_3[8]:= ComboBox24;
|
||||
Combo_3[9]:= ComboBox27;
|
||||
Combo_3[9].Visible := False;
|
||||
|
||||
Edit_1[1] := Edit1;
|
||||
Edit_1[2] := Edit2;
|
||||
Edit_1[3] := Edit3;
|
||||
Edit_1[4] := Edit4;
|
||||
Edit_1[5] := Edit5;
|
||||
Edit_1[6] := Edit6;
|
||||
Edit_1[7] := Edit7;
|
||||
Edit_1[8] := Edit8;
|
||||
Edit_1[9] := Edit9;
|
||||
|
||||
//*****************************************************************************
|
||||
FGrid := AGrid;
|
||||
ClearALL(FGrid);
|
||||
if LastFilter.Count > 0 Then
|
||||
begin
|
||||
for X := 0 To LastFilter.Count-1 do
|
||||
begin
|
||||
S := LastFilter.Strings[X];
|
||||
P := Pos('|||',S);
|
||||
if P > 0 Then
|
||||
begin
|
||||
S1:=System.Copy(S,1,P-1);
|
||||
C:=FGrid.ColumnByFieldName(S1);
|
||||
Combo_1[X+1].ItemIndex := Combo_1[X+1].Items.IndexOf(C.Title.Caption);
|
||||
System.Delete(S,1,P+2);
|
||||
end;
|
||||
|
||||
P := Pos('|||',S);
|
||||
if P > 0 Then
|
||||
begin
|
||||
SD:=System.Copy(S,1,P-1);
|
||||
Combo_2[X+1].ItemIndex := Combo_2[X+1].Items.IndexOf(System.Copy(S,1,P-1));
|
||||
System.Delete(S,1,P+2);
|
||||
if (SD=' IS NULL ') or (SD=' IS NOT NULL ') Then
|
||||
Begin
|
||||
Edit_1[X+1].Text:= '';
|
||||
Edit_1[X+1].Enabled := False;
|
||||
Edit_1[X+1].Color := clInactiveCaption;
|
||||
End;
|
||||
end;
|
||||
|
||||
P := Pos('|||',S);
|
||||
if P > 0 then
|
||||
begin
|
||||
Edit_1[X+1].Text := System.Copy(S,1,P-1);
|
||||
System.Delete(S,1,P+2);
|
||||
end;
|
||||
Combo_3[X+1].ItemIndex := Combo_3[X+1].Items.IndexOf(S);
|
||||
|
||||
if Combo_3[X+1].ItemIndex = -1 Then Combo_3[X+1].ItemIndex := 0;
|
||||
end;
|
||||
end;
|
||||
|
||||
if ShowModal = mrOK Then
|
||||
begin
|
||||
Result := True;
|
||||
FilterStr := '';
|
||||
LastFilter.Clear;
|
||||
for X := 1 to 9 Do
|
||||
begin
|
||||
if (Combo_1[X].Text <> '') and (Combo_2[X].Text <> '') then
|
||||
begin
|
||||
if (Edit_1[X].Enabled=False) or (Edit_1[X].Text <> '') Then
|
||||
begin
|
||||
if X>1 Then
|
||||
FilterStr := FilterStr+Combo_3[X-1].Text+' ';
|
||||
|
||||
C:=FGrid.ColumnByCaption(Combo_1[X].Text);
|
||||
|
||||
if Edit_1[X].Items.IndexOf(Edit_1[X].Text)>-1 then
|
||||
begin
|
||||
C1:=FGrid.ColumnByCaption(Edit_1[X].Text);
|
||||
FilterStr := FilterStr+'('+C.FieldName+Combo_2[X].Text+C1.FieldName+') ';
|
||||
end
|
||||
else
|
||||
if Pos('NULL', Combo_2[X].Text) > 0 then
|
||||
FilterStr := FilterStr+'('+C.FieldName+Combo_2[X].Text+') '
|
||||
else
|
||||
case C.Field.DataType of
|
||||
ftDateTime ,
|
||||
ftDate : FilterStr := FilterStr+'('+C.FieldName+Combo_2[X].Text+Char(39)+Copy(Edit_1[X].Text,7,4)+Copy(Edit_1[X].Text,3,4)+Copy(Edit_1[X].Text,1,2)+Copy(Edit_1[X].Text,11,9)+Char(39)+') ';
|
||||
ftUnknown : FilterStr := FilterStr+'('+C.FieldName+Combo_2[X].Text+Edit_1[X].Text+') ';
|
||||
ftTime,
|
||||
ftString,
|
||||
ftMemo : FilterStr := FilterStr+'('+C.FieldName+Combo_2[X].Text+QuotedString(Edit_1[X].Text, '''')+') ';
|
||||
else
|
||||
FilterStr := FilterStr+'('+C.FieldName+Combo_2[X].Text+Edit_1[X].Text+') ';
|
||||
end;
|
||||
LastFilter.Add(C.FieldName+'|||'+Combo_2[X].Text+'|||'+Edit_1[X].Text+'|||'+Combo_3[X].Text);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Function TrxFilterByForm.FindCombo(CB:TComboBox):Integer;
|
||||
var
|
||||
X : Integer;
|
||||
begin
|
||||
Result :=0;
|
||||
for X := 1 to 9 do
|
||||
begin
|
||||
if Combo_2[X]=CB Then
|
||||
begin
|
||||
Result := X;
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TrxFilterByForm.FindEdit(ED:TComboBox):Integer;
|
||||
var
|
||||
X : Integer;
|
||||
begin
|
||||
Result :=0;
|
||||
for X := 1 to 9 do
|
||||
begin
|
||||
if Edit_1[X]=ED then
|
||||
begin
|
||||
Result := X;
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
1906
RXLib/rxdb/rxlookup.pas
Normal file
1906
RXLib/rxdb/rxlookup.pas
Normal file
File diff suppressed because it is too large
Load Diff
2146
RXLib/rxdb/rxmemds.pas
Normal file
2146
RXLib/rxdb/rxmemds.pas
Normal file
File diff suppressed because it is too large
Load Diff
1003
RXLib/rxdb/rxpopupunit.pas
Normal file
1003
RXLib/rxdb/rxpopupunit.pas
Normal file
File diff suppressed because it is too large
Load Diff
74
RXLib/rxdb/rxseldsfrm.lfm
Normal file
74
RXLib/rxdb/rxseldsfrm.lfm
Normal file
@@ -0,0 +1,74 @@
|
||||
object SelectDataSetForm: TSelectDataSetForm
|
||||
Left = 445
|
||||
Height = 315
|
||||
Top = 197
|
||||
Width = 400
|
||||
ActiveControl = CheckBox1
|
||||
Caption = 'Select dataset to copy to'
|
||||
ClientHeight = 315
|
||||
ClientWidth = 400
|
||||
OnCreate = FormCreate
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '1.3'
|
||||
object Label1: TLabel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = CheckBox1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 21
|
||||
Top = 35
|
||||
Width = 98
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Sourse dataset'
|
||||
FocusControl = DataSetList
|
||||
ParentColor = False
|
||||
end
|
||||
object CheckBox1: TCheckBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Owner
|
||||
Left = 6
|
||||
Height = 23
|
||||
Top = 6
|
||||
Width = 154
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Copy only metadata'
|
||||
OnChange = CheckBox1Change
|
||||
TabOrder = 0
|
||||
end
|
||||
object DataSetList: TListBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Label1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = ButtonPanel1
|
||||
Left = 6
|
||||
Height = 200
|
||||
Top = 62
|
||||
Width = 388
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
OnDblClick = ListBox1DblClick
|
||||
OnKeyPress = ListBox1KeyPress
|
||||
ScrollWidth = 386
|
||||
TabOrder = 1
|
||||
TopIndex = -1
|
||||
end
|
||||
object ButtonPanel1: TButtonPanel
|
||||
Left = 6
|
||||
Height = 41
|
||||
Top = 268
|
||||
Width = 388
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
HelpButton.Name = 'HelpButton'
|
||||
HelpButton.DefaultCaption = True
|
||||
CloseButton.Name = 'CloseButton'
|
||||
CloseButton.DefaultCaption = True
|
||||
CancelButton.Name = 'CancelButton'
|
||||
CancelButton.DefaultCaption = True
|
||||
TabOrder = 2
|
||||
ShowButtons = [pbOK, pbCancel, pbHelp]
|
||||
end
|
||||
end
|
292
RXLib/rxdb/rxseldsfrm.pas
Normal file
292
RXLib/rxdb/rxseldsfrm.pas
Normal file
@@ -0,0 +1,292 @@
|
||||
{ seldsfrm unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit rxseldsfrm;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
||||
Buttons, ComponentEditors, DB, ButtonPanel;
|
||||
|
||||
type
|
||||
|
||||
{ TSelectDataSetForm }
|
||||
|
||||
TSelectDataSetForm = class(TForm)
|
||||
ButtonPanel1: TButtonPanel;
|
||||
CheckBox1: TCheckBox;
|
||||
Label1: TLabel;
|
||||
DataSetList: TListBox;
|
||||
procedure CheckBox1Change(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure ListBox1DblClick(Sender: TObject);
|
||||
procedure ListBox1KeyPress(Sender: TObject; var Key: char);
|
||||
private
|
||||
FDesigner: TComponentEditorDesigner;
|
||||
FExclude: string;
|
||||
procedure FillDataSetList(ExcludeDataSet: TDataSet);
|
||||
procedure AddDataSet(const S: string);
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
{ TMemDataSetEditor }
|
||||
|
||||
TMemDataSetEditor = class(TComponentEditor)
|
||||
private
|
||||
DefaultEditor: TBaseComponentEditor;
|
||||
function UniqueName(Field: TField): string;
|
||||
procedure BorrowStructure;
|
||||
protected
|
||||
function CopyStructure(Source, Dest: TDataSet): Boolean; virtual;
|
||||
public
|
||||
constructor Create(AComponent: TComponent; ADesigner: TComponentEditorDesigner); override;
|
||||
destructor Destroy; override;
|
||||
procedure ExecuteVerb(Index: Integer); override;
|
||||
function GetVerb(Index: Integer): string; override;
|
||||
function GetVerbCount: Integer; override;
|
||||
end;
|
||||
|
||||
function SelectDataSet(ADesigner: TComponentEditorDesigner; const ACaption: string;
|
||||
ExcludeDataSet: TDataSet): TDataSet;
|
||||
|
||||
var
|
||||
SelectDataSetForm: TSelectDataSetForm;
|
||||
|
||||
implementation
|
||||
uses rxmemds, rxdconst;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
function SelectDataSet(ADesigner: TComponentEditorDesigner; const ACaption: string;
|
||||
ExcludeDataSet: TDataSet): TDataSet;
|
||||
begin
|
||||
Result := nil;
|
||||
with TSelectDataSetForm.Create(Application) do
|
||||
try
|
||||
if ACaption <> '' then Caption := ACaption;
|
||||
FDesigner := ADesigner;
|
||||
FillDataSetList(ExcludeDataSet);
|
||||
if ShowModal = mrOk then
|
||||
if DataSetList.ItemIndex >= 0 then
|
||||
begin
|
||||
with DataSetList do
|
||||
Result := FDesigner.Form.FindComponent(Items[ItemIndex]) as TDataSet;
|
||||
end;
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TSelectDataSetForm }
|
||||
|
||||
procedure TSelectDataSetForm.CheckBox1Change(Sender: TObject);
|
||||
begin
|
||||
Label1.Enabled:=not CheckBox1.Checked;
|
||||
DataSetList.Enabled:=not CheckBox1.Checked;
|
||||
end;
|
||||
|
||||
procedure TSelectDataSetForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
Caption:=sRxSelectDatasetStruct;
|
||||
CheckBox1.Caption:=sRxCopyOnlyMetadata;
|
||||
Label1.Caption:=sRxSourceDataset;
|
||||
end;
|
||||
|
||||
procedure TSelectDataSetForm.ListBox1DblClick(Sender: TObject);
|
||||
begin
|
||||
if DataSetList.ItemIndex >= 0 then ModalResult := mrOk;
|
||||
end;
|
||||
|
||||
procedure TSelectDataSetForm.ListBox1KeyPress(Sender: TObject; var Key: char);
|
||||
begin
|
||||
if (Key = #13) and (DataSetList.ItemIndex >= 0) then
|
||||
ModalResult := mrOk;
|
||||
end;
|
||||
|
||||
procedure TSelectDataSetForm.FillDataSetList(ExcludeDataSet: TDataSet);
|
||||
var
|
||||
I: Integer;
|
||||
Component: TComponent;
|
||||
begin
|
||||
DataSetList.Items.BeginUpdate;
|
||||
try
|
||||
DataSetList.Clear;
|
||||
FExclude := '';
|
||||
if ExcludeDataSet <> nil then FExclude := ExcludeDataSet.Name;
|
||||
for I := 0 to FDesigner.Form.ComponentCount - 1 do
|
||||
begin
|
||||
Component := FDesigner.Form.Components[I];
|
||||
if (Component is TDataSet) and (Component <> ExcludeDataSet) then
|
||||
AddDataSet(Component.Name);
|
||||
end;
|
||||
with DataSetList do
|
||||
begin
|
||||
if Items.Count > 0 then ItemIndex := 0;
|
||||
Enabled := Items.Count > 0;
|
||||
ButtonPanel1.OKButton.Enabled:= (ItemIndex >= 0);
|
||||
end;
|
||||
finally
|
||||
DataSetList.Items.EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSelectDataSetForm.AddDataSet(const S: string);
|
||||
begin
|
||||
if (S <> '') and (S <> FExclude) then DataSetList.Items.Add(S);
|
||||
end;
|
||||
|
||||
{ TMemDataSetEditor }
|
||||
|
||||
function TMemDataSetEditor.UniqueName(Field: TField): string;
|
||||
const
|
||||
AlphaNumeric = ['A'..'Z', 'a'..'z', '_'] + ['0'..'9'];
|
||||
var
|
||||
Temp: string;
|
||||
Comp: TComponent;
|
||||
I: Integer;
|
||||
begin
|
||||
Result := '';
|
||||
if (Field <> nil) then begin
|
||||
Temp := Field.FieldName;
|
||||
for I := Length(Temp) downto 1 do
|
||||
if not (Temp[I] in AlphaNumeric) then System.Delete(Temp, I, 1);
|
||||
if (Temp = '') or not IsValidIdent(Temp) then begin
|
||||
Temp := Field.ClassName;
|
||||
if (UpCase(Temp[1]) = 'T') and (Length(Temp) > 1) then
|
||||
System.Delete(Temp, 1, 1);
|
||||
end;
|
||||
end
|
||||
else Exit;
|
||||
Temp := Component.Name + Temp;
|
||||
I := 0;
|
||||
repeat
|
||||
Result := Temp;
|
||||
if I > 0 then Result := Result + IntToStr(I);
|
||||
Comp := Designer.Form.FindComponent(Result);
|
||||
Inc(I);
|
||||
until (Comp = nil) or (Comp = Field);
|
||||
end;
|
||||
|
||||
procedure TMemDataSetEditor.BorrowStructure;
|
||||
var
|
||||
DataSet: TDataSet;
|
||||
I: Integer;
|
||||
Caption: string;
|
||||
begin
|
||||
Caption := Component.Name;
|
||||
if (Component.Owner <> nil) and (Component.Owner.Name <> '') then
|
||||
Caption := Format('%s.%s', [Component.Owner.Name, Caption]);
|
||||
DataSet := SelectDataSet(Designer, Caption, TDataSet(Component));
|
||||
if DataSet <> nil then
|
||||
begin
|
||||
// StartWait;
|
||||
try
|
||||
if not CopyStructure(DataSet, Component as TDataSet) then Exit;
|
||||
with TDataSet(Component) do
|
||||
begin
|
||||
for I := 0 to FieldCount - 1 do
|
||||
if Fields[I].Name = '' then
|
||||
Fields[I].Name := UniqueName(Fields[I]);
|
||||
end;
|
||||
Modified;
|
||||
finally
|
||||
// StopWait;
|
||||
end;
|
||||
Designer.Modified;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TMemDataSetEditor.CopyStructure(Source, Dest: TDataSet): Boolean;
|
||||
begin
|
||||
Result := Dest is TRxMemoryData;
|
||||
if Result then
|
||||
TRxMemoryData(Dest).CopyStructure(Source);
|
||||
end;
|
||||
|
||||
type
|
||||
PClass = ^TClass;
|
||||
|
||||
constructor TMemDataSetEditor.Create(AComponent: TComponent;
|
||||
ADesigner: TComponentEditorDesigner);
|
||||
var
|
||||
CompClass: TClass;
|
||||
begin
|
||||
inherited Create(AComponent, ADesigner);
|
||||
CompClass := PClass(Acomponent)^;
|
||||
try
|
||||
PClass(AComponent)^ := TDataSet;
|
||||
DefaultEditor := GetComponentEditor(AComponent, ADesigner);
|
||||
finally
|
||||
PClass(AComponent)^ := CompClass;
|
||||
end;
|
||||
end;
|
||||
|
||||
destructor TMemDataSetEditor.Destroy;
|
||||
begin
|
||||
DefaultEditor.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TMemDataSetEditor.ExecuteVerb(Index: Integer);
|
||||
begin
|
||||
if Index < DefaultEditor.GetVerbCount then
|
||||
DefaultEditor.ExecuteVerb(Index)
|
||||
else
|
||||
begin
|
||||
case Index - DefaultEditor.GetVerbCount of
|
||||
0:BorrowStructure;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TMemDataSetEditor.GetVerb(Index: Integer): string;
|
||||
begin
|
||||
if Index < DefaultEditor.GetVerbCount then
|
||||
Result := DefaultEditor.GetVerb(Index)
|
||||
else
|
||||
begin
|
||||
case Index - DefaultEditor.GetVerbCount of
|
||||
0:Result:=sRxBorrowStructure;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TMemDataSetEditor.GetVerbCount: Integer;
|
||||
begin
|
||||
Result:=DefaultEditor.GetVerbCount + 1;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
233
RXLib/rxdb/rxsortby.lfm
Normal file
233
RXLib/rxdb/rxsortby.lfm
Normal file
@@ -0,0 +1,233 @@
|
||||
object rxSortByForm: TrxSortByForm
|
||||
Left = 450
|
||||
Height = 398
|
||||
Top = 243
|
||||
Width = 684
|
||||
ActiveControl = AddBtn
|
||||
Caption = 'Sort by fields'
|
||||
ClientHeight = 398
|
||||
ClientWidth = 684
|
||||
OnCreate = FormCreate
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '1.7'
|
||||
object Label1: TLabel
|
||||
AnchorSideLeft.Control = AddBtn
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Owner
|
||||
Left = 421
|
||||
Height = 20
|
||||
Top = 6
|
||||
Width = 113
|
||||
BorderSpacing.Around = 6
|
||||
Caption = '&Fields for sorting:'
|
||||
FocusControl = ListBox1
|
||||
ParentColor = False
|
||||
end
|
||||
object Label2: TLabel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Owner
|
||||
Left = 6
|
||||
Height = 20
|
||||
Top = 6
|
||||
Width = 60
|
||||
BorderSpacing.Around = 6
|
||||
Caption = '&All fields:'
|
||||
FocusControl = ListBox2
|
||||
ParentColor = False
|
||||
end
|
||||
object ListBox2: TListBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Label2
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = AddBtn
|
||||
AnchorSideBottom.Control = CheckBox1
|
||||
Left = 6
|
||||
Height = 282
|
||||
Top = 32
|
||||
Width = 258
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
OnDblClick = ListBox2DblClick
|
||||
ScrollWidth = 256
|
||||
TabOrder = 0
|
||||
TopIndex = -1
|
||||
end
|
||||
object RemoveBtn: TBitBtn
|
||||
AnchorSideLeft.Control = AddBtn
|
||||
AnchorSideTop.Control = AddBtn
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = AddBtn
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 270
|
||||
Height = 35
|
||||
Top = 73
|
||||
Width = 145
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Top = 6
|
||||
Caption = '&Remove'
|
||||
Glyph.Data = {
|
||||
8A010000424D8A01000000000000760000002800000018000000170000000100
|
||||
0400000000001401000000000000000000001000000010000000000000000000
|
||||
80000080000000808000800000008000800080800000C0C0C000808080000000
|
||||
C80000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
|
||||
7777777777777777777777777877777777777777777777770077777777777777
|
||||
7777777090777777777777777777770990777777777777777777709990777777
|
||||
7777777777770999907777777777777777709999900000008777777777099999
|
||||
999999990777777770999999999999990777777709999999999999990777777F
|
||||
999999999999999907777777F999999999999999077777777F99999999999999
|
||||
0777777777F999999999999907777777777F999998FFFFFF877777777777F999
|
||||
987777777777777777777F999877777777777777777777F99877777777777777
|
||||
7777777F987777777777777777777777F877777777777777777777777F777777
|
||||
7777777777777777777777777777
|
||||
}
|
||||
OnClick = RemoveBtnClick
|
||||
TabOrder = 2
|
||||
end
|
||||
object UpBtn: TBitBtn
|
||||
AnchorSideLeft.Control = AddBtn
|
||||
AnchorSideTop.Control = RemoveBtn
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = AddBtn
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 270
|
||||
Height = 36
|
||||
Top = 114
|
||||
Width = 145
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Top = 6
|
||||
Caption = 'M&ove up'
|
||||
Glyph.Data = {
|
||||
96010000424D9601000000000000760000002800000017000000180000000100
|
||||
0400000000002001000000000000000000001000000010000000000000000000
|
||||
80000080000000808000800000008000800080800000C0C0C000808080000000
|
||||
C80000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
|
||||
7777777777707777777777777777777777707777777777777777777777707777
|
||||
77780000000877777770777777709999999F77777770777777709999999F7777
|
||||
7770777777709999999F77777770777777709999999F77777770777777709999
|
||||
999F77777770777777709999999F77777770780000009999999888888F707709
|
||||
9999999999999999F7707770999999999999999F7770777709999999999999F7
|
||||
777077777099999999999F7777707777770999999999F7777770777777709999
|
||||
999F7777777077777777099999F7777777707777777770999F77777777707777
|
||||
77777709F7777777777077777777777F77777777777077777777777777777777
|
||||
7770777777777777777777777770777777777777777777777770
|
||||
}
|
||||
OnClick = UpBtnClick
|
||||
TabOrder = 3
|
||||
end
|
||||
object DownBtn: TBitBtn
|
||||
AnchorSideLeft.Control = AddBtn
|
||||
AnchorSideTop.Control = UpBtn
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = AddBtn
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 270
|
||||
Height = 36
|
||||
Top = 156
|
||||
Width = 145
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Top = 6
|
||||
Caption = '&Move down'
|
||||
Glyph.Data = {
|
||||
96010000424D9601000000000000760000002800000017000000180000000100
|
||||
0400000000002001000000000000000000001000000010000000000000000000
|
||||
80000080000000808000800000008000800080800000C0C0C000808080000000
|
||||
C80000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
|
||||
7777777777707777777777777777777777707777777777777777777777707777
|
||||
7777777F777777777770777777777709F777777777707777777770999F777777
|
||||
777077777777099999F777777770777777709999999F77777770777777099999
|
||||
9999F777777077777099999999999F777770777709999999999999F777707770
|
||||
999999999999999F777077099999999999999999F77078000000999999988888
|
||||
8F70777777709999999F77777770777777709999999F77777770777777709999
|
||||
999F77777770777777709999999F77777770777777709999999F777777707777
|
||||
77709999999F7777777077777778000000087777777077777777777777777777
|
||||
7770777777777777777777777770777777777777777777777770
|
||||
}
|
||||
OnClick = DownBtnClick
|
||||
TabOrder = 4
|
||||
end
|
||||
object ListBox1: TListBox
|
||||
AnchorSideLeft.Control = AddBtn
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Label1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = CheckBox1
|
||||
Left = 421
|
||||
Height = 282
|
||||
Top = 32
|
||||
Width = 257
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
OnDblClick = SpeedButton1Click
|
||||
OnDrawItem = ListBox1DrawItem
|
||||
ScrollWidth = 255
|
||||
Style = lbOwnerDrawFixed
|
||||
TabOrder = 5
|
||||
TopIndex = -1
|
||||
end
|
||||
object AddBtn: TBitBtn
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideLeft.Side = asrCenter
|
||||
AnchorSideTop.Control = ListBox1
|
||||
Left = 270
|
||||
Height = 35
|
||||
Top = 32
|
||||
Width = 145
|
||||
AutoSize = True
|
||||
Caption = '&Add field to sort'
|
||||
Glyph.Data = {
|
||||
8A010000424D8A01000000000000760000002800000018000000170000000100
|
||||
0400000000001401000000000000000000001000000010000000000000000000
|
||||
80000080000000808000800000008000800080800000C0C0C000808080000000
|
||||
C80000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
|
||||
7777777777777777777777877777777777777777777777007777777777777777
|
||||
7777770907777777777777777777770990777777777777777777770999077777
|
||||
7777777777777709999077777777777800000009999907777777777099999999
|
||||
9999907777777770999999999999990777777770999999999999999077777770
|
||||
9999999999999999F7777770999999999999999F7777777099999999999999F7
|
||||
777777709999999999999F7777777778FFFFFF899999F7777777777777777789
|
||||
999F7777777777777777778999F7777777777777777777899F77777777777777
|
||||
77777789F7777777777777777777778F7777777777777777777777F777777777
|
||||
7777777777777777777777777777
|
||||
}
|
||||
Layout = blGlyphRight
|
||||
OnClick = AddBtnClick
|
||||
TabOrder = 1
|
||||
end
|
||||
object ButtonPanel1: TButtonPanel
|
||||
Left = 6
|
||||
Height = 42
|
||||
Top = 350
|
||||
Width = 672
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
HelpButton.Name = 'HelpButton'
|
||||
HelpButton.DefaultCaption = True
|
||||
CloseButton.Name = 'CloseButton'
|
||||
CloseButton.DefaultCaption = True
|
||||
CancelButton.Name = 'CancelButton'
|
||||
CancelButton.DefaultCaption = True
|
||||
TabOrder = 6
|
||||
ShowButtons = [pbOK, pbCancel, pbHelp]
|
||||
end
|
||||
object CheckBox1: TCheckBox
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideBottom.Control = ButtonPanel1
|
||||
Left = 6
|
||||
Height = 24
|
||||
Top = 320
|
||||
Width = 158
|
||||
Anchors = [akLeft, akBottom]
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'Case insensitive sort'
|
||||
Enabled = False
|
||||
TabOrder = 7
|
||||
end
|
||||
end
|
272
RXLib/rxdb/rxsortby.pas
Normal file
272
RXLib/rxdb/rxsortby.pas
Normal file
@@ -0,0 +1,272 @@
|
||||
{ RXDBGrid unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit rxsortby;
|
||||
|
||||
{$I rx.inc}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
StdCtrls, Buttons, ButtonPanel, rxdbgrid, db, types;
|
||||
|
||||
type
|
||||
|
||||
{ TrxSortByForm }
|
||||
|
||||
TrxSortByForm = class(TForm)
|
||||
AddBtn: TBitBtn;
|
||||
ButtonPanel1: TButtonPanel;
|
||||
CheckBox1: TCheckBox;
|
||||
DownBtn: TBitBtn;
|
||||
Label1: TLabel;
|
||||
Label2: TLabel;
|
||||
ListBox1: TListBox;
|
||||
ListBox2: TListBox;
|
||||
RemoveBtn: TBitBtn;
|
||||
UpBtn: TBitBtn;
|
||||
procedure AddBtnClick(Sender: TObject);
|
||||
procedure DownBtnClick(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure ListBox1DblClick(Sender: TObject);
|
||||
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
|
||||
ARect: TRect; State: TOwnerDrawState);
|
||||
procedure ListBox2DblClick(Sender: TObject);
|
||||
procedure RemoveBtnClick(Sender: TObject);
|
||||
procedure SpeedButton1Click(Sender: TObject);
|
||||
procedure UpBtnClick(Sender: TObject);
|
||||
private
|
||||
FDBGrid:TRxDBGrid;
|
||||
public
|
||||
{ public declarations }
|
||||
function Execute(ADBGrid:TRxDBGrid; SortNames:TStringList):Boolean;
|
||||
end;
|
||||
|
||||
var
|
||||
rxSortByForm: TrxSortByForm;
|
||||
|
||||
implementation
|
||||
uses rxdconst, DBGrids;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TrxSortByForm }
|
||||
|
||||
procedure TrxSortByForm.DownBtnClick(Sender: TObject);
|
||||
var
|
||||
TmpField:String;
|
||||
C1:TObject;
|
||||
Poz: Integer;
|
||||
begin
|
||||
if ListBox1.ItemIndex < ListBox1.Items.Count-1 Then
|
||||
begin
|
||||
Poz:=ListBox1.ItemIndex;
|
||||
|
||||
TmpField:=ListBox1.Items[Poz+1];
|
||||
C1:=ListBox1.Items.Objects[Poz+1];
|
||||
|
||||
ListBox1.Items[Poz+1]:=ListBox1.Items[Poz];
|
||||
ListBox1.Items.Objects[Poz+1]:=ListBox1.Items.Objects[Poz];
|
||||
|
||||
ListBox1.Items[Poz]:=TmpField;
|
||||
ListBox1.Items.Objects[Poz]:=C1;
|
||||
ListBox1.ItemIndex:=Poz+1;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TrxSortByForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
{ ComboBox1.Clear;
|
||||
ComboBox1.Items.Add(sRxAscendign);
|
||||
ComboBox1.Items.Add(sRxDescending);}
|
||||
Caption:=sRxSortByFormCaption;
|
||||
Label2.Caption:=sRxSortByFormAllFields;
|
||||
Label1.Caption:=sRxSortByFormSortFields;
|
||||
// Label4.Caption:=sRxSortByFormSortOrder;
|
||||
AddBtn.Caption:=sRxSortByFormAddField;
|
||||
RemoveBtn.Caption:=sRxSortByFormRemoveField;
|
||||
UpBtn.Caption:=sRxSortByFormMoveUpField;
|
||||
DownBtn.Caption:=sRxSortByFormMoveDnField;
|
||||
CheckBox1.Caption:=sRxSortByFormCaseInsens;
|
||||
end;
|
||||
|
||||
procedure TrxSortByForm.ListBox1DblClick(Sender: TObject);
|
||||
begin
|
||||
RemoveBtn.Click;
|
||||
end;
|
||||
|
||||
procedure TrxSortByForm.ListBox1DrawItem(Control: TWinControl; Index: Integer;
|
||||
ARect: TRect; State: TOwnerDrawState);
|
||||
var
|
||||
X, Y:integer;
|
||||
//P:TRxColumn;
|
||||
S1, S2:string;
|
||||
Cnv:TCanvas;
|
||||
begin
|
||||
Cnv:=ListBox1.Canvas;
|
||||
Cnv.FillRect(ARect); { clear the rectangle }
|
||||
//P:=TRxColumn(ListBox1.Items.Objects[Index]);
|
||||
S1:=ListBox1.Items[Index];
|
||||
S2:=Copy(S1, 1, 1);
|
||||
Delete(S1, 1, 1);
|
||||
|
||||
X := aRect.Left + 2;
|
||||
Y := Trunc((aRect.Top + aRect.Bottom - UpBtn.Glyph.Height) / 2);
|
||||
|
||||
if S2 = '1' then
|
||||
Cnv.Draw(X, Y, UpBtn.Glyph)
|
||||
else
|
||||
Cnv.Draw(X, Y, DownBtn.Glyph);
|
||||
|
||||
Cnv.TextOut(ARect.Left + UpBtn.Glyph.Width + 6, (ARect.Top + ARect.Bottom - Cnv.TextHeight('Wg')) div 2, S1);
|
||||
end;
|
||||
|
||||
procedure TrxSortByForm.ListBox2DblClick(Sender: TObject);
|
||||
begin
|
||||
AddBtn.Click;
|
||||
end;
|
||||
|
||||
|
||||
procedure TrxSortByForm.AddBtnClick(Sender: TObject);
|
||||
var
|
||||
S:string;
|
||||
begin
|
||||
if ListBox2.ItemIndex <> -1 Then
|
||||
begin
|
||||
S:='1'+ListBox2.Items[ListBox2.ItemIndex];
|
||||
ListBox1.Items.Objects[ListBox1.Items.Add(S)]:=ListBox2.Items.Objects[ListBox2.ItemIndex];
|
||||
ListBox2.Items.Delete(ListBox2.ItemIndex);
|
||||
ListBox1.ItemIndex:=ListBox1.Items.Count-1;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TrxSortByForm.RemoveBtnClick(Sender: TObject);
|
||||
var
|
||||
S:string;
|
||||
begin
|
||||
if ListBox1.ItemIndex <> -1 Then
|
||||
begin
|
||||
S:=TRxColumn(ListBox1.Items.Objects[ListBox1.ItemIndex]).Title.Caption;
|
||||
ListBox2.Items.Objects[ListBox2.Items.Add(S)]:=ListBox1.Items.Objects[ListBox1.ItemIndex];
|
||||
ListBox1.Items.Delete(ListBox1.ItemIndex);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TrxSortByForm.SpeedButton1Click(Sender: TObject);
|
||||
var
|
||||
S:string;
|
||||
begin
|
||||
if (ListBox1.ItemIndex <> -1) then
|
||||
begin
|
||||
S:=ListBox1.Items[ListBox1.ItemIndex];
|
||||
if S[1] = '1' then
|
||||
S[1] := '0'
|
||||
else
|
||||
S[1] := '1';
|
||||
ListBox1.Items[ListBox1.ItemIndex]:=S;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TrxSortByForm.UpBtnClick(Sender: TObject);
|
||||
var
|
||||
TmpField:String;
|
||||
Poz : Integer;
|
||||
C1:TObject;
|
||||
begin
|
||||
if ListBox1.ItemIndex > 0 Then
|
||||
begin
|
||||
Poz:=ListBox1.ItemIndex;
|
||||
TmpField:=ListBox1.Items[Poz-1];
|
||||
C1:=ListBox1.Items.Objects[Poz-1];
|
||||
|
||||
ListBox1.Items[Poz-1]:=ListBox1.Items[Poz];
|
||||
ListBox1.Items.Objects[Poz-1]:=ListBox1.Items.Objects[Poz];
|
||||
|
||||
ListBox1.Items[Poz]:=TmpField;
|
||||
ListBox1.Items.Objects[Poz]:=C1;
|
||||
|
||||
ListBox1.ItemIndex:=Poz-1;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function TrxSortByForm.Execute(ADBGrid: TRxDBGrid; SortNames: TStringList
|
||||
): Boolean;
|
||||
var
|
||||
i : Integer;
|
||||
S : String;
|
||||
C:TRxColumn;
|
||||
begin
|
||||
Result:=False;
|
||||
if not (Assigned(ADBGrid.DataSource) and Assigned(ADBGrid.DataSource.DataSet) and ADBGrid.DataSource.DataSet.Active) then exit;
|
||||
|
||||
FDBGrid:=ADBGrid;
|
||||
|
||||
ListBox1.Clear;
|
||||
ListBox2.Clear;
|
||||
|
||||
|
||||
for i:=0 to ADBGrid.Columns.Count-1 do
|
||||
begin
|
||||
C:=TRxColumn(ADBGrid.Columns[i]);
|
||||
if C.SortOrder = smNone then
|
||||
ListBox2.Items.Objects[ListBox2.Items.Add(C.Title.Caption)]:=C;
|
||||
end;
|
||||
|
||||
for i:=0 to ADBGrid.SortColumns.Count-1 do
|
||||
begin
|
||||
C:=ADBGrid.SortColumns[i];
|
||||
|
||||
if C.SortOrder = smUp then
|
||||
S:='1'+C.Title.Caption
|
||||
else
|
||||
S:='0'+C.Title.Caption;
|
||||
|
||||
ListBox1.Items.Objects[ListBox1.Items.Add(S)]:=C
|
||||
end;
|
||||
|
||||
if ShowModal = mrOK Then
|
||||
begin
|
||||
SortNames.Clear;
|
||||
for i:=0 to ListBox1.Items.Count-1 do
|
||||
begin
|
||||
C:=ListBox1.Items.Objects[i] as TRxColumn;
|
||||
SortNames.Add(Copy(ListBox1.Items[i], 1, 1) + C.FieldName);
|
||||
end;
|
||||
|
||||
Result:=True;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
72
RXLib/rxdb/rxsortmemds.pas
Normal file
72
RXLib/rxdb/rxsortmemds.pas
Normal file
@@ -0,0 +1,72 @@
|
||||
{ rxsortmemds unit
|
||||
|
||||
Copyright (C) 2005-2017 Lagunov Aleksey alexs75@yandex.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.
|
||||
}
|
||||
|
||||
unit rxsortmemds;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, DB, RxDBGrid;
|
||||
|
||||
type
|
||||
|
||||
{ TRxMemoryDataSortEngine }
|
||||
|
||||
TRxMemoryDataSortEngine = class(TRxDBGridSortEngine)
|
||||
protected
|
||||
public
|
||||
procedure Sort(FieldName: string; ADataSet:TDataSet; Asc:boolean; SortOptions:TRxSortEngineOptions);override;
|
||||
procedure SortList(ListField:string; ADataSet:TDataSet; Asc: array of boolean; SortOptions: TRxSortEngineOptions);override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
uses rxmemds;
|
||||
|
||||
procedure TRxMemoryDataSortEngine.Sort(FieldName: string; ADataSet: TDataSet;
|
||||
Asc: boolean; SortOptions: TRxSortEngineOptions);
|
||||
begin
|
||||
if Assigned(ADataSet) then
|
||||
(ADataSet as TRxMemoryData).SortOnFields(FieldName, seoCaseInsensitiveSort in SortOptions, not Asc);
|
||||
end;
|
||||
|
||||
procedure TRxMemoryDataSortEngine.SortList(ListField: string;
|
||||
ADataSet: TDataSet; Asc: array of boolean; SortOptions: TRxSortEngineOptions);
|
||||
begin
|
||||
if Assigned(ADataSet) then
|
||||
(ADataSet as TRxMemoryData).SortOnFields(ListField, seoCaseInsensitiveSort in SortOptions, Asc[0]);
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterRxDBGridSortEngine(TRxMemoryDataSortEngine, 'TRxMemoryData');
|
||||
end.
|
||||
|
Reference in New Issue
Block a user