[Lazarus] Easiest way to "case" strings

Alexander Klenin klenin at gmail.com
Thu Mar 26 14:33:31 CET 2009


On Thu, Mar 26, 2009 at 23:07, Marc Weustink <marc.weustink at cuperus.nl> wrote:
> Alexander Klenin wrote:
>> 1) Iterating over array property, where and item should be stored in a
>>   temporary variable
>>   to avoid rereated calls to GetItem method inside the loop iteration:
>> var
>>   i: integer; item: TItem;
>> ...
>> for i := 0 to obj.ItemCount do begin
>>   item := Items[i];
>>   ... item ... item ...
>> end;
>>
>> versus
>>
>> var
>>   item: TItem;
>> ...
>> for item in obj.Items do begin
>>   ... item ... item ...
>> end;
>>
>> the latter is safer, simpler and more clear code.
>
> ehm, what if I want it reversed ?

Reverse iteration might be common enough to warrant a special syntax,
but in general all non-standard iteration orders should fall back to indexing.

> and how should the compiler know that there are Count items ?

It should not. Iterators are usually based on end-of-items condition,
not counting (since the latter might be unavailabe or inefficient for
some containers).

-- 
Alexander S. Klenin




More information about the Lazarus mailing list