Delphi Type Narrowing

From: Ed (contacted2001_at_yahoo.co.uk)
Date: 08/31/04

  • Next message: Maarten Wiltink: "Re: Delphi Type Narrowing"
    Date: 31 Aug 2004 05:29:37 -0700
    
    

    Hi all,

    After wrestling with a bug on and off for over a week, I finally
    discovered that the programmer before me had mistakenly used the
    following:

    var
      TheData: TMemoryStream;
      DataOffset: Integer;
    .
    .
      TheData.Seek(soFromBeginning,DataOffset);

    when the seek signature is:

    function Seek(Offset: Longint; Origin: Word): Longint; override;

    Easy enough mistake to transpose the two parameters - much harder to
    spot that it had happend :-\ though. What I find rather disconcerting
    is that passing an integer as a parameter to a method that requires a
    word doesn't produce any compiler warnings or hints, much less a
    compile time error. IIRC in java any such type narrowing would
    require an explicit cast to allow compilation.

    Is this a missing feature in Delphi? Can anyone suggest a reason why
    this can happen e.g are there benefits from being able to do this or
    technical reasons why it must be so? I'm too tired and frustrated to
    think clearly about this and would greatly appreciate it if someone
    with more insight than myself could clarify this stuff.

    Off to the coffee machine now....

    TIA,

    Ed


  • Next message: Maarten Wiltink: "Re: Delphi Type Narrowing"

    Relevant Pages

    • Re: Delphi Type Narrowing
      ... > Easy enough mistake to transpose the two parameters - much harder to ... > word doesn't produce any compiler warnings or hints, ... > technical reasons why it must be so? ...
      (comp.lang.pascal.delphi.misc)
    • Re: How printf() works???????
      ... Getting something totally backwards is,of course, a mistake. ... is no evil intent in my correction. ... What he said to you about your compiler is beside the point and did not ... Therefore Robbie Hatley took your statement as correcting a ...
      (comp.lang.c)
    • Re: #define and (brackets)
      ... If I make a mistake, ... if the compiler knows enough to tell me ... due to some implicit type conversion say, then I define that conversion as ... That's automatic bug detection at compile time. ...
      (microsoft.public.vc.language)
    • Re: How printf() works???????
      ... Getting something totally backwards is,of course, a mistake. ... is no evil intent in my correction. ... What he said to you about your compiler is beside the point and did ... "Hey Robbie, you are an idiot to have said that my compiler is not good ...
      (comp.lang.c)
    • Re: How printf() works???????
      ... Getting something totally backwards is,of course, a mistake. ... What he said to you about your compiler is beside the point ... RHs whole reply was based on explaining the OPs code. ... fuss over *my* reply instead of answering directly to Robbie Hatley, ...
      (comp.lang.c)