Fórum acesso violetion - Thread #368483

16/02/2009

0

{ TClientThread }

constructor TClientThread.Create(CreateSuspended: Boolean);
begin
//inherited Create(CreateSuspended);
inherited Create(true);

Self.Priority := tpIdle;
Self.FreeOnTerminate:= true;
end;

procedure TClientThread.Execute;
begin
// inherited;
[b:12b1b92828]with Form1 do //aqui da erro lembrando q este form1 qdo a propriedade ( FormStyle ) fica = fsMDIChild da erro, mas seu colocar fsNormal ( funciona normal ) [/b:12b1b92828]

alguem tem ideia de como posso resolver ISTO?


begin
if not IdTCPClient1.Connected then
exit;
repeat
cmd.text:= IdTCPClient1.ReadLn;
if trim(cmd.text) <> ´´ then
begin


if VerificaComando(cmd.text,´msg=´,true) then
Synchronize(ShowReceiveMsg)
else
if VerificaComando(cmd.text,´list_user=´,true) then
Synchronize(ListUsers)
else
if VerificaComando(cmd.text,´nick_existente=´,true) then
Synchronize(NickExistente)
else
if VerificaComando(cmd.text,´server_error=´,true) then
Synchronize(ShowServerError)
else
Synchronize(UnknowCmd);


end;
until not IdTCPClient1.Connected;
end;
{if not Terminated then
Terminate;}
end;


Walter Faria

Walter Faria

Responder

Posts

16/02/2009

Woinch

Já experimentou colocar o Execute todo dentro de uma procedure e utilizar no Execute o comando: Synchronize(NomeDaProcedure)?

Espero ter ajudado.


Responder

Gostei + 0

16/02/2009

Walter Faria

Boa noite, entao nao entendo muito... como eu poderia fazer ? na propriedade do FORM ( formStyle ) se estiver fsNormal, funciona certo, se eu colocar como fsMDIChild da este erro de Violetion .



Obrigado.


Responder

Gostei + 0

17/02/2009

Woinch

Experimente assim:

{ TClientThread } 

constructor TClientThread.Create(CreateSuspended: Boolean); 
begin 
//inherited Create(CreateSuspended); 
inherited Create(true); 

Self.Priority := tpIdle; 
Self.FreeOnTerminate:= true; 
end; 

procedure TClientThread.Execute;
begin
  Synchronize(Executa);
end;

procedure TClientThread.ExecutaThread;
begin
  //inherited;

  with Form1 do
    begin
    if not IdTCPClient1.Connected then
      Exit;

    repeat
      cmd.text:= IdTCPClient1.ReadLn;
      if trim(cmd.text) <> ´´ then
      begin


        if VerificaComando(cmd.text,´msg=´,true) then
          ShowReceiveMsg
        else if VerificaComando(cmd.text,´list_user=´,true) then
          ListUsers
        else if VerificaComando(cmd.text,´nick_existente=´,true) then
          NickExistente
        else if VerificaComando(cmd.text,´server_error=´,true) then
          ShowServerError
        else
          UnknowCmd;

      end;
    until not IdTCPClient1.Connected;
  end;

  {if not Terminated then
    Terminate;}
end;


Talvez o problema não seja na Thread, mas sim no Form. Se não funcionar precisa de uma análise mais crítica.


Responder

Gostei + 0

18/02/2009

Ivanh

Botando tudo dentro de [b:dd4382ec83]Synchronize[/b:dd4382ec83] ai deixa de ser [b:dd4382ec83]Thread[/b:dd4382ec83], nao faz sentido.

Um teste que pode ser feito eh passar o Form1 como parametro de criacao da Thread.

TClientThread = class(TThread)

private
  FForm : TForm;
end;

constructor TClientThread.Create(CreateSuspended: Boolean, AForm : TForm);
begin
//inherited Create(CreateSuspended);
inherited Create(true);

Self.Priority := tpIdle;
Self.FreeOnTerminate:= true;
Self.FForm  := AForm;
end; 



Responder

Gostei + 0

18/02/2009

Ivanh

No execute vc deve usar o TForm1(FForm) ao inves de Form1.
Pode nao resolver seu problema, mas vai evitar alguns problemas futuros.


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar