Recent

Author Topic: Commands into loop  (Read 4359 times)

Alexantr

  • Newbie
  • Posts: 5
Commands into loop
« 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;

Lulu

  • Full Member
  • ***
  • Posts: 230
Re: Commands into loop
« Reply #1 on: December 10, 2016, 07:49:43 pm »
Hi
Have you tryed to insert "Application.ProcessMessage;" in your loop ?
wishing you a nice life

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Commands into loop
« Reply #2 on: December 10, 2016, 09:44:51 pm »
Quote
...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...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Alexantr

  • Newbie
  • Posts: 5
Re: Commands into loop
« Reply #3 on: December 22, 2016, 07:13:33 pm »
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;

Alexantr

  • Newbie
  • Posts: 5
Re: Commands into loop
« Reply #4 on: December 22, 2016, 07:19:52 pm »
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.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Commands into loop
« Reply #5 on: December 22, 2016, 07:36:26 pm »
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.

Alexantr

  • Newbie
  • Posts: 5
Re: Commands into loop
« Reply #6 on: December 22, 2016, 07:41:47 pm »
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

Alexantr

  • Newbie
  • Posts: 5
Re: Commands into loop
« Reply #7 on: December 22, 2016, 09:09:52 pm »
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.

Lulu

  • Full Member
  • ***
  • Posts: 230
Re: Commands into loop
« Reply #8 on: December 22, 2016, 09:42:47 pm »
I'm happy ! :D It's the first time I help someone  8-)
wishing you a nice life

 

TinyPortal © 2005-2018