
21.11.2012, 19:37
|
 |
Профессионал
|
|
Регистрация: 06.08.2012
Адрес: Кривой Рог
Сообщения: 1,791
Версия Delphi: Delphi 7, XE2
Репутация: 4415
|
|
Цитата:
Сообщение от SHIFT999
Код:
x:=min;
while x<max do
begin
for i:=0 to Length(formula) do
if formula[i]='x' then
begin
Delete(formula,i,1);
Insert(floattostr(x),formula,i);
end;
y:=ScriptControl.Eval(formula);
formula:=Edit1.Text;
Form1.Chart1.SeriesList[0].AddXY(x,y,' ',col);
x:=x+0.1;
end;
Похоже, теперь он прибавляет 0.1, притом у тот же, что и на следующем целом...
|
У меня вот так работает:
Код:
procedure TForm1.Button1Click(Sender: TObject);
const
formula: string = 'sin(x)';
var
SaveDecimalSeparator: Char;
i: Integer;
min, max, step, x, y: Extended;
s: string;
begin
min := 0;
max := 10;
step := 0.1;
SaveDecimalSeparator := DecimalSeparator;
try
DecimalSeparator := '.';
x := min;
while x < max do
begin
s := formula;
for i := Length(s) downto 1 do
begin
if s[i] = 'x' then
begin
Delete(s, i, 1);
Insert(FloatToStr(x), s, i);
end;
end;
y := ScriptControl.Eval(s);
Chart1.SeriesList[0].AddXY(x, y, ' ', clRed);
x := x + step;
end;
finally
DecimalSeparator := SaveDecimalSeparator;
end;
end;
Результат:

|