Skip to content

Commit 099faee

Browse files
author
delphidabbler
committed
Added new TDatabase.SnippetConditionExists method
1 parent d7b14f0 commit 099faee

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Src/DB.UMain.pas

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ TEventInfo = class(TInterfacedObject, IDatabaseChangeEventInfo)
152152
function SnippetExists(const ASnippetID: TSnippetID): Boolean;
153153
function SnippetCount: Integer;
154154
function IsEmpty: Boolean;
155+
/// <summary>Checks if a any snippet in the database satisfies a given
156+
/// condition.</summary>
157+
/// <param name="FilterFn">Closure that is passed each snippet. True must
158+
/// be returned if the snippet meets the condition.</param>
159+
/// <returns>True if a snippet meets the condition, False if not.</returns>
160+
/// <remarks>Ceases searching database when 1st snippet meets the
161+
/// condition. The whole database is searched if the condition is not met.
162+
/// </remarks>
163+
function SnippetConditionExists(FilterFn: TDBFilterFn): Boolean;
155164
// Returns a list of IDs of all snippets that depend on the snippet with
156165
// the given ID.
157166
function GetDependentsOf(const ASnippetID: TSnippetID): ISnippetIDList;
@@ -430,6 +439,16 @@ function TDatabase.SelectSnippets(FilterFn: TDBFilterFn): ISnippetIDList;
430439
);
431440
end;
432441

442+
function TDatabase.SnippetConditionExists(FilterFn: TDBFilterFn): Boolean;
443+
var
444+
Snippet: TDBSnippet;
445+
begin
446+
for Snippet in fSnippetsTable do
447+
if FilterFn(Snippet.CloneAsReadOnly) then
448+
Exit(True);
449+
Result := False;
450+
end;
451+
433452
function TDatabase.SnippetCount: Integer;
434453
begin
435454
Result := fSnippetsTable.Size;

0 commit comments

Comments
 (0)