Tuesday, November 03, 2026

On (De)Activate

In the OP's ERP management system: there can be several forms displayed at the same time and all have the same background colour, so if one is not paying attention, it can be difficult to know which is the active form.

In an application that has a main form and several son forms, all of which are modal, then this active form problem does not exist as only one modal form can be displayed at a given time (that's not 100% true: a modal form can cause another modal form to be displayed on top of the first, but this is unusual and possibly confusing). But in an application where there are several non-modal forms (they don't have to be MDIChild forms), a few can appear on the screen simultaneously, of which only one is the active form.

How to solve this? I thought at first of using screen.activeform but this isn't a particularly good idea. Whilst it might allow discovering which form is active, it won't restore the previous active form when the active form loses focus (not necessarily closed).

It turns out that there is a pair of methods than solve this problem - OnActivate and OnDeactivate. I have come across OnActivate in the context of modal forms although for them, this method doesn't add anything to OnCreate or OnShow. But with non-modal forms, this is a good mechanism. As CoPilot tells me, 

OnActivate is raised not only when a form is first shown, but whenever the user switches to it:

  1. by clicking it
  2. via Window menu
  3. after another form closes
  4. after minimizing/restoring another child

Of course, OnDeactivate is invoked by a form when it is about to lose focus. Using this pair of methods, the necessary code to change the background colour of not-active forms becomes very simple.

Procedure TStickyForm.HandleActivate (Sender: TObject); begin inherited; color:= clMoneyGreen; end; Procedure TStickyForm.HandleDeActivate (Sender: TObject); begin inherited; color:= $008FBC8F; // clDarkSeaGreen ?? end;

TStickyForm is the parent form from which most of the non-modal forms inherit, so all of them automatically get this behaviour. There are one or two non-modal forms that don't inherit from TStickyForm for reasons that I don't recall, but it's easy to add these two methods to their code.

In a sense, this is similar to this code1 for modal forms, although that solution simply causes the screen's background to become grey whilst displaying the modal dialog form in front of the background.

Internal links
[1] 1827



This day in blog history:

Blog #Date TitleTags
42403/11/2011The thousand-dollar penalty for reusing passwordsComputers
108703/11/2017More thinking on the page (DBA)DBA
118203/11/2018Protecting cells in Excel filesProgramming, Delphi, Excel, Office automation
135403/11/2020Overcoming the 'leading zero' leads to other problems with ExcelProgramming, Excel, Office automation
154703/11/2022Have I found the solution to a cooking problem?Cooking, Meta-blogging
168403/11/2023YouTuber's first listens to Van der Graaf GeneratorVan der Graaf Generator

Sunday, November 01, 2026

Ajovy (3)

It's the first of the month and so it's time for my third Ajovy injection. As opposed to last month1, this went without difficulty, although I should note that quite a bit of force is required to remove the needle guard. This is what went wrong last time.

As to the efficacy of the injection, I can't really be sure. I've been having sleep problems for the past six weeks (difficulty in falling asleep, waking up several times during the night and difficulty returning to sleep) so I've been prescribed Brotizolam for occasional use. Although I cut each tablet into two or four, I have been using this quite frequently in the past few weeks. This makes me feel funny the next day (I have difficulty in describing the feeling, something like 'a fuzzy head' but my GP understood) and may have caused more than a few 'pressure' headaches. These feel like someone pressing on part of my head as opposed to a classic headache that hurts. It could be that rizatriptan handled these headaches, in which case they were migraines, but they could also have dissipated on their own. They certainly weren't 'normal' migraines, although these seem to come in several variations.

Regarding the sleep problems: apart from anything else, they may be due to my stopping certain medications. I have been taking Amitriptyline for years in a small prophylactic dose, and this medication can cause sleepiness - in my case, an advantage. I asked the neurologist whether I should continue taking this medication once I start with Ajovy and he said that I can stop after a month (ie at the beginning of October). The cessation could cause two separate problems: withdrawal symptoms (nothing like opiate withdrawal!!!!) and the fact that the medication's effect is simply missing.

I also stopped taking theanine once I retired as I expected that my levels of anxiety would be greatly reduced. This supplement also helps to calm the body down and improves sleep - so again, cessation might be seen as an own goal.

I had an appointment with the GP today to discuss my sleep problems, and apart from anything else, she recommended that I resume taking both of these medications as they will help with the sleep. In a few days, I'll do my biannual blood tests and next week I'll have another appointment to review the test results and any changes in the sleep. She said that there's a better medication than amitriptyline for what I need (she didn't divulge its name) and presumably next week she'll prescribe this for me.

With regard to the CPAP machine, I increased the pressure slightly as my weight has increased. It is time for a new mask that should also reduce the number of apneic events.


Internal links
[1] 2150

This day in blog history:

Blog #Date TitleTags
77201/11/2014Undoing textual changesProgramming
154501/11/2022Big cloudWeather
203001/11/2025More apneic eventsCPAP