The Using statement is used to get a resource, execute a embedded statement block and then release the resource.
using-statement:
Using identifier := expression Do block End Using
The structure or class implementing the System.IDisposable interface, is named a resource. This interface has a single parameterless method named Dispose. A code using the resource can call the Dispose method to indicate that this resource is no longer required.
The Using structure is expanded as follows:
Begin
identifier := expression;
Try
block
Finally
If identifier <> Null Then
(identifier as IDisposable).Dispose;
End If
End Try
End
Private Sub TestUsing();
Var
a: Font;
Begin
Using a := New Font("Arial", 10) Do
//Using obtained font
End Using;
End Sub;
See also: