mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-27 15:45:40 +01:00
DictionaryStringlist: Deduplicate: allow the AStrings to have objects if it does not own them.
git-svn-id: trunk@47328 -
This commit is contained in:
parent
0c1a2ec8fe
commit
f2491ead05
@ -53,22 +53,25 @@ type
|
|||||||
function IndexOf(const S: string): Integer; override;
|
function IndexOf(const S: string): Integer; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function Deduplicate(AStrings: TStrings): Boolean;
|
function Deduplicate(AStrings: TStrings; AStringsOwnsObjects: Boolean = True): Boolean;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{
|
{
|
||||||
Removes duplicate strings (case sensitive) from the AStrings object
|
Removes duplicate strings (case sensitive) from AStrings.
|
||||||
When the AStrings contains objects, the function will return false.
|
When the AStrings owns and contains objects, the function will return false.
|
||||||
}
|
}
|
||||||
function Deduplicate(AStrings: TStrings): Boolean;
|
function Deduplicate(AStrings: TStrings; AStringsOwnsObjects: Boolean): Boolean;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
DSL: TDictionaryStringList;
|
DSL: TDictionaryStringList;
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
for i := 0 to AStrings.Count - 1 do
|
if AStringsOwnsObjects then
|
||||||
|
begin
|
||||||
|
for i := 0 to AStrings.Count - 1 do
|
||||||
if Assigned(AStrings.Objects[i]) then Exit;
|
if Assigned(AStrings.Objects[i]) then Exit;
|
||||||
|
end;
|
||||||
DSL := TDictionaryStringList.Create;
|
DSL := TDictionaryStringList.Create;
|
||||||
try
|
try
|
||||||
DSL.Assign(AStrings);
|
DSL.Assign(AStrings);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user