delphi - How do I load a chess board into program once saved? -


i have procedure saves chess board text file. trying read board in program once saved. when call procedure error.

enter image description here

code have loading in board.

procedure loadboard(var board : tboard); var   fptr:text;   i,j,x:integer;   line:string;   load:char;  begin   write('do want load game? (enter y yes)');   readln(load);   if (ord(load) >= 97) , (ord(load) <= 122)     load := chr(ord(load) - 32);    if load='y'     begin       assignfile(fptr,'sboard.txt');       reset(fptr);       i:=1;       repeat         readln(fptr,line);         j:=1;         x:=1;         repeat           begin             if (line[x]<>',') , (line[x+1]<>',')                           begin                 board[i,j][1]:=line[x];                 board[i,j][2]:=line[x+1];               end;             if line[x]=','                           j:=j+1;               x:=x+1;           end;         until j=9;         i:=i+1;       until i=9;       close(fptr);     end; end; 

you access violation exception because string members in board array empty (length zero) , therefore have no accessible character positions.

to fix present code, should use setlength() on each string member before assign content character positions. have not shown strings contain, know set length should be.

on other hand, in previous answer questions have been adviced several other methods save chess board. should review , possibly choose 1 of them. polite respond answers , maybe tell why did not select them. maybe not able explain benefits.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -