Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Для новичков > не является целым значением


Автор: NZero 8.5.2010, 20:04
Все привет!!! Вот код программы

Код

unit test;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  egtr, ndoc, nd1, nd2, nd3, nd4, nd5, nd6, nd7, nd8, nd9, len: Integer;
  npas, l, s1, s2, s3, s4, s5, s6, s7, s8, s9, filename: string;
  myfile: TextFile;
  procedure passport(egtr,ndoc: Integer);
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
filename:='Count.ini';
if FileExists(filename) then
begin
AssignFile(myfile, 'Count.ini');
Reset(myfile);
ReadLN(myfile, s1);
nd1:=StrToInt(s1);
ReadLN(myfile, s2);
nd2:=StrToInt(s2);
ReadLN(myfile, s3);
nd3:=StrToInt(s3);
ReadLN(myfile, s4);
nd4:=StrToInt(s4);
ReadLN(myfile, s5);
nd5:=StrToInt(s5);
ReadLN(myfile, s6);
nd6:=StrToInt(s6);
ReadLN(myfile, s7);
nd7:=StrToInt(s7);
ReadLN(myfile, s8);
nd8:=StrToInt(s8);
ReadLN(myfile, s9);
nd9:=StrToInt(s9);
CloseFile(myfile);
end;
AssignFile(myfile, 'Count.ini');
Rewrite(myfile);
if ComboBox1.ItemIndex=0 then
begin
egtr:=1;
nd1:=nd1+1;
WriteLN(myfile, IntToStr(nd1));
passport(egtr, nd1);
end;
if ComboBox1.ItemIndex=1 then
begin
egtr:=2;
nd2:=nd2+1;
passport(egtr, nd2);
WriteLN(myfile, IntToStr(nd2));
end;
if ComboBox1.ItemIndex=2 then
begin
egtr:=3;
nd3:=nd3+1;
passport(egtr, nd3);
writeLN(myfile, IntToStr(nd3));
end;
if ComboBox1.ItemIndex=3 then
begin
egtr:=4;
nd4:=nd4+1;
passport(egtr, nd4);
writeLN(myfile, IntToStr(nd4));
end;
if ComboBox1.ItemIndex=4 then
begin
egtr:=5;
nd5:=nd5+1;
passport(egtr, nd5);
writeLN(myfile, IntToStr(nd5));
end;
if ComboBox1.ItemIndex=5 then
begin
egtr:=6;
nd6:=nd6+1;
passport(egtr, nd6);
writeLN(myfile, IntToStr(nd6));
end;
if ComboBox1.ItemIndex=6 then
begin
egtr:=7;
nd7:=nd7+1;
passport(egtr, nd7);
writeLN(myfile, IntToStr(nd7));
end;
if ComboBox1.ItemIndex=7 then
begin
egtr:=8;
nd8:=nd8+1;
passport(egtr, nd8);
writeLN(myfile, IntToStr(nd8));
end;
if ComboBox1.ItemIndex=8 then
begin
egtr:=9;
nd9:=nd9+1;
passport(egtr, nd9);
writeLN(myfile, IntToStr(nd9));
end;
CloseFile(myfile);
Edit3.Text:=npas;
Label1.Caption:=l;
end;
procedure passport(egtr, ndoc: Integer);
begin
len:=Length(npas);
npas:='0'+IntToStr(egtr)+'-'+'000'+IntToStr(ndoc);
l:=IntToStr(len);
end;
end.


Запускается, но при выборе ComboBox выдает сообщение ( см. рисунок)

Автор: Данкинг 8.5.2010, 21:08
А в ComboBox'е что выбрано?

Автор: kami 8.5.2010, 21:27
Цитата(Данкинг @  8.5.2010,  21:08 Найти цитируемый пост)
А в ComboBox'е что выбрано?

Имхо, здесь проблема не в комбобоксе, а в том что ничего не прочиталось из файла.
Цитата(NZero @  8.5.2010,  20:04 Найти цитируемый пост)
nd1:=StrToInt(s1);

NZero пройдись по F8 от начала этой процедуры, выясни, на какой строчке возникает исключение. от нее и пляши - какие значения имеют переменные в этой строке и что с ними делается...

Автор: Данкинг 8.5.2010, 21:43
Ну, в общем, да: особое внимание - на строки с IntToStr. smile 

Автор: NZero 9.5.2010, 22:16
Как раз после строчки nd1:=StrToInt(s1); выходит сообщение. Возможно что s1 читает весь файл и потом файл уже пустой?

Автор: Данкинг 9.5.2010, 23:04
Цитата(NZero @  9.5.2010,  23:16 Найти цитируемый пост)
Возможно что s1 читает весь файл и потом файл уже пустой? 

Вот и проверь, что там у тебя в s1.

Автор: NZero 10.5.2010, 00:54
Все получилось!!! Спасибо большое. Как говорится одна голова хорошо, а 2 лучше)))

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)