[lazarus] files: I give up
Now I really dont know whats wrong, please help me. The writting code: procedure TForm1.Button1Click(Sender: TObject); var archivo: File of String; cadena: String; begin cadena := Edit1.Text; ShowMessage(cadena); System.Assign(archivo, 'archivo.dat'); System.Rewrite(archivo); Write(archivo, cadena); System.Close(archivo); end; The Reading code (Another app): procedure TForm1.Button1Click(Sender: TObject); var archivo: file of string; cadena: string; begin System.Assign(archivo, 'archivo.dat'); System.Reset(archivo); read(archivo, cadena); System.Close(archivo); Edit1.Text := cadena; end; When I run the writting app, it seems to work, the archivo.dat file is created. But when I run the Reading app, and press the read button, it apperas an error message who say something about Access violation. Please help! Have mercy Regards, German
Re: [lazarus] files: I give up
- Original Message - From: German C. Basisty [EMAIL PROTECTED] To: lazarus@miraclec.com Sent: Tuesday, July 17, 2007 7:46 PM Subject: [lazarus] files: I give up Now I really dont know whats wrong, please help me. The writting code: procedure TForm1.Button1Click(Sender: TObject); var archivo: File of String; cadena: String; begin cadena := Edit1.Text; ShowMessage(cadena); System.Assign(archivo, 'archivo.dat'); System.Rewrite(archivo); Write(archivo, cadena); System.Close(archivo); end; The Reading code (Another app): procedure TForm1.Button1Click(Sender: TObject); var archivo: file of string; cadena: string; begin System.Assign(archivo, 'archivo.dat'); System.Reset(archivo); read(archivo, cadena); System.Close(archivo); Edit1.Text := cadena; end; When I run the writting app, it seems to work, the archivo.dat file is created. But when I run the Reading app, and press the read button, it apperas an error message who say something about Access violation. Please help! Have mercy Regards, German It looks like you speak spanish, if you want, see me in the #lazarus-es IRC channel in freenode, everybody is invited btw. Jesus Reyes A. _ To unsubscribe: mail [EMAIL PROTECTED] with unsubscribe as the Subject archives at http://www.lazarus.freepascal.org/mailarchives
Re: [lazarus] files: I give up
German C. Basisty ?: Now I really dont know whats wrong, please help me. The writting code: procedure TForm1.Button1Click(Sender: TObject); var archivo: File of String; cadena: String; begin cadena := Edit1.Text; ShowMessage(cadena); System.Assign(archivo, 'archivo.dat'); System.Rewrite(archivo); Write(archivo, cadena); System.Close(archivo); end; The Reading code (Another app): procedure TForm1.Button1Click(Sender: TObject); var archivo: file of string; cadena: string; begin System.Assign(archivo, 'archivo.dat'); System.Reset(archivo); read(archivo, cadena); System.Close(archivo); Edit1.Text := cadena; end; When I run the writting app, it seems to work, the archivo.dat file is created. But when I run the Reading app, and press the read button, it apperas an error message who say something about Access violation. Please help! Have mercy Regards, German The idea is to change the type of your file to Text; I.e. procedure TForm1.Button1Click(Sender: TObject); var archivo: Text; cadena: String; begin cadena := Edit1.Text; ShowMessage(cadena); System.Assign(archivo, 'archivo.dat'); System.Rewrite(archivo); Write(archivo, cadena); System.Close(archivo); end; The Reading code (Another app): procedure TForm1.Button1Click(Sender: TObject); var archivo: Text; cadena: string; begin System.Assign(archivo, 'archivo.dat'); System.Reset(archivo); read(archivo, cadena); System.Close(archivo); Edit1.Text := cadena; end; Also, the good idea is to check the file existence before open it with FileExists() function. *Regards, Alexey.*
Re: [lazarus] files: I give up
Also, it depends on exactly what you are trying to save. There are other ways of saving strings than using the low level file routines. They may be less efficient, but involve less programming. If your strings are in a TStrings or TStringList object, you can simply use the SaveToFile and LoadFromFile methods. This gives you lots of good ways to work with the strings as well. If you just want to save odd form or control properties, there is the sessionproperties system (Congratulations to whoever invented that, by the way!). If you want to work with large slabs of text, the low level routines might be best. If you are just experimenting, don't let me put you off! cheers, John _ To unsubscribe: mail [EMAIL PROTECTED] with unsubscribe as the Subject archives at http://www.lazarus.freepascal.org/mailarchives