delphi - How to exchange TList items during a for-loop -
i have tlist which' items continuously processed many for-loops. need exchange items in list in order rearrange order of visual representation of list (in stringgrid).
how exchange these items?
my preliminary thoughts are:
- during for-loop think items should not exchanged.
- if exchange in timers'
ontimerevent, having set timers' interval short interval (e.g. 1 millisecond), think for-loop have intermission of 1 millisecond.
will work? or there better alternatives?
as long ensure count of items in tlist not change, exchanging items fine during for-loop. note that, depending on index of items exchanged, of items may not processed or may processed twice.
if exchange operation not called within for-loop, started for-loop run until done. cannot expect "break in" timer, because timer's message not processed until for-loop , surrounding code done.
so, solution problem be:
- exchange items within for-loop,
- use threading solution able 2 different things simultaniously on 1 list (this may need learning threads),
- wait until for-loop done, , exchange then,
- split for-loop in multiple slices reduce time needed, or
- use timer start multiple for-loops in order give program breathing time in between.
Comments
Post a Comment