Показать сообщение отдельно
  #6  
Старый 03.09.2012, 16:33
qazpos qazpos вне форума
Прохожий
 
Регистрация: 02.09.2012
Сообщения: 5
Репутация: 10
По умолчанию

Цитата:
Сообщение от poli-smen
А если убрать этот код ошибка появляется? И где объявления переменных (например str)?
Я немного переписал и дописал код, исключил возможность обработки пустых файлов:
Код:
type
    Ttime = record
        dd,hh,mm:byte;
    end;
    Tzap1 = record
        town1,town2:string [30];
        price:integer;
        time:Ttime;
    end;
    Tzap2 = record
        NalWay:boolean;
        price:integer;
        time:Ttime;
    end;

  public
    townsfile: TextFile;
    waysfile: File of Tzap1;
    townsmas: array of string [30];
    waysmas: array of array of tzap2;
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}


procedure TForm1.FormCreate(Sender: TObject);
var nmax,i,num1,num2:integer;
    str:string;
    way:Tzap1;
    sluzh:tzap2;
begin
assignfile (townsfile, 'Towns');
assignfile (waysfile, 'Ways');
if not FileExists ('Towns') then
    begin
    rewrite (townsfile);
    closefile (townsfile);
    end;
reset (townsfile);
if not FileExists ('Ways') then
    begin
    rewrite (waysfile);
    closefile (waysfile);
    end;
reset (waysfile);
if not eof (townsfile) then
    begin
    nmax:=filesize (townsfile);
    SetLength (townsmas, nmax);
    SetLength (waysmas, nmax);
    nmax:=nmax-1;
    for i:=0 to nmax do
        begin
            readln (townsfile, str);
            townsmas [i]:=str;
        end;
    combobox1.Items.LoadFromFile('towns');
    combobox2.Items.LoadFromFile('towns');
    sluzh.NalWay:=false;
    sluzh.price:=0;
    sluzh.time.dd:=0;
    sluzh.time.hh:=0;
    sluzh.time.mm:=0;
    for num1:=0 to nmax do
        for num2:=0 to nmax do
            waysmas[num1,num2]:=sluzh;
    while not eof (waysfile) do
        begin
        num1:=-1;
        num2:=-1;
        read (waysfile, way);
        for i:=0 to nmax do
            begin
            if way.town1=townsmas[i] then
                num1:=i;
            if way.town2=townsmas[i] then
                num2:=i;
            end;
        if num1>=0 then
            begin
            waysmas[num1,num2].NalWay:=true;
            waysmas[num1,num2].price:=way.price;
            waysmas[num1,num2].time:=way.time;
            end;
        end;
    combobox1.Text:=townsmas[0];
    combobox2.Text:=townsmas[0];
    end;
closefile (townsfile);
closefile (waysfile);
end;
Если убрать код, то ошибка не появляется. Скажу больше, ошибка не появляется, если убрать 93 и 94 строки
Ответить с цитированием