Link to home
Start Free TrialLog in
Avatar of eNarc
eNarcFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Try Until Error Then Stop Function

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.

Avatar of Limbeck
Limbeck

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
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
ASKER CERTIFIED SOLUTION
Avatar of MerijnB
MerijnB
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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