Forum > General

Why this code does not return OK?

(1/2) > >>

typo:

--- Code: ---if 300 in [100,200,300,400,500,600,700,800,900] then
  ShowMessage('OK');

--- End code ---

It returns OK to 100 and 200 but does it not to 300 or higher. Why?

Am I missing something?

Leledumbo:
Sets can have maximally 256 elements. I don't know how the compiler treats inline sets, but since you have 100-900 (over 256 range) there might be problems regarding this.

typo:
Any workaround?

bonmario:
Put the values in a sorted TStringList and then search them with IndexOf

Hi, Mario

JuhaManninen:

--- Quote from: bonmario on September 20, 2010, 07:08:30 am ---Put the values in a sorted TStringList and then search them with IndexOf

--- End quote ---

IndexOf does not use sorting. It does a linear search.
For a sorted list you should use Find. It does a faster binary search.

Anyway, you have integers, not strings. Lack of container classes is a problem with Delphi and FPC. I hope the generics containers will improve the situation.

I have made a IntList class because I didn't find such class.
I just published it in GitHub:
 http://github.com/JuhaManninen/Pascal/tree/master/IntList/
It is well optimized and fast, may be helpful in your case, too.

Juha

Navigation

[0] Message Index

[#] Next page

Go to full version