Lazarus
Free Pascal => Beginners => Topic started by: Alexantr on December 10, 2016, 07:02:55 pm
-
Hi!
I've looped to capture values in a file and produce tones according to those values. I need to change the color of a Shape when a certain value appears while this loop is executed. But it only allows you to modify at the end of the loop. How do I solve this?
Example:
If Freq = 750 then Shape1.Brush.Color: = $0000ff else Shape1.Brush.Color: = $000000;
-
Hi
Have you tryed to insert "Application.ProcessMessage;" in your loop ?
-
...But it only allows you to modify at the end of the loop.
Really ???
If that is the case, then you can try "BREAK", do what you need to do and start the loop again...
Would be my first thought...
-
40/5000
Deeply grateful for the help given.
Sorry for the absence. Larger forces.
I tried Break, but I was not very happy. Maybe he acted inappropriately. I'll try one more time.
I will put a practical, simplified example below. A counter loop with a delay of 1s, which alternates the color of a shape at each pass. If it works correctly, the problem will have a similar solution.
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
For i:=0 to 10 do
begin
if shape1.brush.color = clwhite then
shape1.brush.color := clblack else
shape1.brush.color := clwhite;
delay(1000);
end;
end;
-
Hi
Have you tryed to insert "Application.ProcessMessage;" in your loop ?
I really do not know how that could help. Never did it. I'll read about it and see if it works. Thanks for the tip. I'll post a feedback soon.
-
Using Delay() inside a for...do loop in a GUI program is not good.
Drop a TTimer on your form, sets its interval appropriately and use its OnTimer event to change the brush color of your shapes at regular intervals.
-
Hi
Have you tryed to insert "Application.ProcessMessage;" in your loop ?
I really do not know how that could help. Never did it. I'll read about it and see if it works. Thanks for the tip. I'll post a feedback soon.
Fantastic! Solved, Lulu!
I added that line inside the loop and it worked!
Very grateful to you! :D
-
Using Delay() inside a for...do loop in a GUI program is not good.
Drop a TTimer on your form, sets its interval appropriately and use its OnTimer event to change the brush color of your shapes at regular intervals.
Although I used an illustrative example, I actually put "delay" in the loop code to cause a gap between two dynamically generated sounds. I did not know he was inaccurate. I thought it would be more responsive in response time than TTimer because I need good precision in milliseconds. I'll read and test with TTimer. Thanks for the tip.
-
I'm happy ! :D It's the first time I help someone 8-)