Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to copy an open text file in delphi

Posted on 2003-02-20
6
Medium Priority
?
378 Views
Last Modified: 2010-04-04
hi

can anyone one advise me on how to copy an open Text file in delphi ?



thanx
0
Comment
Question by:Zaheer
6 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 7988112
You can use TStrings.LoadFromFile or
var F: TextFile;

AssignFile(F,FileName);
Reset(F);
try
while not Eof(F) do
begin
  do here anything You want useing ReadLn(F,...);
end;
finally
CloseFile(F);
end;

ziolko.
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 400 total points
ID: 7988275
wont work ziolko,

first you must change the filemode to readonly
(default is readwrite)

AssignFile(F,FileName);
filemode := 0; //<--- readonly
Reset(F);
try
while not Eof(F) do
begin
 do here anything You want useing ReadLn(F,...);
end;
finally
CloseFile(F);
end;

but i would prefer two two tfilestreams
like

var
  source, dest : TFileStream;
begin
  try
    source := TfileStream.Create('SourceFileName',fmOpenRead);
    try
      dest := TfileStream.Create('DestFileName',fmCreate);
      try
        dest.CopyFrom(source,0);
      finally
        dest.free;
      end;
    finally
      source.free;
    end;
  except
    Showmessage(SomeThing went wrong');
    raise;
  end;
end;

well just from hrad
not tested

meikl ;-)
0
 

Expert Comment

by:RAGAB2000
ID: 7992212
I think kretzschmar in his last solution is right
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Expert Comment

by:mocarts
ID: 7992644
if you don't write corssplatform app you can also use:

  Windows.CopyFile(lpExistingFileName, lpNewFileName: PChar; bFailIfExists: BOOL): BOOL;

copiing is impossible if file is opened without rights to others to read.

wbr, mo.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 7993899
yep kretzschmar you're absolutelly right.
ziolko.
0
 

Expert Comment

by:CleanupPing
ID: 9317155
Zaheer:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Loops Section Overview
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month15 days, 13 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question