1
0

Add sListExample

This commit is contained in:
Timothy Warren 2021-10-27 09:00:37 -04:00
parent d57f308802
commit ac33c8c399
5 changed files with 197 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="slistexample"/>
<Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
<Icon Value="0"/>
</General>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="slistexample.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="slistform.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<ResourceBaseClass Value="Form"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="slistexample"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,22 @@
program slistexample;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, slistform
{ you can add units after this };
{$R *.res}
begin
RequireDerivedFormResource:=True;
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@ -0,0 +1,38 @@
object Form1: TForm1
Left = 638
Height = 320
Top = 227
Width = 480
Caption = 'Stringlist Example'
ClientHeight = 320
ClientWidth = 480
OnCreate = FormCreate
LCLVersion = '2.0.12.0'
object LCount: TLabel
Left = 10
Height = 16
Top = 10
Width = 43
Caption = 'LCount'
ParentColor = False
end
object LBWords: TListBox
Left = 0
Height = 200
Top = 120
Width = 480
Align = alBottom
Columns = 4
ItemHeight = 0
TabOrder = 0
end
object Mdisplay: TMemo
Left = 0
Height = 80
Top = 40
Width = 480
Align = alBottom
Lines.Strings = ( )
TabOrder = 1
end
end

View File

@ -0,0 +1,58 @@
unit slistform;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
const specimen: string = 'Enter by the narrow gate; for the wide gate has a broad' +
' road which leads to destruction and there are many people going that way. The' +
' narrow gate and the hard road lead to life and only a few find it.';
type
TForm1 = class(TForm)
LBWords: TListBox;
LCount: TLabel;
Mdisplay: TMemo;
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
sl, noDuplicates: TStringList;
j: integer;
begin
MDisplay.Text := specimen;
sl := TStringList.Create;
noDuplicates := TStringList.Create;
try
sl.CommaText := specimen;
sl.Sort;
for j := 0 to sl.Count-1 do
if (noDuplicates.indexOf(sl[j]) > 0) then noDuplicates.Add(sl[j]);
LBWords.Items.AddStrings(noDuplicates);
LCount.Caption := Format(
'Specimen text has %d words of which %d are unique',
[sl.Count, noDuplicates.Count]
);
finally
sl.Free;
noDuplicates.Free;
end;
end;
end.