Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Error con multihilos (https://www.clubdelphi.com/foros/showthread.php?t=89751)

Ramsay 31-01-2016 01:20:41

Error con multihilos
 
Hola , tengo un problema haciendo multireading , estoy tratando de crear cinco que muestren simplemente un mensaje , el problema es que siempre muestra el error "Exception class EAccessViolation with message 'Access violation at address" al usarlo

Código Delphi [-]
type
  TMyThread = class(TThread)
  protected
    procedure Execute; override;
  public
    text: string;
    property ReturnValue;
  end;

procedure TMyThread.Execute;
begin
  if Terminated then
    Exit;
  MessageDlgPos(text, mtInformation, [mbOk], 0, 100, 200);
end;

procedure TForm1.btnTestClick(Sender: TObject);
var
  LThread: TMyThread;
  i: Integer;
begin

  For i := 1 to 5 do
  begin
    LThread := TMyThread(Sender);
    try
      LThread.text := 'hi';
      LThread.FreeOnTerminate := True;
    except
      LThread.Free;
      raise;
    end;
    LThread.Resume;
  end;
end;

¿ Cual es el problema ?

AgustinOrtu 31-01-2016 16:18:34

Nunca creaste el thread, estas realizando un cast forzado sobre Sender, que no es un TThread, es un TButton

Mosis2k2 01-02-2016 20:02:21

Multihilos
 
Preuba con esto y nos comentas:

Código Delphi [-]
procedure TForm1.btnTestClick(Sender: TObject);
var
  LThread: TMyThread;
  i: Integer;
begin

  For i := 1 to 5 do
  begin
    LThread := TMyThread.Create;
    try
      LThread.text := 'hi';
      LThread.FreeOnTerminate := True;
    except
      LThread.Free;
      raise;
    end;
    LThread.Resume;
  end;
end;


La franja horaria es GMT +2. Ahora son las 03:30:07.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi