Never said it was, I was just commenting on the need to remove the check from run time after the debugging is over, it makes me shrug a bit.
Neither the check nor it's exception are desired, not in any good design. When in doubt "is" should be used, and when it returns false a proper action should be taken, instead of leaving the code at that point to unknown consequences.
When a few TButtons share one OnClick event, there is no point of checking if the Sender is of type TButton, because it is a fact by design. It is perfectly ok to cast the Sender to get, for instance, the Tag value.
When we use TCollection and TCollectionItem as in the following code:
TSomeItem = Class(TCollectionItem)
...
end;
TSomeCollection = Class(TCollection)
..
Public
Function AddSomeItem(Const AFewParams : String, ...) : TSomeItem;
end;
...
I used to use "as" because it is more readable. I did not use it for checking.
Function TSomeCollection AddSomeItem(Const AFewParams : String, ...) : TSomeItem;
begin
Result:=Add as TSomeItem;
...
end;
I believe a cast should be used instead:
Function TSomeCollection AddSomeItem(Const AFewParams : String, ...) : TSomeItem;
begin
Result:=TSomeItem(Add);
...
end;
except the fact that it was used 4 times in a row wasting cpu it is the only legitimate use I have seen so far. Its use is well thought in here.
Well, the point here is about the four times. I won't argue about the first one. I believe the programmer did use "as" as a type cast in the last three.