Why is the rectangle the same color after the ELSE condition? lazarus / 39-Graphics ---------------------------------------------------------------------- Tomi · 2023-05-30 13:04 In the FormPaint, this code always gives blue rectangles, even if the unit is not belong to the player, when the rectangle should be yellow. What is wrong with this? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if numberofunits>0 then          begin            for edb:=0 to numberofunits-1 do            begin              if gameunits[edb].exists=true then              begin               if gameunits[edb].unitowner='player' then                  canvas.brush.Color:=clBlue               else                   canvas.brush.Color:=clYellow;               radarobj.left:=gameunits[edb].xplace;               radarobj.top:=gameunits[edb].yplace;               radarobj.right:=radarobj.left+2;               radarobj.bottom:=radarobj.top+2;               canvas.rectangle(radarobj);              end;            end;end; ---------------------------------------------------------------------- Handoko · 2023-05-30 13:19 Try this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if numberofunits>0 then  begin    for edb:=0 to numberofunits-1 do    begin      if gameunits[edb].exists then      begin       if LowerCase(gameunits[edb].unitowner) = 'player' then         canvas.brush.Color:=clBlue       else         canvas.brush.Color:=clYellow;       radarobj.left:=gameunits[edb].xplace;       radarobj.top:=gameunits[edb].yplace;       radarobj.right:=radarobj.left+2;       radarobj.bottom:=radarobj.top+2;       canvas.rectangle(radarobj);    end;    end;  end; We need to the whole source code to be sure what's wrong with your code. My guess is case issue, see line #7. It usually good to convert the string to upper/lower case before comparison if you're not sure the case of the text it compares to. But better, don't use string, use enum type instead: https://wiki.freepascal.org/Enum_Type ---------------------------------------------------------------------- Tomi · 2023-05-30 14:36 Quote from: Handoko on May 30, 2023, 03:19:21 pmWe need to the whole source code to be sure what's wrong with your code. In my program, there are units controlled by the player and controlled by the computer, too. The unitowner field holds these two attributions in string format ('player' or 'enemy'). And I would like draw a blue rectangle on the radar in case of player's units, and yellow rectangles in case of enemy units. But now the program draws blue rectangles in both cases. Only this piece of code handles this drawing. It seems good, but it is not... ---------------------------------------------------------------------- Handoko · 2023-05-30 14:55 Can you provide the whole source code? Or the code after removing all other unnecessary items. Simply showing some lines of code isn't helpful because bug can be hidden in anywhere in the code. We need the the code that we can compile, run and inspect so we can tell you where goes wrong. Copy all the source files into a new folder but excluding the binary (exe file), *.bak, lib and backup folders. Compress the folder and sent the zip file to the forum. ---------------------------------------------------------------------- Bart · 2023-05-30 15:56 Add some debugln statements to inspect the content of relevant variables (e.g. gameunits[edb].unitowner). It's unlikely (very unlikely) the compiler is wrong, mos likely you made a mistake somewehere. Bart ---------------------------------------------------------------------- Tomi · 2023-05-31 09:16 Interesting and I don't know why, but the drawing with the two colors now works with this code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if gameunits[edb].unitowner='player' then                  canvas.pen.Color:=clBlue               else                   canvas.pen.Color:=clYellow;So, I used pen instead of brush. ---------------------------------------------------------------------- zeljko · 2023-05-31 12:35 Pen IS correct for rectangle, Brush is used to fill rectangle. So if you want yellow rectangle with red border you should set: Pen.Color := clRed; Brush.Color := clYellow. ---------------------------------------------------------------------- Tomi · 2023-06-01 08:56 A-ha; thanks, Zeljko! Maybe the rectangle with 2x2 pixels dimensions only shows its border and not a filled area, therefore I couldn't see the correct colors(?).