This makes me wonder why have erase background at all? If the appearance will be refreshed anyway why is it the default behavior to erase it first?
The answer to that is very simple. Let's use an example to make it obvious.
Imagine you have a window with an image (smaller than the window) you want to keep centered in the window. The crucial fact in that statement is "centered in the window", this means that every time the window is resized, the image has to move to be at the new center.
Now imagine that when the window size is changed, the background isn't erased. What will happen is that part of image where the previous center used to be will remain there (because the background isn't erased) and part of it will be overpainted with the same image in the new window center.
To avoid having part of the image left in the window when it is resized, the background is erased. For an instant, the window has nothing in it (just the background color, whatever it may be) then, after the erase, the image is painted in the new center. That two-step process, erase which leaves the background clear, followed by the painting of the image is the source of the flicker. IOW, there would be no flicker if the background had not been erased but then, if the background is not erased and no "special measures" are taken then left overs of the previous image will be visible (which is undesirable.)
What can the special measures be ?... if you paint on a bitmap instead of the screen then you can lie to Windows (or whatever window manager you're using) and tell it that the background has been erased even though it hasn't. The reason that will work is because, on the bitmap you're using as a window replacement, you'll first clear the bitmap then paint on it but, since the bitmap isn't visible until you paint it on the window, the clearing of the bitmap is not visible. This process is what is commonly called "double buffering".
There are other ways to eliminate flicker without using "double buffering" (double buffering consumes memory for the bitmap it paints on which can potentially be large.) One of those ways is to clear only those areas that need to be clear in the final screen. To that effect there are plenty of techniques that can be used. You can find some of them explained here:
https://forum.lazarus.freepascal.org/index.php/topic,53791.0.htmlalong with example code you can step through using a debugger.
Now you should know why I inquired about the trackbar moving when the window is resized. if the trackbar doesn't move nor changes size then it is trivial to eliminate the flicker. Study the examples if the reason why is still unclear to you at this time.
HTH.