Board index » cppbuilder » How to save a previous f-ion address
Vladimir Stefanovic
![]() CBuilder Developer |
Vladimir Stefanovic
![]() CBuilder Developer |
How to save a previous f-ion address2004-11-30 11:38:31 PM cppbuilder2 Hi, Today is not my day... How can I save a previous f-on address, that I can reasing it later if needed. // Remember last address... Tmp = Application->OnMinimize; // Assign new... Application->OnMinimize = MyMinimize; DoSomething(); // Reasign remembered... Application->OnMinimize = Tmp; How to declare Tmp ? Best regards, Vladimir Stefanovic |
Andrue Cope [TeamB]
![]() CBuilder Developer |
2004-11-30 11:57:28 PM
Re:How to save a previous f-ion address
Vladimir Stefanovic wrote:
Quote// Assign new... { RAII_TmpValue * MyOrgPointer, MyOrgPointerValue; public: TGeneral_RAII_TempValueChange( RAII_TmpValue * OrgPointer, RAII_TmpValue TemporaryValue ) { MyOrgPointer=OrgPointer; MyOrgPointerValue=*MyOrgPointer; *MyOrgPointer=TemporaryValue; } ~TGeneral_RAII_TempValueChange() { *MyOrgPointer=MyOrgPointerValue; } }; And in answer to your question: { // RAII code block TGeneral_RAII_TempValueChange<TNotifyEvent> wibble( &( Application->OnMinimize ), TNotifyEvent( NULL ) ); DoSomething(); } Once you are aware of this class you'd be surprised at just how often it comes in useful. -- Andrue Cope [TeamB] [Bicester, Uk] info.borland.com/newsgroups/guide.html |
Vladimir Stefanovic
![]() CBuilder Developer |
2004-12-01 12:12:20 AM
Re:How to save a previous f-ion address
Thanks,
I have just tested it! Very nice indeed. Every month somebody forces me to use the RAII model ;) Do you have some other useful RAII templates (to share with us)? Best regards, Vladimir Stefanovic Andrue Cope [TeamB] < XXXX@XXXXX.COM >wrote in message QuoteVladimir Stefanovic wrote: {smallsort} |
Andrue Cope [TeamB]
![]() CBuilder Developer |
2004-12-01 12:50:47 AM
Re:How to save a previous f-ion address
Vladimir Stefanovic wrote:
QuoteDo you have some other useful RAII templates { static HourGlassCounter; public: TOGeneral_RAII_HourGlass() { ++HourGlassCounter; Screen->Cursor=crHourGlass; } ~TOGeneral_RAII_HourGlass() { if( HourGlassCounter ) --HourGlassCounter; if( !HourGlassCounter ) Screen->Cursor=crDefault; } }; usage (and it supports recursion): { TOGeneral_RAII_HourGlass hourGlass; ... do something } ///////////////// template<typename TRAIIEnabler>class TGeneral_RAII_Enable { TRAIIEnabler * MyObjectToControl; bool MyInitialValueF; public: TGeneral_RAII_Enable( TRAIIEnabler * ObjectToControl, bool DesiredValueF ) { MyObjectToControl=ObjectToControl; if( MyObjectToControl ) { MyInitialValueF=ObjectToControl->Enabled; MyObjectToControl->Enabled=DesiredValueF; } } virtual ~TGeneral_RAII_Enable() { if( MyObjectToControl ) MyObjectToControl->Enabled=MyInitialValueF; } }; usage: { TGeneral_RAII_Enable<TSpeedButton> speedButton1Disabler( SpeedButton1, false ); } /////////////////// template<typename RAIIBeginEndUpdate>class TGeneral_RAII_BeginEndUpdate { RAIIBeginEndUpdate *MyObjectToControl; public: TGeneral_RAII_BeginEndUpdate( RAIIBeginEndUpdate *ObjectToControl ) { ObjectToControl->BeginUpdate(); MyObjectToControl=ObjectToControl; } virtual ~TGeneral_RAII_BeginEndUpdate() { MyObjectToControl->EndUpdate(); } }; usage: { TGeneral_RAII_BeginEndUpdate<TListItems> listItems( lvwEntries->Items ); lvwEntries->Items->Clear(); } -- Andrue Cope [TeamB] [Bicester, Uk] info.borland.com/newsgroups/guide.html |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-12-01 03:17:47 AM
Re:How to save a previous f-ion address
"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
Quote// Remember last address... QuoteHow to declare Tmp ? TNotifyEvent Tmp = Application->OnMinimize; Gambit |
Vladimir Stefanovic
![]() CBuilder Developer |
2004-12-01 03:56:41 AM
Re:How to save a previous f-ion address
Thanks for the code.
Best regards, Vladimir Stefanovic Andrue Cope [TeamB] < XXXX@XXXXX.COM >wrote in message QuoteVladimir Stefanovic wrote: |
Vladimir Stefanovic
![]() CBuilder Developer |
2004-12-01 03:58:17 AM
Re:How to save a previous f-ion addressQuoteIf you read the documentation, you will see that Vladimir Stefanovic |