title: Delphi String unreliable
body: <p>Hello im currently creating a pretty heavy application which relay on another applications threads and also grabs the handle. therefore if that application would freeze so does mine and it does lag a bit form time to time while the target software does heavy loading)</p>
  
  <p>The issue is that if somehow the more heavy application "Lag" i get unexpected issues with strings and they give me unreliable outputs.</p>
  
  <p>Anyone have any idea why this is happening and how i can solve this or work around this?</p>
  
  <p>My currently solution i have been using is belove, however thats not really what i want to do since it does make the runtime very unreliable due to the fact i cant be sure about the outcome.</p>
  
  <pre><code>function GetInt(MyNum:string):integer;
  begin
    try
      result := strtoint(MyNum);
    except
      result := 0;
    end;
  end;
  </code></pre>
  
  <hr>
  
  <p>As an example i made this script and suddenly i got the $ReBEFF is not a valid integer. (all of the sudden it have been running fine for hours)</p>
  
  <p>oldB is a Byte which is handles as a number converted to hexadecimal. oldB is set to always 0 it should never change especially not to Re which is not even within the hexadecimal number system</p>
  
  <pre><code>xx0000 = B
  00xx00 = G
  0000xx = R
  </code></pre>
  
  <p>example script (this is not the only codepart which have had issues with strings, it appers randomly for no reason all over the application)</p>
  
  <pre><code>var
    oldR:byte = 0;
    oldG:byte = 30;
    oldB:byte = 0;
    _Down:bool = false;
  
  function GetColor(R, G, B:byte):integer;
  var
    MyColor:string;
  begin
    MyColor := '';
    MyColor := MyColor + inttohex(B, 2);
    MyColor := MyColor + inttohex(G, 2);
    MyColor := MyColor + inttohex(R, 2);
    result := strtoint('$' + MyColor);
  end;
  
  procedure TMainF.DonateColorTimer(Sender: TObject);
  var
    MyColor:integer;
  begin
  
    oldR := 255;
  
    if _Down then begin
      dec(oldG, 10);
      if oldG &lt;= 0+30 then
        _Down := false;
    end else begin
      inc(oldG, 10);
      if oldG &gt;= 255-30 then
        _down := true;
    end;
  
    oldB := 0;
  
    MyColor := GetColor(oldR, oldG, oldB);
  
    if MyColor = 0 then
      exit;
  
    Label32.Font.Color := MyColor;
    Label33.Font.Color := MyColor;
  end;
  </code></pre>
  
  <hr>
  
  <p>When i did stress my application i did manage to get access error FFFFFFFC (-1 in an array?) in a codepart of the application which is in the structure itself not in my codeparts (the codepart was running even before my GUI is created when i rerun the application and tested with a debugger) sadly i cant manage to to repeat to locate it.</p>
  
  <p>however it feels that somehow some function from the "library in delphi" cant handle the "lag" and it overlap itself and messup the string.</p>
  
  <p>Im using RAD Studio XE 8</p>
  
  <p>Another Example that got messedup all of the sudden</p>
  
  <pre><code>function GetAppPath:string;
  var
    Buffer: Array[0..260] of Char;
    Path:string;
  begin
    try
      GetModuleFileName(hInstance, Buffer, Length(Buffer));
      Path := ExtractFilePath(Buffer);
      result := Path;
    except
    end;
  end;
  
  Should have returned D:\Download\Finished\Apps\
  returned D:\Download\Finished\A#ps\
  </code></pre>