<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On 22 March 2016 at 14:43, Michael Van Canneyt wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">On 3/22/16 2:01 AM, Michael Van Canneyt wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
There are now several options:<br>
1. I change the code to raise an exception instead (as was my original plan)<br>
2. I change the code to resort to a linear search if sorted is false.<br>
3. I introduce a boolean property that determines whether Find does any check.<br>
By default the check will be done, to warn people they're doing<br>
something stupid. If they override the check, we can assume they know what<br>
they are doing.<br>
4. Combine 1 and 3.<br>
<br>
Or,<br>
<br>
5. You override sort so it does nothing. It is virtual.<br>
You can then set sorted to True, no sort will occur, and find will do it's job.<br>
<br>
6. You use another TStringList where you change find to suit your needs.<br>
All it takes for you is to copy the implementation, you can keep the same<br>
name, and insert the unit after the classes unit in places where you need it.<br></blockquote></blockquote>
<br>
That aside: I will probably go for 1 or 4.<br>
<br>
Michael.<br></blockquote><div><br></div><div><br></div><div>Please consider the following implementation logic, I think it covers all angles:</div><div><br></div><div>procedure Find(const S: string; out Index: Integer):Boolean;</div><div>begin</div><div> if Sorted then</div><div> Result := FindSorted(S, Index);</div><div> else</div><div> begin</div><div> Index := IndexOf(S);</div><div> Result := (Index >= 0);</div><div> end;</div><div>end;</div><div><br></div><div>procedure FindSorted(const S: string; out Index: Integer; CheckSorted: Boolean = True):Boolean;</div><div>begin</div><div> if CheckSorted and not Sorted then</div><div> raise Exception.Create('List must be sorted');</div><div> // search logic here...</div><div>end;</div><div><br></div><div><br></div><div>Denis</div></div></div></div>