Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 27.06.2013, 22:54   #1
LLIALLIJIbIK
Пользователь
 
Регистрация: 26.08.2010
Сообщений: 51
По умолчанию Ошибка в Classes и в SysUtils

Дорогие форумчане, подскажите по какой причине по нажатию на кнопку:

Код:
procedure TCalculation.SpeedButton6Click(Sender: TObject);
Var
  i,k,j:integer;
begin
  countt:=10;
  for i:=1 to 34 do
    ForceValGraph[i-1]:=StrToFloat(StringGrid1.Cells[1,i]);
  SpeedButton6.Enabled:=False;
  for k:=0 to 33 do begin
    if MainForce[k]>ForceValGraph[k] then begin
      tmax:=MainForce[0];
      imax:=0;
      for i:=1 to 33 do begin
        if tmax<MainForce[i] then begin
          tmax:=MainForce[i];
          imax:=i;
        end;
      end;
      Chart1.SeriesList.Clear;
      Chart1.AddSeries(TLineSeries.Create(self));
      for j:=0 to 33 do
        Chart1.Series[0].AddXY(Frequency[j],MainForce[j]);
      Calculation.Chart1.Series[0].SeriesColor:=clRed;
      Calculation.Chart1.AddSeries(TLineSeries.Create(self));
      for j:=0 to 33 do
        Calculation.Chart1.Series[1].AddXY(Frequency[j],ForceValGraph[j]);
      Calculation.Chart1.Series[1].SeriesColor:=clBlue;      Calculation.Chart1.LeftAxis.SetMinMax(Calculation.Chart1.Series[0].MinYValue,Calculation.Chart1.Series[1].MaxYValue+1000);
      ShowMessage('Требуется оптимизация');
      GroupBox1.Visible:=True;
      Edit1.Text:='5000';
      Edit2.Text:='50000';
      Edit3.Text:='0.004';
      Edit4.Text:='0.2';
      Edit7.Text:='50';
      Edit8.Text:='150';
      Edit9.Text:='100';
      Calculation.Height:=836;
      SpeedButton1.Enabled:=False;
      break;
    end
    else begin
    Chart1.SeriesList.Clear;
        Chart1.AddSeries(TLineSeries.Create(self));
        for j:=0 to 33 do
          Chart1.Series[0].AddXY(Frequency[j],MainForce[j]);
        Calculation.Chart1.Series[0].SeriesColor:=clGreen;
        Calculation.Chart1.AddSeries(TLineSeries.Create(self));
        for j:=0 to 33 do
          Calculation.Chart1.Series[1].AddXY(Frequency[j],ForceValGraph[j]);
        Calculation.Chart1.Series[1].SeriesColor:=clBlue;       Calculation.Chart1.LeftAxis.SetMinMax(Calculation.Chart1.Series[0].MinYValue,Calculation.Chart1.Series[1].MaxYValue+1000);
        ShowMessage('Задача решена. Оптимизация не требуется');
        break;
        end;
  end;
end;
появляется ошибка "Project Project2.exe raised exception class EAccessViolation with message 'Access violation at address 0041D51B in module 'Project2.Exe'. Read of address 40FB5BCC'. Process stopped. Use Step or Run to continue". В разделе Classes:
Код:
procedure TComponent.Notification(AComponent: TComponent;
  Operation: TOperation);
var
  I: Integer;
begin
  if (Operation = opRemove) and (AComponent <> nil) then
    RemoveFreeNotification(AComponent);
  if FComponents <> nil then
  begin
    I := FComponents.Count - 1;
    while I >= 0 do
    begin
      TComponent(FComponents[I]).Notification(AComponent, Operation); //в этой строке
      Dec(I);
      if I >= FComponents.Count then
        I := FComponents.Count - 1;
    end;
  end;
end;
И второй вопрос. Когда я читаю из файла, возникает ошибка "Project Project2.exe raised exception class EConvertError with message "' is not a valid floating point value'. Process stopped. Use Step or Run to continue." в разделе SysUtils:

Код:
procedure ConvertErrorFmt(ResString: PResStringRec; const Args: array of const); local;
begin
  raise EConvertError.CreateResFmt(ResString, Args);
end;
LLIALLIJIbIK вне форума Ответить с цитированием
Старый 27.06.2013, 22:55   #2
LLIALLIJIbIK
Пользователь
 
Регистрация: 26.08.2010
Сообщений: 51
По умолчанию

Чтение из файла:

Код:
procedure TVib.SpeedButton2Click(Sender: TObject);
var
  FileDir:String;
  i,j:integer;
  buf:string[80];
  F:TextFile;
  cb1,cb2,cb3:integer;
