Delphi Error: Got "untyped", expected "AnsiString" -
below sample file preview scheme project working on. there 2 listboxes on main form. first one, [lst_filelist], displays list of ".txt" files in directory [files], each labeled [order###.txt], ### beingness number 1 999. when procedure run, finds selected item in listbox, (a .txt file), , displays each individual line within file upon sec listbox [lst_filepreview].
although run it, error occurs on 21st line @ readln(selectedfile). error states (incompatible type: got "untyped", expected "ansistring").
i have looked error few hours now, no avail... help appreciated, give thanks you.
procedure tform1.btn_getpreviewclick(sender: tobject); var checkselect:integer; orderselect:string; i:integer; selectedfile:textfile; begin if lst_filelist.selcount > 0 begin checkselect:= 0 (lst_filelist.items.count - 1) if lst_filelist.selected [checkselect] begin orderselect:=lst_filelist.items[checkselect]; orderselect:=rightstr(orderselect,3); if fileexists('files\order'+orderselect+'.txt') begin assignfile(selectedfile,'files\order'+orderselect+'.txt'); reset(selectedfile); while not eof(selectedfile) begin lst_filepreview.items.add(readln(selectedfile)); // error occurs here: // end; closefile(selectedfile); end; end; end else showmessage('please select item first!'); end;
your code
lst_filepreview.items.add(readln(selectedfile)); tries utilize readln function. not. is, officially, procedure, function returning void (untyped). in reality, compiler-magic procedure, , depending on tries read, compiler inserts calls different runtime functions or procedures.
you may want rid of old pascal-style routines altogether, , utilize streams instead, now, try:
s: string ... readln(selectedfile, s); lst_filepreview.items.add(s); please read delphi docwiki notes @ standard routines , input-output, saying:
note: new programs, might want utilize file management classes , functions in system.classes , system.sysutils units. system.classes.tstream , descendent classes recommended general file handling in delphi (for related routines, see streams, reader , writers). text-file handling, tstreamreader , tstreamwriter recommended on calling write , writeln. api categories index contains lists of related routines , classes.
and if lst_filepreview in fact tlistbox, can do:
lst_filepreview.items.loadfromfile('files\order'+orderselect+'.txt'); and save entire reading code. utilize tmemo instead , do:
filepreviewmemo.lines.loadfromfile('files\order'+orderselect+'.txt'); delphi compiler-errors pascal var lazarus
No comments:
Post a Comment