I can not imagine how to solve this problem: In the label, when you press the button, a range is generated (in ascending order) which consists of the "-" sign.

That is the place label label:

- -- --- ---- ----- ------ ------- -------- 

As soon as it reaches the end - the cycle repeats again.

Closed due to the fact that the essence of the issue is not clear to the participants of Kromster , 0xdb , nick_n_a , Edward , Viktor Tomilov 12 Jun '18 at 16:16 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Try again to formulate the problem. In Label, a character must be added for each button click - until the line length exceeds a certain length. And after exceeding the line starts to fill again. So? - Anton Shchyrov
  • @Anton Shchyrov, A little bit wrong. In Label, when you click a button, the lines from the “-” character will be generated, in ascending order. From 1 to 8 characters (As shown above.) And the cycle should be constantly repeated. That is, first the sign "-" then "-" and so on ... - Tatiana
  • one
    How is this different from what I wrote? Or do you want the Label change to go on continuously, without pressing a button? - Anton Shchyrov
  • @Anton Shchyrov, Yes, you need it continuously. - Tatiana
  • Timer, timer: = Label.Text + '-', check the length and so on. - nick_n_a

1 answer 1

 TMyThread = class(TThread) strict private FLabel: TLabel; FStopEvent: THandle; strict private procedure UpdateLabel; protected procedure Execute; public constructor Create(ALabel: TLabel); destructor Destroy; override; end; constructor Create(ALabel: TLabel); begin inherited Create(False); FLabel := ALabel; FStopEvent := CreateEvent(nil, False, False, nil); end; destructor TMyThread.Destroy; begin SetEvent(FStopEvent); inherited Destroy; CloseHandle(FStopEvent); end; procedure TMyThread.UpdateLabel; begin if Length(FLabel.Caption) > 10 then FLabel.Caption := '-' else FLabel.Caption := FLabel.Caption + '-'; end; procedure TMyThread.Execute; var LRes: Cardinal; begin repeat LRes := WaitForSingleObject(FStopEvent, 1000); case LRes of WAIT_TIMEOUT: Synchronize(UpdateLabel); WAIT_FAILED: RaiseLastOSError; end; until LRes = WAIT_OBJECT_0; end; procedure TForm1.Button1Click(Sender: TObject); begin if FThread = nil then FThread := TMyThread.Create(Label1) else FreeAndNil(FThread); end; 


Update

Something in the evening I stopped thinking. There is a much simpler solution.

We throw a timer on the form, specify the Interval property, how often it should work, in the OnTimer handler OnTimer write

 procedure TForm1.Timer1Timer(Sender: TObject); begin if Length(Label1.Caption) > 10 then Label1.Caption := '-' else Label1.Caption := Label1.Caption + '-'; end; 

In the OnClick handler, OnClick write buttons

 procedure TForm1.Button1Click(Sender: TObject); begin Timer1.Enabled := not Timer1.Enabled; end;