K2RFP,
Warnings are hints that though the code will compile, there might be unexpected 
results. The "unsafe typecast" just means that any object [pointer] may be cast 
to an integer, losing type specificity. When the programmer casts it back to an 
object, the compiler cannot verify that is the correct object type. In Delphi 
(and in C++), untyped pointers are often used, but require a bit more care on 
the part of the developer.
If you'd like to eliminate the messages, a few options are available:
1. Use a type-safe container class rather than TList (see 
http://www.atug.com/andypatterns/collections.htm).
2. In Project Options\Compiler Messages, un-check Unsafe typecast.
3. Surround the offending code with compiler directives as follows:
    {$WARN UNSAFE_CAST OFF}
    [your Delphi code that raises warning message]
    {$WARN UNSAFE_CAST ON}
    That stops the warning and serves to comment that the warning is 
superfluous.







From: -K2RFP- <[email protected]>
Subject: Compiler Warnings
  I get [Warning] Unsafe typecast messages for these statements

D:=integer(ListM.Objects[k]);
...
ListM.Objects[k]:=TObject(D);

The program works fine. The question is what are [Warnings]
all about?



      
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk

Reply via email to