LazUtils: make Deduplicate in DictionaryStringlist a bit more general and improve check for objects.

git-svn-id: trunk@47322 -
This commit is contained in:
bart 2015-01-08 21:53:07 +00:00
parent 9bbe6f00a1
commit 73d61b2750

View File

@ -53,20 +53,27 @@ type
function IndexOf(const S: string): Integer; override; function IndexOf(const S: string): Integer; override;
end; end;
procedure Deduplicate(AStrings: TStringList); function Deduplicate(AStrings: TStrings): Boolean;
implementation implementation
procedure Deduplicate(AStrings: TStringList); {
Removes duplicate strings (case sensitive) from the AStrings object
When the AStrings contains objects, the function will return false.
}
function Deduplicate(AStrings: TStrings): Boolean;
var var
DSL :TDictionaryStringList; i: Integer;
DSL: TDictionaryStringList;
begin begin
if AStrings.OwnsObjects then Result := False;
raise Exception.Create('Deduplicate: OwnsObjects in AStrings is not supported.'); for i := 0 to AStrings.Count - 1 do
if Assigned(AStrings.Objects[i]) then Exit;
DSL := TDictionaryStringList.Create; DSL := TDictionaryStringList.Create;
try try
DSL.Assign(AStrings); DSL.Assign(AStrings);
AStrings.Assign(DSL); AStrings.Assign(DSL);
Result := True;
finally finally
DSL.Free; DSL.Free;
end; end;