Board index » delphi » Reading tabs and line breaks from text files
Tom Edwards
![]() Delphi Developer |
Reading tabs and line breaks from text files2004-04-11 01:26:47 AM delphi191 I'm having a very strange problem with my program. It is designed to add and remove entries from an xml file - this it does without any problems. The catch is that when it removes an entry it must create a new file and write the contents of the entry to it, and vice versa. Reading a file into the xml also presents no problems, but when I try to make it write an entry the initial tab space and the final carriage return are both recorded as spaces. I have tried appending a line break, and I have tried adding a tab in before the main chunk of data is written, but to no avail. No matter how hard I try the output is *always* with a space at both ends of the file - I know the information is lost when the new file is written to because the xml entry is correct. The offending code: For i := 0 TO MainForm.Proto_List.Items.Count-1 do If MainForm.Proto_List.Checked[i] = false then begin MainForm.Preset_Items.Items.Add('Unchecked item found: entry ' + inttostr(i)); FileName := Filesearch(MainForm.Proto_List.Items[i] + '.ent', XMLDir); if Filename = '' then begin CreateFile (pChar(XMLDir+ProtoEntries[1,i]+'.ent'), GENERIC_READ, GENERIC_WRITE, nil, FILE_SHARE_WRITE, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, ); AssignFile(CharPipe,XMLDir+ProtoEntries[1,i]+'.ent'); Rewrite(CharPipe); For i2 := 1 TO length(ProtoEntries[2,i])* do Write(CharPipe,ProtoEntries[2,i][i2]); CloseFile(CharPipe);** for i2 := 0 TO 2 do begin ProtoEntries[i2,i]:= ''; MainForm.Preset_Items.Items.Add('Unchecked entry '+inttostr(i)+' deleted from array'); MainForm.Preset_Items.Items.Add(''); end; end else ... I am using Preset_Items as a temporary log to help me diagnose problems. CharPipe is naturally a file of char (changing to file of text and plain file has no effect), and ProtoEntries (dynamic array) is the temporary storage I use to organise exactly what will be appended to the xml file. Columnn 0 is the ID, 1 the Name, 2 the actual entry. The fields are all correct. * adding +90 at the end of the line gives me the following: "VF ???? ? C:\Program Files\Microsoft Games\Age of Mythology\XML Entries\*.ent VF ?". I can only assume this is a fragment of the executable seeing as the string is XMLDir, up to *.ent. Wha? ** Opening up a TextPipe and telling it to append a Writeln('') has no effect - surely it should add an extra line break to the end of the file? |