Thema: Delphi Copy Text

Einzelnen Beitrag anzeigen

t.roller
(Gast)

n/a Beiträge
 
#3

AW: Copy Text

  Alt 28. Feb 2017, 22:54
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;

Geändert von t.roller ( 1. Mär 2017 um 06:38 Uhr)
  Mit Zitat antworten Zitat