Board index » cppbuilder » R: How to get access on TMemo Canvas ?
Steve_Aletto
![]() CBuilder Developer |
Steve_Aletto
![]() CBuilder Developer |
R: How to get access on TMemo Canvas ?2003-06-27 08:02:51 PM cppbuilder73 Giuliano < XXXX@XXXXX.COM >wrote in message XXXX@XXXXX.COM ... QuoteOn Fri, 27 Jun 2003 11:16:35 +0200, Hans Galema Why do you need to use std::auto_ptr? Would it be the same with TControlCanvas *C = new TControlCanvas()? What differences are there? What's the best way? TIA, Steve. |
Hans Galema
![]() CBuilder Developer |
2003-06-27 08:27:30 PM
Re:R: How to get access on TMemo Canvas ?
Steve_Aletto wrote:
QuoteWhy do you need to use std::auto_ptr? you have to use delete (exept if the object handles that self). QuoteWhat's the best way? |
Damon Chandler (TeamB)
![]() CBuilder Developer |
2003-06-28 12:13:41 PM
Re:R: How to get access on TMemo Canvas ?
Steve,
The auto_ptr class assures that the TControlCanvas object is destroyed when the variable (C, in this case) goes out of scope. It's important to destroy the TControlCanvas object not only to avoid leaking its associated memory, but also to ensure that device context is released via the ReleaseDC() Win32 function (which the TControlCanvas class effectively calls from within its destructor). Furthermore, with auto_ptr, you don't have to worry about explicitly calling 'delete C' in case an exception is thrown. For example, the following blocks are functionally equivalent... TControlCanvas* C = new TControlCanvas(); try { C->Control = Memo1; // do something with C } catch (...) { delete C; throw; } delete C; or, TControlCanvas* C = new TControlCanvas(); try { C->Control = Memo1; // do something with C } __finally { delete C; } or, std::auto_ptr<TControlCanvas>C(new TControlCanvas()); C->Control = Memo1; // do something with C HTH, -- Damon (TeamB) BCBCAQ - bcbcaq.bytamin-c.com Steve_Aletto wrote: [snip] QuoteWhy do you need to use std::auto_ptr? {smallsort} |