<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 22/03/2016 17:56, Michael Van Canneyt wrote:<br>
<blockquote
cite="mid:alpine.DEB.2.10.1603221856150.6494@home.telenet.be"
type="cite">
or better something concise like ltAuto,ltUser,ltNone.
<br>
</blockquote>
<br>
It may make more sense to call it ListSortType (as opposed to
ListType):<br>
TListSortType = (lstNone, lstAuto, lstManual);<br>
<br>
Something like this could work (prototype code):<br>
<br>
=======================================================<br>
<tt>function TStringList.GetSorted: Boolean;</tt><tt><br>
</tt><tt>begin</tt><tt><br>
</tt><tt> Result := (FSortType = lstAuto);</tt><tt><br>
</tt><tt>end;</tt><tt><br>
</tt><tt><br>
</tt><tt>procedure TStringList.SetSorted(Value: Boolean);</tt><tt><br>
</tt><tt>begin</tt><tt><br>
</tt><tt> if </tt><tt></tt><tt>Value xor </tt><tt>(</tt><tt>FSortType</tt><tt>
= lstAuto)</tt><tt> </tt><tt>then</tt><tt><br>
</tt><tt> begin</tt><tt><br>
</tt><tt> if Value then</tt><tt><br>
</tt><tt> </tt><tt>begin</tt><tt><br>
</tt><tt> Sort;</tt><tt><br>
</tt><tt> FSortType</tt><tt> := lstAuto;</tt><tt><br>
</tt><tt> end</tt><tt><br>
</tt><tt> else</tt><tt><br>
</tt><tt> </tt><tt>FSortType</tt><tt> </tt><tt>:= </tt><tt>lstNone;</tt><tt><br>
</tt><tt> end;</tt><tt><br>
</tt><tt>end; </tt><tt><br>
</tt><tt><br>
</tt><tt>procedure TStringList.SetSort</tt><tt>Type</tt><tt>(Value:
</tt><tt>TListSortType</tt><tt>);</tt><tt><br>
</tt><tt>begin</tt><tt><br>
</tt><tt> if FSort</tt><tt>Type</tt><tt> <> Value then</tt><tt><br>
</tt><tt> begin</tt><tt><br>
</tt><tt> if Value = </tt><tt>lstAuto</tt><tt> then</tt><tt><br>
</tt><tt> </tt><tt>Sort;</tt><tt><br>
</tt><tt> FSorted := </tt><tt>Value;</tt><tt><br>
</tt><tt> end;</tt><tt><br>
</tt><tt>end; </tt><tt><br>
</tt><tt><br>
</tt><tt>procedure </tt><tt>TStringList.</tt><tt>Find(const S:
string; out Index: Integer):Boolean;</tt><tt><br>
</tt><tt>
</tt><tt>
</tt>
<div><tt>begin</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt> if </tt><tt>F</tt><tt>SortType <> lstNone</tt><tt>
</tt><tt>then</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt> Result := FindSorted(S, Index);</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt> else</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt> begin</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt> Index := IndexOf(S);</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt> Result := (Index >= 0);</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt> end;</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt>end;</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt><br>
</tt> </div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt>procedure </tt><tt>TStringList.</tt><tt>FindSorted(const
S: string; out Index: Integer</tt><tt>):Boolean;</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt>begin</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt> if</tt><tt> </tt><tt>FSortType</tt><tt> </tt><tt>= </tt><tt>lstNone</tt><tt>
t</tt><tt>hen</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt> raise Exception.Create('List must be sorted');</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt> // sorted search logic here...</tt></div>
<tt>
</tt><tt> </tt><tt>
</tt>
<div><tt>end;</tt></div>
=======================================================<br>
<br>
An alternative solution, without adding TListSortType:<br>
<br>
=======================================================<br>
<tt>procedure Find(const S: string; out Index: Integer; <b>AssumeSorted:
Boolean = False</b>):Boolean;</tt><tt><br>
</tt>
<div><tt>begin</tt></div>
<tt> </tt>
<div><tt> if </tt><tt><tt><b><tt>AssumeSorted</tt></b> or </tt>Sorted
</tt><tt>then</tt></div>
<tt> </tt>
<div><tt> Result := FindSorted(S, Index, False);</tt></div>
<tt> </tt>
<div><tt> else</tt></div>
<tt> </tt>
<div><tt> begin</tt></div>
<tt> </tt>
<div><tt> Index := IndexOf(S);</tt></div>
<tt> </tt>
<div><tt> Result := (Index >= 0);</tt></div>
<tt> </tt>
<div><tt> end;</tt></div>
<tt> </tt>
<div><tt>end;</tt></div>
<tt> </tt>
<div><tt><br>
</tt> </div>
<tt> </tt>
<div><tt>procedure FindSorted(const S: string; out Index: Integer; <b>CheckSorted:
Boolean = True</b>):Boolean;</tt></div>
<tt> </tt>
<div><tt>begin</tt></div>
<tt> </tt>
<div><tt> if <b>CheckSorted</b> and not Sorted then</tt></div>
<tt> </tt>
<div><tt> raise Exception.Create('List must be sorted');</tt></div>
<tt> </tt>
<div><tt> // search logic here...</tt></div>
<tt> </tt>
<div><tt>end;</tt></div>
=======================================================<br>
<br>
Denis<br>
</body>
</html>