Delphi - What does Abort/Break/Exit


Abort
Break
Exit
FormCreate - 1
FormCreate - 1
FormCreate - 1
MyLoop - 1
MyLoop - 1
MyLoop - 1
MyLoop - 2
MyLoop - 2
MyLoop - 2

MyLoop - 3



FormCreate - 2

FormCreate - 2


Abort
Raises a silent exception.
Use Abort to escape from an execution path without reporting an error.
Abort raises a special "silent exception" (EAbort), which operates like any other exception, but does not display an error message to the end user. Abort redirects execution to the end of the last exception block.
Break
Causes the flow of control to exit a for, while, or repeat statement.
The Break procedure causes the flow of control in Delphi code to exit a for, while, or repeat statement and continue at the next statement following the loop statement.
A call to Break must be contained in a for, while, or repeat statement; otherwise, the compiler reports an error.
Note: Break does not violate the flow of control dictated by a try..finally construct. If a break occurs inside the try clause, the finally clause is entered.
Exit
Exits from the current procedure.
In Delphi, the Exit procedure immediately passes control away from the current procedure. If the current procedure is the main program, Exit causes the program to terminate.
Exit causes the calling procedure to continue with the statement after the point at which the procedure was called.
Note: Exit passes control away from the current procedure, not merely the current block. However, Exit does not violate the flow of control dictated by a try..finally construct; if Exit is called inside the try clause, the finally clause is still executed.
Beginning with Delphi 2009, Exit can take a parameter specifying a result. The parameter must be of the same type as the result of the function. For example:
function DoSomething(aInteger: integer): string;
begin
  if aInteger < 0 then
  begin
    Exit('Negative');
  end;
  Result := 'Positive';
end;

Yorumlar

Bu blogdaki popüler yayınlar

Türkçe Upper

$REGION