begin
  FileDir:='c:\vibro.fvib';
  OpenDialog1.Filter := 'Файлы VIB|*.fvib';
  if OpenDialog1.Execute then begin
    AssignFile(F,FileDir);
    Vib.Caption:=Vib.Caption+' - '+OpenDialog1.FileName;
    Reset(F);
    ReadLn(F, count);
    //count:=StrToInt(buf);
    ReadLn(F,t);
    //t:=StrToInt(buf);
    ReadLn(F,buf);
    Vib.Label5.Caption:=buf;
    ReadLn(F, buf);
    Vib.Label7.Caption:=buf;
    SetLength(Mechanism,count);
    for i:=0 to (count-1) do
      ReadLn(F,Mechanism[i]);
      //Mechanism[i]:=StrToFloat(buf);
    SetLength(Abscissa,count);
    for i:=0 to (count-1) do
      ReadLn(F,Abscissa[i]);
      //Abscissa[i]:=StrToFloat(buf);
    SetLength(Ordinate,count);
    for i:=0 to (count-1) do
      ReadLn(F,Ordinate[i]);
      //Ordinate[i]:=StrToFloat(buf);
    SetLength(VibroNum,count);
    for i:=0 to (count-1) do
      ReadLn(F,VibroNum[i]);
      //VibroNum[i]:=StrToInt(buf);
    SetLength(Stiffness,count);
    for i:=0 to (count-1) do
      ReadLn(F,Stiffness[i]);
      //Stiffness[i]:=StrToFloat(buf);
    SetLength(Path,count);
    for i:=0 to (count-1) do
      ReadLn(F,Path[i]);
      //Path[i]:=buf;
    SetLength(StringGridArr,34,t);
    for j:=0 to t-1 do begin
      for i:=0 to 33 do
        ReadLn(F,StringGridArr[i,j]);
        //StringGridArr[i,j]:=StrToFloat(buf);
    end;
    ReadLn(F, Mp);
    //Mp:=StrToFloat(buf);
    ReadLn(F, Lp);
    //Lp:=StrToFloat(buf);
    ReadLn(F, Bp);
    //Bp:=StrToFloat(buf);
    ReadLn(F, Lpl);
    //Lpl:=StrToFloat(buf);
    ReadLn(F, Bpl);
    //Bpl:=StrToFloat(buf);
    ReadLn(F, Hpl);
    //Hpl:=StrToFloat(buf);
    ReadLn(F, Cf);
    //Cf:=StrToFloat(buf);
    ReadLn(F, cb1);
    ReadLn(F, cb2);
    ReadLn(F, cb3);
    //if counter=1 then begin
    ReadLn(F, buf);
    Mpmin:=StrToFloat(buf);
    ReadLn(F, buf);
    Mpmax:=StrToFloat(buf);
    ReadLn(F, buf);
    Hplmin:=StrToFloat(buf);
    ReadLn(F, buf);
    Hplmax:=StrToFloat(buf);
    SetLength(Kmmin,count);
    for i:=0 to count-1 do begin
      ReadLn(F, buf);
      Kmmin[i]:=StrToFloat(buf);
    end;
    SetLength(Kmmax,count);
    for i:=0 to count-1 do begin
      ReadLn(F, buf);
      Kmmax[i]:=StrToFloat(buf);
    end;
    ReadLn(F, buf);
    kbmin:=StrToFloat(buf);
    ReadLn(F, buf);
    kbmax:=StrToFloat(buf);
    ReadLn(F, buf);
    nos:=StrToInt(buf);
    for i:=1 to 34 do begin
      ReadLn(F,buf);
      Calculation.StringGrid1.Cells[1,i]:=buf;
    end;
    //end;
    CloseFile(F);
LLIALLIJIbIK вне форума Ответить с цитированием
Старый 27.06.2013, 22:58   #3
Stilet
Белик Виталий :)
Старожил
 
Аватар для Stilet
 
Регистрация: 23.07.2007
Сообщений: 57,097
По умолчанию

Цитата:
StrToFloat(buf);
Вот место потенциальной ошибки.
Используй StrToFloatDef(); или TryStrToFloat();
I'm learning to live...
Stilet вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Ошибка несоответствия типов после подключения System и Classes Alex Cones Общие вопросы Delphi 9 26.11.2017 10:36
Избавиться от модулей SysUtils и Classes RageGod Общие вопросы Delphi 10 13.02.2013 01:40
Вставить текущую дату и время в строку, не используя SysUtils. Alex Cones Общие вопросы Delphi 8 16.12.2009 03:13
BinToHex из Classes. Как юзать и скормить ей большой String Alex Cones Общие вопросы Delphi 5 05.11.2009 17:18
Windows, Messages,SysUtils,Variants,... Рустам Общие вопросы Delphi 5 04.02.2008 08:34