diff --git a/sListExample/slistexample.ico b/sListExample/slistexample.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/sListExample/slistexample.ico differ diff --git a/sListExample/slistexample.lpi b/sListExample/slistexample.lpi new file mode 100644 index 0000000..4917de2 --- /dev/null +++ b/sListExample/slistexample.lpi @@ -0,0 +1,79 @@ + + + + + + + + + <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> diff --git a/sListExample/slistexample.lpr b/sListExample/slistexample.lpr new file mode 100644 index 0000000..1607f5f --- /dev/null +++ b/sListExample/slistexample.lpr @@ -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. + diff --git a/sListExample/slistform.lfm b/sListExample/slistform.lfm new file mode 100644 index 0000000..458a32b --- /dev/null +++ b/sListExample/slistform.lfm @@ -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 diff --git a/sListExample/slistform.pas b/sListExample/slistform.pas new file mode 100644 index 0000000..68af1ed --- /dev/null +++ b/sListExample/slistform.pas @@ -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. +