请看下面这段代码:
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));
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)edtColor.Text := '$' + IntToHex (TColor (RGB (R, G, B)), 8);
edtColor.SetFocus;
end;