Delphi - Store and read 2d array from text file -
this question has answer here:
- how save contents of 2d array file 3 answers
i trying store 2d array holds characters, text file in comma separated values (csv) format. have been semi able store array text file dont think allow read there no new line @ end of end of each line end of array (board[1][8]) example. have been unable read informatoin array.
this code storing array text file
const boarddimension = 8; type tboard = array[1..boarddimension, 1..boarddimension] of string; procedure savegame(board : tboard); var filenm : textfile; rankcount : integer; filecount : integer; begin assignfile(filenm, 'savedgame.txt'); rewrite(filenm); rankcount :=1 boarddimension begin filecount := 1 boarddimension-1 begin write(filenm,board[rankcount,filecount],','); end; write(filenm,board[rankcount,boarddimension]); end; closefile(filenm); writeln('game saved'); end; this code reading text file back, getting error states function copy2symbdel undeclared have included strutils in using statement
procedure loadgame(var board :tboard); var filenm : textfile; rankcount : integer; filecount : integer; text : string; begin assignfile(filenm, 'savedgame.txt'); reset(filenm); rankcount := 1 boarddimension begin readln(filenm,text); filecount := 1 boarddimension -1 begin board[rankcount,filecount] := copy2symbdel(text, ','); end; board[rankcount,boarddimension] := text; end; end; how can store , read 2d array in delphi/pascal
thank you
copy2symbdel freepascal library function not available in delphi. described this:
function copy2symbdel( var s: string; symb: char ):string;description
copy2symbdel determines position of first occurrence of symb in string s , returns characters position. symb character not included in result string. returned characters , symb character, deleted string s, after right-trimmed. if symb not appear in s, whole of s returned, , s emptied.
in delphi function implemented this:
function copy2symbdel(var s: string; symb: char): string; var i: integer; begin := pos(symb, s); if = 0 begin result := s; s := ''; end else begin result := copy(s, 1, i-1); s := trimright(copy(s, i+1, maxint)); end; end;
Comments
Post a Comment