|
Yes - would have thought a thread approach would be
the best option.
A another, simple, approach (should be quick and
easy to try out - see if it is workable)
A TMoving containing a TTimer and the TBitmap
that is on the Screen.
Self destruction - I am not sure about... I haven't
looked into this area in a long time.
But if the TMoving contains the Timer
you shouldn't the have problems Moving destroyed objects.
You may still find that the backlog of Moving the
Bitmaps too great.
I would personally go for a Thread Object
containing all the "parts" of a TMoving (i.e. the base object for the
TMoving)
I would also have the thread object contain the
Bitmap and a TTimer.
I believe you will have to do some sort of
"synchronisation" (I can't think of the proper word for it) to get the main
VCL Thread to draw each Bitmap.
HTH
Regards Paul McKenzie Analyst Programmer SMSS Ltd.
----- Original Message -----
Sent: Wednesday, January 14, 2004 7:44
AM
Subject: [DUG] Should I use threads? I
need suggestions how to solve thisproblem!
I have a problem that I'm not sure how to solve.
Perhaps I should do with threads, but that is something I've never done
before, and since I don't really have the time to learn something new I would
appreciate other solutions.
I have a class called TMoving, which is
represented (visually) by a TBitmap. TMoving has several properties, but the
most important are x,y and angle.
So when I press a key, I want a new TMoving to be
created. A new TBitmap should also appear on the form (the bitmap and the
TMoving object are two different objects!) OK, now I would like that in every
100 mseconds the object to move according to the angle. The new x and y are
calculated by the CalcNewXY procedure. So I get the new X and Y, and I move
the image there. When the image is out of the screen (width<x<0 and
height<y<0) it should destroy itself.
So the problem is this: I need to have a variable
number of TMoving objects. Each object should "move itself" without my
intervention, in 2 ms, which perhaps involves a TTimer, although I could just
use TickCount if it can be done.
Does this have to be done with threading or not?
One of my solutions was to create a procedure that activates itself WHEN 2 ms
have passed. Then it moves the object and Bitmap to the new location and calls
itself yet again, with the parameter that is NOW+2 ms. The trouble is the old
procedure (that has called itself) will take up memory until the new procedure
has expired, and since there can be many many calls to that procedure it could
cause a memory error. I would want the procedure to call itself, but also
release "the used" itself at the same time.
The other solution of mine was to create a
central list of TMoving objects and a TTimer which moves each object in every
2 ms, but it has failed for some reason, I think the object destroys itself
before the Timer realises so it calls the destroyed object again. Again, this
is a bad solution because if the number of TMoving increases the Timer will be
unable to move each object at the same time. That is why it would be nice to
have an "internal timer" (solution #1).
Any ideas?
Gajo
_______________________________________________ Delphi mailing
list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
|