Autor Beitrag
emteg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Fr 11.03.05 19:48 
Hallo leute,

ich suche nach einer möglichkeit, einen string zeichen für zeichen in ein label zu schreiben. nach jedem zeichen soll ein paar ms pause gemacht werden, das ganze soll quasi in das label reingeschrieben werden.
Wie mach ich das? Ich hab das jetzt zwar schon hingekriegt, aber extrem umständlich und schlecht (ich schreibe wirklich jeden buchstaben einzeln und zwar hardcoded).
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Fr 11.03.05 19:55 
Hallo,

vielleicht so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure Delay(const MS: Cardinal);
var
  Time: Cardinal;
begin
  Time := GetTickCount + Ms;
  while GetTickCount < Time do
    Application.ProcessMessages;
end;

procedure TypeText(ALabel: TLabel; const Text: String; Pause: Cardinal);
var
  I: Integer;
begin
  for I := 1 to Length(Text) do begin
    ALabel.Caption := ALabel.Caption + Text[I];
    Delay(Pause);
  end;
end;

//Beispiel
TypeText(Label1, 'Wir gehen jetzt nach Hause.', 300);
Gruß Hape!

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
emteg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Fr 11.03.05 20:01 
wie sähe das ganze mit nem timer aus?
EUOCheffe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124



BeitragVerfasst: Fr 11.03.05 20:03 
Sehr hübsch! Man sollte hier aber noch ein Sleep einbauen, sonst steigt der CPU Bedarf unnötig auf 100%.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
while GetTickCount < Time do
begin
  Application.ProcessMessages;  
  Sleep(1);
end;
emteg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Fr 11.03.05 20:10 
vergiss das mit dem timer, ist besser so. danke!
EUOCheffe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124



BeitragVerfasst: Fr 11.03.05 20:25 
Multi-Label-Lösung mit Timer.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
     Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Timer1: TTimer;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  end;

var
  Form1   : TForm1;
  StrList : TStringList;

implementation
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Timer1.Interval:=300;
  Label1.Caption:='';
  Label2.Caption:='';
  Label3.Caption:='';
  StrList.AddObject('Test',Label1);
  StrList.AddObject('TestTest',Label2);
  StrList.AddObject('TestTestTest',Label3);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  Cnt  : Integer;
begin
  for Cnt:=StrList.Count-1 downto 0 do
    with TLabel(StrList.Objects[Cnt]) do
  begin
    Caption:=Caption+Copy(StrList[Cnt],1,1);
    StrList[Cnt]:=Copy(StrList[Cnt],2,99999);
    if StrList[Cnt]='' then StrList.Delete(Cnt);
  end;
end;

initialization
  StrList:=TStringList.Create;
finalization
  StrList.Free;
end.


Bei der GetTickCount Lösung müsste man evtl. noch eine globale Variable einbauen, die bei True die Textschreib-Schleife abbricht, z.B. wenn der Benutzer das Programm schliesst (globale Variable in OnCloseQuery setzen).

user profile iconemteg hat folgendes geschrieben:
vergiss das mit dem timer, ist besser so. danke!


Hehe, zu spät! :)