mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-01 13:19:31 +01:00
LazUtils: Improve DictionaryStringList and its example project. Issue #28159, patch from Antônio Galvão.
git-svn-id: trunk@49147 -
This commit is contained in:
parent
824f9ac5d9
commit
f88dc97367
@ -53,7 +53,7 @@ type
|
||||
function IndexOf(const S: string): Integer; override;
|
||||
end;
|
||||
|
||||
function Deduplicate(AStrings: TStrings; AStringsOwnsObjects: Boolean = True): Boolean;
|
||||
function Deduplicate(AStrings: TStrings): Boolean;
|
||||
|
||||
implementation
|
||||
|
||||
@ -61,17 +61,12 @@ implementation
|
||||
Removes duplicate strings (case sensitive) from AStrings.
|
||||
When the AStrings owns and contains objects, the function will return false.
|
||||
}
|
||||
function Deduplicate(AStrings: TStrings; AStringsOwnsObjects: Boolean): Boolean;
|
||||
function Deduplicate(AStrings: TStrings): Boolean;
|
||||
var
|
||||
i: Integer;
|
||||
DSL: TDictionaryStringList;
|
||||
begin
|
||||
Result := False;
|
||||
if AStringsOwnsObjects then
|
||||
begin
|
||||
for i := 0 to AStrings.Count - 1 do
|
||||
if Assigned(AStrings.Objects[i]) then Exit;
|
||||
end;
|
||||
DSL := TDictionaryStringList.Create;
|
||||
try
|
||||
DSL.Assign(AStrings);
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
Demonstrate how TDictionaryStringList can quicly remove duplicates from a list.
|
||||
Demonstrate how TDictionaryStringList can quicly remove duplicates from a list without changing the order.
|
||||
|
||||
Author: Antônio Galvão
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="9"/>
|
||||
@ -38,7 +38,6 @@
|
||||
<Unit0>
|
||||
<Filename Value="TDictionaryStringListDemo.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="TDictionaryStringListDemo"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="main.pas"/>
|
||||
@ -67,12 +66,6 @@
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerMessages>
|
||||
<MsgFileName Value=""/>
|
||||
</CompilerMessages>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
object Form1: TForm1
|
||||
Left = 291
|
||||
Left = 353
|
||||
Height = 353
|
||||
Top = 215
|
||||
Top = 194
|
||||
Width = 535
|
||||
BorderStyle = bsSingle
|
||||
Caption = 'TDictionaryStringList Demo'
|
||||
@ -11,11 +11,11 @@ object Form1: TForm1
|
||||
OnDestroy = FormDestroy
|
||||
OnShow = FormShow
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '1.1'
|
||||
LCLVersion = '1.4.0.4'
|
||||
object btnDedupeMemo: TButton
|
||||
Left = 346
|
||||
Height = 25
|
||||
Top = 8
|
||||
Top = 72
|
||||
Width = 183
|
||||
Anchors = [akTop, akRight]
|
||||
Caption = 'Dedupe Memo'
|
||||
@ -26,8 +26,7 @@ object Form1: TForm1
|
||||
Left = 0
|
||||
Height = 281
|
||||
Top = 72
|
||||
Width = 535
|
||||
Align = alBottom
|
||||
Width = 336
|
||||
ScrollBars = ssAutoBoth
|
||||
TabOrder = 1
|
||||
end
|
||||
@ -35,7 +34,7 @@ object Form1: TForm1
|
||||
Left = 16
|
||||
Height = 15
|
||||
Top = 48
|
||||
Width = 33
|
||||
Width = 30
|
||||
Caption = 'Time:'
|
||||
ParentColor = False
|
||||
end
|
||||
@ -43,7 +42,7 @@ object Form1: TForm1
|
||||
Left = 130
|
||||
Height = 15
|
||||
Top = 48
|
||||
Width = 107
|
||||
Width = 90
|
||||
Caption = 'Duplicated Lines:'
|
||||
ParentColor = False
|
||||
end
|
||||
@ -70,12 +69,22 @@ object Form1: TForm1
|
||||
AnchorSideRight.Control = btnDedupeMemo
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 346
|
||||
Height = 25
|
||||
Top = 38
|
||||
Height = 32
|
||||
Top = 232
|
||||
Width = 183
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
Caption = 'Create File and Dedupe it'
|
||||
OnClick = btnDedupeFileClick
|
||||
TabOrder = 4
|
||||
end
|
||||
object Label1: TLabel
|
||||
Left = 346
|
||||
Height = 64
|
||||
Top = 168
|
||||
Width = 182
|
||||
AutoSize = False
|
||||
Caption = 'Deduplicating from a file is very much faster than using a GUI control. Use the button below to see the whole process.'
|
||||
ParentColor = False
|
||||
WordWrap = True
|
||||
end
|
||||
end
|
||||
|
||||
@ -16,6 +16,7 @@ type
|
||||
btnDedupeMemo: TButton;
|
||||
btnDedupeFile: TButton;
|
||||
btnGenerate: TButton;
|
||||
Label1 :TLabel;
|
||||
lblLines: TLabel;
|
||||
lblTime: TLabel;
|
||||
Memo: TMemo;
|
||||
@ -109,10 +110,14 @@ begin
|
||||
lblTime.Caption := 'Time:';
|
||||
lblLines.Caption := 'Duplicated lines:';
|
||||
Application.ProcessMessages;
|
||||
ShowMessage('Generating data. Please wait.');
|
||||
SpinEdit1.Value := 1000000;
|
||||
btnGenerateClick(nil);
|
||||
ShowMessage('Saving it to a file. Please wait.');
|
||||
|
||||
if Trim(Memo.Text) = '' then
|
||||
begin
|
||||
ShowMessage('Generating data. Please wait.');
|
||||
btnGenerateClick(nil);
|
||||
end;
|
||||
|
||||
ShowMessage('Saving memo to a file. Please wait.');
|
||||
Memo.Lines.SaveToFile('temp.txt');
|
||||
ShowMessage('Dedupping the file.');
|
||||
T := Now;
|
||||
@ -143,7 +148,7 @@ end;
|
||||
|
||||
procedure TForm1.FormShow(Sender: TObject);
|
||||
begin
|
||||
spinedit1.Value := 1000000;
|
||||
spinedit1.Value := 100000;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user