mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-15 11:19:11 +02:00
LCL: Implemented an enumerator for dbgrid's bookmarklist.
git-svn-id: trunk@58009 -
This commit is contained in:
parent
ad0ca3e419
commit
3d7b93845d
@ -132,6 +132,33 @@ type
|
|||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
TBookmarkList = class;
|
||||||
|
TBookmarkedRecordEnumeratorOptions = set of
|
||||||
|
(
|
||||||
|
breDisableDataset,
|
||||||
|
breStopOnInvalidBookmark,
|
||||||
|
breRestoreCurrent
|
||||||
|
);
|
||||||
|
|
||||||
|
{ TBookmarkedRecordEnumerator }
|
||||||
|
|
||||||
|
TBookmarkedRecordEnumerator = class
|
||||||
|
private
|
||||||
|
fBookmarkList: TBookmarkList;
|
||||||
|
fBookmarkIndex: Integer;
|
||||||
|
fCurrent, fBook: TBookmark;
|
||||||
|
fDataset: TDataset;
|
||||||
|
fOptions: TBookmarkedRecordEnumeratorOptions;
|
||||||
|
public
|
||||||
|
constructor Create(bookList: TBookmarkList; aGrid: TCustomDbGrid;
|
||||||
|
anOptions: TBookmarkedRecordEnumeratorOptions);
|
||||||
|
destructor Destroy; override;
|
||||||
|
function MoveNext: boolean;
|
||||||
|
function GetEnumerator: TBookmarkedRecordEnumerator;
|
||||||
|
property Current: TBookmark read fCurrent;
|
||||||
|
property Options: TBookmarkedRecordEnumeratorOptions read fOptions write fOptions;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TBookmarkList }
|
{ TBookmarkList }
|
||||||
|
|
||||||
TBookmarkList = class
|
TBookmarkList = class
|
||||||
@ -155,6 +182,8 @@ type
|
|||||||
function Find(const Item: TBookmark; var AIndex: Integer): boolean;
|
function Find(const Item: TBookmark; var AIndex: Integer): boolean;
|
||||||
function IndexOf(const Item: TBookmark): Integer;
|
function IndexOf(const Item: TBookmark): Integer;
|
||||||
function Refresh: boolean;
|
function Refresh: boolean;
|
||||||
|
function GetEnumerator(opt: TBookmarkedRecordEnumeratorOptions =
|
||||||
|
[breDisableDataset, breRestoreCurrent]): TBookmarkedRecordEnumerator;
|
||||||
|
|
||||||
property Count: integer read GetCount;
|
property Count: integer read GetCount;
|
||||||
property CurrentRowSelected: boolean
|
property CurrentRowSelected: boolean
|
||||||
@ -753,6 +782,56 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TBookmarkedRecordEnumerator }
|
||||||
|
|
||||||
|
constructor TBookmarkedRecordEnumerator.Create(bookList: TBookmarkList;
|
||||||
|
aGrid: TCustomDbGrid; anOptions: TBookmarkedRecordEnumeratorOptions);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
fBookmarkList := bookList;
|
||||||
|
fBookmarkIndex := -1;
|
||||||
|
fDataset := aGrid.Datasource.dataset;
|
||||||
|
fOptions := anOptions;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TBookmarkedRecordEnumerator.Destroy;
|
||||||
|
begin
|
||||||
|
if breRestoreCurrent in fOptions then begin
|
||||||
|
if fDataset.BookmarkValid(fBook) then
|
||||||
|
fDataset.GotoBookmark(fBook);
|
||||||
|
fDataset.FreeBookmark(fBook);
|
||||||
|
end;
|
||||||
|
if breDisableDataset in fOptions then
|
||||||
|
fDataset.EnableControls;
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TBookmarkedRecordEnumerator.MoveNext: boolean;
|
||||||
|
begin
|
||||||
|
inc(fBookmarkIndex);
|
||||||
|
|
||||||
|
if fBookmarkIndex=0 then begin
|
||||||
|
if breDisableDataset in fOptions then
|
||||||
|
fDataset.DisableControls;
|
||||||
|
if breRestoreCurrent in fOptions then
|
||||||
|
fBook := fDataset.GetBookmark;
|
||||||
|
end;
|
||||||
|
|
||||||
|
result := fBookmarkIndex<fBookmarkList.Count;
|
||||||
|
if result then begin
|
||||||
|
fCurrent := fBookmarkList[fBookmarkIndex];
|
||||||
|
if fDataset.BookmarkValid(fCurrent) then
|
||||||
|
fDataSet.GotoBookmark(fCurrent)
|
||||||
|
else if breStopOnInvalidBookmark in fOptions then
|
||||||
|
result := false;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TBookmarkedRecordEnumerator.GetEnumerator: TBookmarkedRecordEnumerator;
|
||||||
|
begin
|
||||||
|
result := self;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCustomDBGrid }
|
{ TCustomDBGrid }
|
||||||
|
|
||||||
procedure TCustomDBGrid.OnRecordChanged(Field: TField);
|
procedure TCustomDBGrid.OnRecordChanged(Field: TField);
|
||||||
@ -4557,7 +4636,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TBookmarkList.Create(AGrid: TCustomDBGrid);
|
function TBookmarkList.GetEnumerator(opt: TBookmarkedRecordEnumeratorOptions
|
||||||
|
): TBookmarkedRecordEnumerator;
|
||||||
|
begin
|
||||||
|
result := TBookmarkedRecordEnumerator.Create(self, fGrid, opt);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TBookmarkList.Create(AGrid: TCustomDbGrid);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FGrid := AGrid;
|
FGrid := AGrid;
|
||||||
|
Loading…
Reference in New Issue
Block a user