Your code (which I suspect differs from that in the question) does not have the correct syntax, which is what the compiler is telling you.
The fact that it looks likely that your code differs from the code we see in the question, and that we cannot tell whether you use VCL or FMX, makes this question somewhat dubious. On another day, I would probably vote to close as off-topic, but today, I'm going to plough on regardless, which is probably imprudent. Here goes.
The code in the question is (nearly) valid VCL code. There is an extra end
and I can only assume that is a transcription error. Clearly your actual code doesn't look like this because you would not indent like that.
Your code is not valid FMX code, even after the stray end
is removed. The compiler objects to Selected[ii]
with:
[dcc32 Error]: E2149 Class does not have a default property
That's a different error from the one you reported. The reason for the error is that Selected
is a non-indexed property of type TListBoxItem
.
I think that what is really going on is that the code in the question differs from the code that you are attempting to compile. And the code that you are attempting to compile is not valid. As a broad rule, when the compiler tells you that your code is invalid, you should believe it, even if you cannot immediately understand it.
Your life will become much easier when you stop using with
. Every time you use with
, a puppy dies. Furthermore, your namespace is widened with often surprising and unpredictable results, as names from the inner namespace hide those from the outer namespace.
Whilst it is clear that -1 + Items.Count
is the same as Items.Count - 1
, you will have to search far and wide to find a programmer that would write the former. You could continue doing so, but you will be swimming against the tide. Your code will look different from all other code, and there will be a large impedance for any other readers of your code. I suggest that you go with the flow on this one.