DictionaryStringlist: Deduplicate: allow the AStrings to have objects if it does not own them.

git-svn-id: trunk@47328 -
This commit is contained in:
bart 2015-01-10 15:35:20 +00:00
parent 0c1a2ec8fe
commit f2491ead05

View File

@ -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);