Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Getting stronger type checking


How can I get Delphi to perform stronger type checking on user defined types. Example: If I create a user defined type that descends from a double, I can pass a variable of this new type to any function that expects a double. I want Delphi to provide stronger type checking and produce a warning in this instance.   

    The following example demonstrates Delphi's new Strong type checking types, allowing you to define types that require stronger type checking at compile time. Example:

    type TStrongType = type Double;
    type TWeakType = Double;
    procedure AddWeakType(var d : TWeakType);
    begin
      d := d +  ;
    end;
    procedure AddStrongType(var d : TStrongType);
    begin
      d := d +  ;
    end;
    procedure AddDoubleType(var d : Double);
    begin
      d := d +  ;
    end;
    procedure TForm .Button Click(Sender: TObject);
    var
      d : Double;
      s : TStrongType;
      w : TWeakType;
    begin
      AddDoubleType(d);              { compiles fine }
      AddDoubleType(w);              { compiles fine }
      AddDoubleType(s);              { <- compile error }
      AddDoubleType(double(s));      { compiles fine }
      AddWeakType(d);                { compiles fine }
      AddWeakType(w);                { compiles fine }
      AddWeakType(s);                { <- compile error }
      AddWeakType(TWeakType(s));     { compiles fine }
      AddStrongType(d);              { <- compile error }
      AddStrongType(TStrongType(d)); { compiles fine }
      AddStrongType(w);              { <- compile error }
      AddStrongType(TStrongType(w)); { compiles fine }
      AddStrongType(s);              { compiles fine }
    end;
    

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use