![]() |
Copy Text
Hello,
Please, I need a copy Edit1 text character by character into Edit2 after a certain time, for example, 250 milliseconds. Edit1.Text = 'this'; after 250 milliseconds Edit2.Text = 't' and after 250 milliseconds Edit2.Text = 'h' and after 250 milliseconds Edit2.Text = 'i' .... Thank you |
AW: Copy Text
This sounds rather trivial. What is your problem? You will need a variable for keeping track of which character (which index) has been copied to the other Edit so you know which one will be next.
What is your plan if text gets added or removed while the "transmission" to Edit 2 is still taking place? |
AW: Copy Text
Delphi-Quellcode:
(If You want) Replace sleep(250) by
procedure TForm1.Button1Click(Sender: TObject);
var I , le : Integer; begin Edit1.Text:= 'this is a text'; Edit2.Text:= ''; le:= Length(Edit1.Text); for I := 1 to le do BEGIN Edit2.Text:= Edit2.Text + copy(Edit1.Text,I,1); sleep(250); Application.ProcessMessages; END; end; // Better: procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); var I , le : Integer; begin If Key = #13 then // Return begin Edit2.Text:= ''; le:= Length(Edit1.Text); for I := 1 to le do BEGIN Edit2.Text:= Edit2.Text + copy(Edit1.Text,I,1); sleep(250); Application.ProcessMessages; END; Key := #0; end; end;
Delphi-Quellcode:
procedure Wait250;
var AlarmTimer : THandle; Time : Large_Integer; start, ende : Cardinal; begin AlarmTimer := CreateWaitableTimer(nil, False, nil); CancelWaitableTimer(AlarmTimer); Time.QuadPart := 25 * (-100000); // 250 msec SetWaitableTimer(AlarmTimer, Time.Quadpart, 0, nil, nil, False); while WaitForSingleObject(AlarmTimer, 50) <> Wait_Object_0 do begin Application.ProcessMessages; end; CloseHandle(AlarmTimer); end; procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); var I , le : Integer; begin If Key = #13 then // Return begin Edit2.Text:= ''; le:= Length(Edit1.Text); for I := 1 to le do BEGIN Edit2.Text:= Edit2.Text + copy(Edit1.Text,I,1); Wait250; //sleep(250); Application.ProcessMessages; END; Key := #0; end; end; |
AW: Copy Text
Hello,
certain time -> use a timer |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:12 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz