Recent

Author Topic: txt can't be updated from TStringList.SaveToFile  (Read 5852 times)

nicolas_lazarus

  • New Member
  • *
  • Posts: 42
txt can't be updated from TStringList.SaveToFile
« on: October 11, 2010, 09:25:35 pm »
Hi all,

I found a strange behavior trying to save in a txt files twice.
The first one works fine, but when I try to save again at the same txt file, the file can't be updated.

More over, I tried deleting the txt file but then the application cannot creates the file again.




piece of  code
Code: [Select]
outputProcess := TStringList.Create;
memStream:=TMemoryStream.Create;
P := TProcess.Create(nil);
.
.
.
p.Output.Read((memStream.Memory+BytesRead)^,READ_BYTES);
.
.
.

outputProcess.LoadFromStream(memStream);
outputProcess.SaveToFile(pathLogs+PathDelim+'xxxx.txt');
.
.
finally
P.Free;
outputProcess.Free;
memStream.Free;


Can someone see what is wrong ?

Thanks in advance!

Nicolas
« Last Edit: October 11, 2010, 09:36:55 pm by nicolas_lazarus »

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: txt can't be updated from TStringList.SaveToFile
« Reply #1 on: October 12, 2010, 08:36:21 am »
I don't understand your code snippet. Probably, you have a sharing violation. Close the file by freeing TStringList and read from/write to the file after that. If you want to share information over one file look for "memory mapped file" if you intend to use Windows.
« Last Edit: October 13, 2010, 09:36:05 am by Ocye »
Lazarus 1.7 (SVN) FPC 3.0.0

nicolas_lazarus

  • New Member
  • *
  • Posts: 42
Re: txt can't be updated from TStringList.SaveToFile
« Reply #2 on: October 12, 2010, 07:44:03 pm »
Hi all,


I found the problem. It is not related to TStringList.SaveToFile();

the problem was started  after excecute SetCurrentDir(pathApplication).

Solved. :D

Thanks anyway !

Nicolas


 

TinyPortal © 2005-2018