Ver Mensaje Individual
  #5  
Antiguo 20-06-2015
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola Lepe.

Es correcta tu observación. Usar el método Synchronize le da mas estabilidad al código, así que por más que haya sido solo un ensayo, se lo agregamos al amigo pokexperto1.
Código Delphi [-]
type
  TSpell = class(TThread)
  private
    FText    : string;
    FCount   : Integer;
    FTime    : DWORD;
    FInterval: Cardinal;
    Memo     : TMemo;
  public
    constructor Create; reintroduce; overload;
    procedure Execute; override;
    procedure WriteChar;
    property Interval: Cardinal read FInterval write FInterval;
    property Text: string read FText write FText;
  end;

constructor TSpell.Create;
begin
  inherited Create(True);
  FTime  := GetTickCount;
  FCount := 0;
end;

procedure TSpell.WriteChar;
begin
  Memo.Text := Memo.Text + FText[FCount];
end;

procedure TSpell.Execute;
begin
  inherited;
  while FCount <= Length(FText) do
  begin
    if GetTickCount - FTime > Interval then
    begin
      Inc(FCount);
      Synchronize(WriteChar);
      Application.ProcessMessages;
      FTime := GetTickCount;
    end;
  end;
end;

procedure SpellText(const Texto: string; Memo: TMemo; const Interv: Integer);
var
  spell: TSpell;
begin
  spell := TSpell.Create(True);
  try
    spell.Memo     := Memo;
    spell.Text     := Texto;
    spell.Interval := Interv;
    spell.Execute;
  finally
    spell.Free;
  end;
end;

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita