Skip to content

Borland Deleters

DryPerspective edited this page Oct 4, 2023 · 1 revision

This library also includes a small selection of deleter structs for Borland types, intended as a ready-made solution to use alongside smart pointers. They are found in borland/borland_deleters.h and exist in namespace dp. They are simple, stateless structs which overload operator() to perform simple tasks before deleting their variable.

List of Features

query_deleter A deleter for TADOQuery objects which will close any active query and reset all parameters before deleting the object
connection_deleter A deleter for TADOConnection objects which will roll back and close any active transaction before deleting the object

Sample code

#include "cpp98/scoped_ptr.h"
#include "borland/borland_deleters.h"

void some_function(){
    dp::scoped_ptr<TADOConnection, dp::connection_deleter> conn(new TADOConnection(NULL));
    //...
    conn->BeginTrans();
    //Perform some part of the transaction
    //...
    
    if(some_query->is_not_right()) throw Exception("Data not found"); //Deleter means the transaction is automatically rolled back 
    else conn->CommitTrans();
} //Connection object automatically deleted. No active transaction => nothing rolled back

Clone this wiki locally