Because you left out a lot of important information ("form is behaving strange" can be interpreted in about a zillion ways, with just as many solutions), I'm going to GUESS what your problem is, and attempt giving you a solution. Please provide relevant information if I'm wrong!
About the TTimer:
The TTimer is a simple solution when you need some timing signals but it's not supposed to be very precise. You set up the timer to "fire" at the given Interval, and Windows will send your application WM_TIMER messages with the configured periodicity. The trick here is, there will never be two WM_TIMER messages on your application's queue at the same time.
If you were to make an clock, and used an TTimer to give you a 1 second heart-beat, your clock would be mostly on time when your computer is idle but it will run slow if your computer is busy. If the processes running the clock is busy the clock would run even slower.
About your problem:
You're saying:
If I run only Show\Hide popup form process all is OK, but when I try run other threads at base form,which are marshling to vcl thread (math painting) behaviour of popup form become strange.
Interpretation: I assume the thread math painting
is happening somewhere in the VCL thread, and that's blocking your application's message queue. This is turn is causing your application to skip WM_TIMER messages, causing the behaviour of popup form become strange
.
Possible solutions:
This is obviously tough without actually knowing the problem (again, strange - how?), but I'm going to give you some ideas any way. First of all let me tell you, I don't think you can fix your problem using a better timer. Your problem is GUI related, and the GUI is single-threaded. While you do have some background threads doing some stuff, they need to marshall to vcl thread
- no matter how precise your timer is, it can't stop the main VCL thread from doing the marshall
thing, so the timer will need to wait for the marshall
to finish in order to do what needs to be done.
Taking hint from I need implement smoothly showing\hiding of this popup form
I assume you need an number of steps for your smooth showing\hiding
, and that's what you're using the TTimer for.
If you got code like this:
(warning, this is pseudo-code, I doubt it compiles)
procedure Timer1OnTimer(Sender:TObject);
begin
SomeCounter := SomeCounter + 1;
if SomeCounter > 10 then
HidePopupForm
else
SetPopupFormTransparencyTo((SomeCounter * 255) div 10);
end;
Replace it with something like this:
var HideAtTime:TDateTime;
ShownAtTime:TDateTime;
procedure Timer1OnTimer(Sender:TObject);
var ExpectedVisibleTime:TDateTime;
ElapsedVisibleTime:TDateTime;
begin
if Now > HideAtTime then
HidePopupForm
else
begin
ExpectedVisibleTime := HideAtTime - ShownAtTime;
ElapsedVisibleTime := Now - ShownAtTime;
SetPopupFormTransparencyTo(ElapsedVisibleTime/ExpectedVisibleTime*255);
end;
end;
The general idea with this solution is to compute deadlines, store them in TDateTime
variables, compare with Now
from your TTimer.OnTimer; That way it doesn't matter if the timer events don't arrive at the requested intervals, you'd be mostly on time with everything else. Sure, showing up a form might not be as smooth as desired, but it'll get the job done.