Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving file, something wierd is happening!

Status
Not open for further replies.

simmo09

Programmer
Apr 22, 2009
82
GB
Hello, im saving alot of files, the paths are assigned in a listbox, eg the listbox could look like this:

E:\Delphi\My Folder\abc.txt
E:\Delphi\My Folder\def.txt
E:\Delphi\My Folder\ghi.txt

i can save these no problem, the problem im experiencing though is this:

i can view these files by browing through a treeview, and then the TMemo loads the appropriate file, but after i have saved all the files, clicking the files in the treeview show nothing.

IT IS NOT A PROBLEM WITH THE CODE THOUGH...., if i open the files from windows into notepad or wordpad the files are blank, empty, contain nothing!

however, if i close the program, the files are normal again, so rerunning my program, browsing through the treeview again works.

Ive tried using CloseFile but im not sure, and not so good with File I/O operations.

I would be grateful if anyone could explain why the files are blank when i overwrite them, but become normal when i close the program????

Thank You!!!
 
Are you forgetting to close the files in time, or are not flushing them to disk periodically? I would suppose that some cleanup is being performed and the rest of the buffers are being flushed to disk on termination of your program.

Of course that's just a guess, we would have to see some code to say more.

Measurement is not management.
 
i found the problem preventing the files to save and close correctly, its the involvment of a TTimer:

Code:
procedure SaveFiles;
begin
  try
    ..
    ..
    ..save files..
  finally
    {show progress}
    with frmProgress do
    begin
      ShowModal;
    end;
  end;
end;

commenting out the progress parts and removing the try, finally.. statement makes the files save correctly.

i need to look further into why the timer is causing the files to save and open correctly, and whether or not i even need a progres form for this operation.

thanks for the info anyway, i could do with cleaning some code up.

just to let you know, im making a code library where i can store all my snippets and stuff. i cant see any free ones available that will store my code, so im attempting to write my own.
 
try..finally without a try..except in between can lead to problems. It will 'eat' any errors and you'll never see them.

I wonder if D2010 has try..except..finally?
 
DjangMan,

I'm, sorry but it is the other way around....

try except will eat errors.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
yes,

except on exception do
Exit;
end;

will trap the errors, i think the timer i was running was not processing the CloseFile correctly, even with Application.ProcessMessages;

i have since removed the use of the timer, progress form is only shown when loading my db file.

Thanks anyway everyone
 
Thanks Daddy - need more sleep - JVCL wouldn't install last night...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top