?
Solved

Try Until Error Then Stop Function

Posted on 2007-10-14
6
Medium Priority
?
186 Views
Last Modified: 2010-04-05
Hi Experts

I need some code to for this

function copyfiles(files:string):string;
var
  i:Integer;
begin
for i:=0 to 100 do begin
  CopyFile(pchar(files+'.db'), pchar(files+inttostr(i)+'.db'), False);
end;
end


how can I do it so that when there is a error it will stop the process.

0
Comment
Question by:eNarc
5 Comments
 
LVL 19

Expert Comment

by:Limbeck
ID: 20073826
hi, somtehing like this

function copyfiles(files:string):string;
var
  i:Integer;
begin
try
for i:=0 to 100 do begin
  CopyFile(pchar(files+'.db'), pchar(files+inttostr(i)+'.db'), False);
except
//errorhandling
end;
end;
end
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20073883
This might do the trick:

function copyfiles(files:string):string;
var
  i:Integer;
try
for i:=0 to 100 do begin
  CopyFile(pchar(files+'.db'), pchar(files+inttostr(i)+'.db'), False);
except
abort;
end;
end;
end
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 2000 total points
ID: 20073894
CoyFile actually returns a boolean if it succeeded or not:

function copyfiles(files:string):string;
var
  i:Integer;
begin
for i:=0 to 100 do begin
  if not CopyFile(pchar(files+'.db'), pchar(files+inttostr(i)+'.db'), False) then
    break;
end;
end
0
 
LVL 1

Expert Comment

by:RuntimeError007
ID: 20081468
Or a Message on error then abort:

function copyfiles(files:string):string;
var
  i:Integer;
begin
try
   for i:=0 to 100 do begin
     CopyFile(pchar(files+'.db'), pchar(files+inttostr(i)+'.db'), False);
   end;
except
  on E : Exception do
     begin
      ShowMessage(E.ClassName+' error raised, with message : '+E.Message);
      abort;
     end;
  end;
end;

0
 
LVL 1

Expert Comment

by:Computer101
ID: 21216681
Forced accept.

Computer101
EE Admin
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

862 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