acesso violetion - Thread
{ 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;
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
Curtidas 0
Respostas
Woinch
16/02/2009
Já experimentou colocar o Execute todo dentro de uma procedure e utilizar no Execute o comando: Synchronize(NomeDaProcedure)?
Espero ter ajudado.
Espero ter ajudado.
GOSTEI 0
Walter Faria
16/02/2009
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.
Obrigado.
GOSTEI 0
Woinch
16/02/2009
Experimente assim:
Talvez o problema não seja na Thread, mas sim no Form. Se não funcionar precisa de uma análise mais crítica.
{ 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.
GOSTEI 0
Ivanh
16/02/2009
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.
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;
GOSTEI 0
Ivanh
16/02/2009
No execute vc deve usar o TForm1(FForm) ao inves de Form1.
Pode nao resolver seu problema, mas vai evitar alguns problemas futuros.
Pode nao resolver seu problema, mas vai evitar alguns problemas futuros.
GOSTEI 0