Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   General (http://www.delphipages.com/forum/forumdisplay.php?f=2)
-   -   How Abort works in delphi5 (http://www.delphipages.com/forum/showthread.php?t=218669)

rmt 04-19-2019 07:16 AM

How Abort works in delphi5
 
Dear Expert,

I have two procedures in my delphi5 application as below. Kindly confirm if there goes something wrong while calling Test(1), then will it call Test(2) or Abort from Test(1) itself.

I want something like if there is some problem in Test(1), it should be aborted from then and there itself without processing Test(2).

HTML Code:

Procedure TestCase
begin
Test(1);
Test(2);

end;

Procedure Test(i : integer)
var loopCnt : integer;
vJsonStr : string;
begin
for loopCnt:=1 to 3 do
                begin
                        executeResultS3:=MoveToS3(FilePath+'\SCVF'+'\'+FileName+'.csv',S3BucketPath + bucketFolder);
                        IF (executeResultS3<0) OR (executeResultS3>32) THEN // not failed
                                break
                        ELSE IF loopCnt=3 THEN
                        BEGIN
                                vJsonStr:='{"status":"999","description":"Unable to Move Prediction File to S3"}';
                                RestPost('POST',vJsonStr);
                                Abort;
                        END;
                end;
end;

Thank you so much in advance.

Norrit 04-19-2019 10:24 AM

No, Abort will only exit the current function, there's no Absolutely Abort.
And that's normal, since this would also abort the application run loop.

There are 2 ways
- make it a function and start 2 if 1 returns true
- throw an exception (since it shouldn't proceed this is valid in my oppinion) and in your TestCase just add try..except around the calls to test

rmt 04-19-2019 10:49 AM

Dear Norrit,

I will go with second option with Try Exception block. Thank you so much for the suggestion.

Regards


All times are GMT. The time now is 12:08 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.