Code Monkey home page Code Monkey logo

Comments (14)

rlebeau avatar rlebeau commented on September 23, 2024 1

I decided to go ahead and just {$IFDEF} the three values in Delphi 7 and earlier. They will get taken out anyway in Indy 11.

from indy.

rlebeau avatar rlebeau commented on September 23, 2024

How does it look now?

from indy.

GreySerg2 avatar GreySerg2 commented on September 23, 2024

Remain 1 warning:
[Warning] IdStackWindows.pas(1832): Return value of function 'TIdSocketListWindows.GetItem' might be undefined

from indy.

martijnlaan avatar martijnlaan commented on September 23, 2024

@GreySerg2 Which version of Delphi are you using?

@rlebeau The changes to TIdIOHandler.WriteFile and TCustomSSPIConnectionContext.UpdateAndGenerateReply actually cause (correct) warnings for me on Delphi 10.4:
[dcc32 Hint] IdIOHandler.pas(2576): H2077 Value assigned to 'TIdIOHandler.WriteFile' never used
[dcc32 Hint] IdAuthenticationSSPI.pas(1058): H2077 Value assigned to 'TCustomSSPIConnectionContext.UpdateAndGenerateReply' never used

from indy.

GreySerg2 avatar GreySerg2 commented on September 23, 2024

I wrote in Header - "Delphi 7".

from indy.

martijnlaan avatar martijnlaan commented on September 23, 2024

Sorry, didn't see that. Delphi 7 wasn't so good with some of these hints and could give invalid ones, for example when the code uses Result but also raises exceptions.

from indy.

GreySerg2 avatar GreySerg2 commented on September 23, 2024

If code will raise exception the return value of function will be undefined. The compiler of Delphi 7 write exactly about this. It's very easy to fix, I set result value at the beginning of function.

from indy.

martijnlaan avatar martijnlaan commented on September 23, 2024

Since there's no return value when an exception is raised by a function Delphi 7 is wrong, this was fixed in a later Delphi version. This is why newer versions will actually give a warning is the result value is set at the beginning anyway, as the code now does. There should be an IFDEF around the assignment.

from indy.

GreySerg2 avatar GreySerg2 commented on September 23, 2024

If I call a function with try..except and then will be work with result value of function - it will be undefined.

from indy.

martijnlaan avatar martijnlaan commented on September 23, 2024

Yes but this is not the case in TIdSocketListWindows.GetItem which you posted about above, nor in TIdIOHandler.WriteFile nor in TCustomSSPIConnectionContext.UpdateAndGenerateReply. They don't handle the exception so the function will raise it.

from indy.

rlebeau avatar rlebeau commented on September 23, 2024

If I call a function with try..except and then will be work with result value of function - it will be undefined.

If the caller decides to swallow an exception and use an undefined return value, that is the fault of the caller, not the callee. Even if the callee were to set its Result before raise'ing the exception, there is no guarantee that the value will reach the caller. If the caller wants to save the return value to a variable and use it even if an exception is raised, the except handler will have to assign a different value to the variable before letting the code move forward, eg:

try
  value := DoSomethingAndGetAValue();
except
  value := SomeOtherValue; // <-- here
end;
// use value as needed...

from indy.

rlebeau avatar rlebeau commented on September 23, 2024

There should be an IFDEF around the assignment.

I would really like to avoid having to do that. There are plenty of other functions throughout Indy that assign an initial Result value and then later raise an exception, and nobody complains about them warning about unused values.

Do we even know in which version of Delphi this issue was "fixed"?

I'm tempted to just revert my earlier change and let old compilers issue their warnings as before. Especially since support for old compilers is being dropped in Indy 11 anyway.

from indy.

martijnlaan avatar martijnlaan commented on September 23, 2024

I think you should revert the changes to TIdIOHandler.WriteFile and TCustomSSPIConnectionContext.UpdateAndGenerateReply then. The changes cause valid warnings under modern Delphi. Reverting them causes old Delphi to issues warnings again, but these warnings are not valid (and also not present in modern Delphi).

from indy.

GreySerg2 avatar GreySerg2 commented on September 23, 2024

Now all is Ok, all warnings are gone in Delphi 7.

from indy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.