We help IT Professionals succeed at work.

Try Until Error Then Stop Function

eNarc
eNarc asked
on
202 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.

Comment
Watch Question

Commented:
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

Commented:
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
Sr. Software Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
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;

Forced accept.

Computer101
EE Admin
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.