Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Sonstiges (https://www.delphipraxis.net/45-library-sonstiges/)
-   -   Delphi Text "Buchstabe für Buchstabe" darstellen lassen (https://www.delphipraxis.net/39256-text-buchstabe-fuer-buchstabe-darstellen-lassen.html)

flomei 30. Jan 2005 23:17


Text "Buchstabe für Buchstabe" darstellen lassen
 
Hallo!
Hier eine kleine Sammlung von Codes mit deren Hilfe man die Buchstaben eines Textes z.B. in einem Label einzeln nacheinander erscheinen lassen kann:

Nummer 1 von Matze
Delphi-Quellcode:
var
  Form1: TForm1;
  Wort: string = 'Hallo, das ist ein Demo-Text';
  Loop: integer;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Loop := 0;
  Label1.Caption := '';
  Timer1.Interval := 250;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if Loop = Length(Wort) then
  begin
    Loop := 0;
    Label1.Caption := '';
  end;

  inc(Loop);
  Label1.Caption := Label1.Caption + Wort[Loop];
end;
Nummer 2 von Aenogym
Delphi-Quellcode:
var i: integer;

procedure TForm1.Timer1Timer(Sender: TObject);
const
  theText = 'Das ist ein Test';
begin
  i := i + 1;
  label1.Caption := label1.caption + theText[i];
end;
Nummer 3 von Christian Reber
Delphi-Quellcode:
procedure Wait(Time: Word);
  var Start: Cardinal;
begin
  Start := GetTickCount;
  while GetTickCount-Start <= time do begin
    Application.ProcessMessages;
    Sleep(0);
  end;
end;

procedure TForm1.ShowText(Text: String);
  var i : Integer;
begin
  Label1.Caption := '';
  for i := 1 to Length(Text) do begin
    Label1.Caption := Label1.Caption + Text[i];
    Wait(500);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowText('Hallo');
end;
HTH!

MfG Florian :hi:

[edit] Hier eine Anmerkung von dasdaniel:
Zu 2.:
Delphi-Quellcode:
  var i: integer;
procedure TForm1.Timer1Timer(Sender: TObject);
const
  theText = 'Das ist ein Test';
begin
  i := i + 1;
  label1.Caption := label1.caption + theText[i];
end;
Wo wird überprüft wann i grösser Länge Text ist !?
Wann hält der Timer an !?



Am meisten sagt mir Variante 3 zu..
Zu 3.: Wie wäre es mit..
Delphi-Quellcode:
procedure ShowText(Text: String, TheLabel:TLabel);

  procedure Wait(ms:Integer);
  begin
    ms := GetTickCount + ms;
    While ms > GetTickCount do
      Application.ProcessMessages;
  end;

  var i : Integer;
begin
  TheLabel.Caption := '';
  for i := 1 to Length(Text) do begin
    TheLabel.Caption := TheLabel.Caption + Text[i];
    Wait(500);
  end;
end;
code ist frei schnautze getippt, nicht debuggt.[/quote]
Bitte berücksichtigt das bei der Nutzung der Codeschnipsel... :)
[/edit]


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:11 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