Deiphi编译优化导致的死循环

2/4/2006来源:Delphi教程人气:12283

 

请看下面这段代码:

PRocedure TForm1.Button1Click(Sender: TObject);
var
  strColor: string;
  i, R, G, B, p: integer;
  strlist: TStringList;
begin
  strColor := medt.Text + '-';
  strlist := TStringList.Create;
  try
    for R := 0 to 2 do       //把变量R改为i正常
    begin
      //showmessage(inttostr(r));   加上这句也正常了 循环体内读过R 值
      p := pos('-', strColor);
      strlist.Add(copy(strColor, 0, p-1));
      delete(strColor, 1, p);
    end;

    R := strToint(strlist[0]);
    G := strToint(strlist[1]);
    B := strToint(strlist[2]);
  finally
    strlist.Free;
  end;

  Self.Color := TColor (RGB (R, G, B));

  edtColor.Text := '$' + IntToHex (TColor (RGB (R, G, B)), 8);

  edtColor.SetFocus;
end;