Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   Delphi Copy Text (https://www.delphipraxis.net/191893-copy-text.html)

danten 28. Feb 2017 20:09

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

Der schöne Günther 28. Feb 2017 20:30

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?

t.roller 28. Feb 2017 21:54

AW: Copy Text
 
Delphi-Quellcode:
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;
(If You want) Replace sleep(250) by
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;

hoika 1. Mär 2017 05:02

AW: Copy Text
 
Hello,
certain time -> use a timer


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:16 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz