File Read/Write problems lazarus / 9-Editor ---------------------------------------------------------------------- forlornity · 2008-01-20 21:44 Hey again, I've got a problem writing to files (and possibly reading from, I can't tell as I haven't written it yet ), whenever I try and read from I file I have supposedly written to it outputs junk. The junk is the same for every variable I store in the file. The code is as follows: Code: [Select]procedure TServerConfigForm.FormShow(Sender: TObject); var    PZCSettings:TPZCSettings; begin    AssignFile(SettingsFile, 'settings.wtf');    If not fileexists('settings.wtf') then begin       ReWrite(SettingsFile);    end;    Reset(SettingsFile);      While not eof(SettingsFile) do begin       Read(SettingsFile, PZCSettings);       HostEdit.Text:=PZCSettings.Server;       UserEdit.Text:=PZCSettings.UserName;       PasswdEdit.Text:=PZCSettings.Password;    end;    CloseFile(SettingsFile); end; procedure TServerConfigForm.ApplyButtonClick(Sender: TObject); var    PZCSettings:TPZCSettings; begin    PZCSettings.Database:=DatabaseEdit.Text;    PZCSettings.Server:=HostEdit.Text;    PZCSettings.UserName:=UserEdit.Text;    PZCSettings.Password:=PasswdEdit.Text;      ReWrite(SettingsFile);    Write(SettingsFile, PZCSettings);    CloseFile(SettingsFile);    ServerConfigForm.Close; end; Also, the type definition is Code: [Select]TPZCSettings = record       Server:String;       UserName:String;       Password:String;       Database:String;   end; When I try and read from the file it gives a load of nonsense " ð­º ð­º ð­º ð­º ð­º!" Anyone able to tell me what's wrong? Thanks, Forlornity. ---------------------------------------------------------------------- theo · 2008-01-20 22:09 If you have AnsiString on (default, $H+) then your record contains 4 pointers. You can check this with: SizeOf(TPZCSettings) which will be 16 in your case on 32bit Machine (4*4 Byte). You save these Pointers, not the content of the Strings. What you can do is:   TPZCSettings = record       Server:String[20];       UserName:String[20];       Password:String[20];       Database:String[20];   end;   These Strings will be written afaik and SizeOf(TPZCSettings) should return 84. You'd better use TIniFile for this purpose, which handles AnsiString too. ---------------------------------------------------------------------- forlornity · 2008-01-21 00:42 Thanks man, setting the string length did the trick (as I'm sure is obvious to the more experienced). I expected it would be something similar to this as it was throwing up strange errors (the same type I get when attempting to read past the end of an array for instance). Again, thanks for the info, Forlornity