Home Value assigned never used. Delphi bug or code bug?
Reply: 0

Value assigned never used. Delphi bug or code bug?

user2323
1#
user2323 Published in May 21, 2018, 9:16 am

This code is part of a third party component I am using in my application. I am trying to solve all possible problems related to hint in my application. But I can not understand this. Delphi Compiler marks first line of this code for a hint "Value assigned to NewState never used!. I just want to understand situation

  NewState := STATE_UNCHECKED;   //Value assigned never used?Really?
  while ( Node <> nil ) and ( Node.Parent <> nil ) do
  begin
    Node := Node.Parent.GetFirstChild;
    CheckedCount := 0;
    UnCheckedCount := 0;
    while True do
    begin
     ....
      if ( Node.StateIndex = STATE_PARTCHECKED ) or
         ( ( CheckedCount > 0 ) and ( UnCheckedCount > 0 ) ) then
      begin
        NewState := STATE_PARTCHECKED; ///assign value on condition
        Break;
      end;

      if Node.GetNextSibling = nil then
      begin
        if CheckedCount > 0 then
          NewState := STATE_CHECKED //assign value on condition
        else
          NewState := STATE_UNCHECKED;
        Break;
      end
      else
        Node := Node.GetNextSibling;
    end;
    Node := Node.Parent;
    if Node <> nil then
      SetState( Node,  NewState );
  end;

But when both of this statments are false this value must be used.Am i wrong?

 if ( Node.StateIndex = STATE_PARTCHECKED ) or
             ( ( CheckedCount > 0 ) and ( UnCheckedCount > 0 ) ) then

and

if Node.GetNextSibling = nil then

UPDATE

answers are correct .The Break Statment runs only after a new value assigned to variable and overwriting first value. then assigned value is never used.

a Minimal, Complete, and Verifiable example:

procedure TForm1.btn1Click(Sender: TObject);
Var x,y,z,k:integer;
begin
   X:=1;
   Y:=strtoint(edit1.text);
   Z:=Strtoint(edit2.text);
   K:=Strtoint(edit3.text);
     while true do
     begin
      If Z=y*2 then
      begin
        X:=2;
        Break;
      end;

      If Y=3 then
      begin
        If K=7 then
        begin
        X:=3;
        Break;
        end
        else
        begin
        x:=6;
        Break;
        end;
      end
     end;

    showmessage(inttostr(x));

end;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.446567 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO