type
EInvalidHandleException =
class(
Exception );
procedure CheckInvalidHandle( AHandle : THandle;
const AText :
string );
begin
if AHandle = INVALID_HANDLE
then
raise EInvalidHandleException.Create( AText );
end;
procedure foo;
var
LHandle1, LHandle2, LHandle3, LHandle4 : THandle;
begin
LHandle1 := GetHandleFromElseWhere;
CheckInvalidHandle( LHandle1, '
from ElseWhere' );
LHandle2 := GetHandleFromElseWhere( LHandle1 );
CheckInvalidHandle( LHandle2, '
from ElseWhere' );
LHandle3 := GetHandleFromElseWhere( LHandle2 );
CheckInvalidHandle( LHandle3, '
from ElseWhere' );
LHandle4 := GetHandleFromElseWhere( LHandle3 );
CheckInvalidHandle( LHandle4, '
from ElseWhere' );
DoSomethingWithHandles( LHandle1, LHandle2, LHandle3, LHandle4 );
end;