Jump to content
Ian Branch

"Value assigned to 'xxxxxxxx' never used" issue..

Recommended Posts

Hi Team,

D10.4.1.

I have the following code or equivalent in several places in a Unit and other apps.

      //
      if not FilterID1.Execute then
        dlgResult := False;
      //
      FilterValue := Trim(FilterID1.Value);
      //
      if FilterID1.Value.IsEmpty then
        dlgResult := False
      else
        dlgResult := True;
      //
      if dlgResult then
      begin
        if not TryStrToInt(FilterValue, iJobNo) then
        begin
          MessageBeep(MB_ICONERROR);
          showmessage('An Invalid Job # has been entered!');
        end
        else
          break
      end
      else
        ApplyFilter := false;

I keep getting the following warning..

Quote

[dcc32 Hint] MyFormFrm.pas(158): H2077 Value assigned to 'dlgResult' never used

Pointing to the "      if not FilterID1.Execute then dlgResult := False;"

 

Yet dlgResult is clearly used in the "if dlgResult then" test.

Is this a bug or a "known issue"? 

If not, how do I get rid of the annoying warning?

Aside from turning all H2077 warnings off.

 

Regards & TIA,

Ian

Edited by Ian Branch

Share this post


Link to post
13 hours ago, Ian Branch said:

I keep getting the following warning..

Pointing to the "      if not FilterID1.Execute then dlgResult := False;"

As you should be, because THAT value you are assigning to dlgResult at THAT point in the code is indeed NOT being used, so it doesn't matter what value you assign to dlgResult.  You are OVERWRITING that value afterwards, at "if FilterID1.Value.IsEmpty then dlgResult := False else dlgResult := True;" hence the compiler warning is correct.

Quote

Yet dlgResult is clearly used in the "if dlgResult then" test.

The compiler is not complaining that the dlgResult variable itself is not being used.  It is complaining that the VALUE you are assigning to the dlgResult variable after FilterID1.Execute() exits is not used, so there is no point in assigning that value at all.

 

I think you need to tweak this code a little.  Try something more like this:

dlgResult := FilterID1.Execute;
if dlgResult then
begin
  FilterValue := Trim(FilterID1.Value);
  dlgResult := not FilterValue.IsEmpty;
end;

if dlgResult then
begin
  if not TryStrToInt(FilterValue, iJobNo) then
  begin
    MessageBeep(MB_ICONERROR);
    ShowMessage('An Invalid Job # has been entered!');
  end
  else
    Break;
end
else
  ApplyFilter := False;

 

Edited by Remy Lebeau

Share this post


Link to post

Ahhhh.  Thank you Remy.

A little nuance I hadn't realised. 😞  Filed away for future reference.

Your restructure of the code showed me that the 

57 minutes ago, Remy Lebeau said:

else ApplyFilter := False;

was redundant.

 

Regards & Thank you again for the assist.

Ian

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×