| View previous topic :: View next topic |
| Author |
Message |
child Guest
|
Posted: Tue Mar 02, 2004 2:28 pm Post subject: [INDY 10]What cause this so simple demo error(in IDE environ |
|
|
//////////////////
// CODE:
/////////////////
procedure TForm1.Button1Click(Sender: TObject);
begin
IdTCPServer1.Active := True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
IdTCPServer1.Active := False;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
IdTCPClient1.Connect;
end;
////////////
// EVENT
////////////
(in IDE environment)
Step 1: Button1.Click;
Step 2: Button3.Click;
Step 3: Button2.Click;
Then a violation memory error occur.
I want to know what cause this ???
|
|
| Back to top |
|
 |
child Guest
|
Posted: Tue Mar 02, 2004 3:03 pm Post subject: Solution, btw why not add these code to idtcpserver.setactiv |
|
|
| Quote: | //////////////////
// CODE:
/////////////////
procedure TForm1.Button1Click(Sender: TObject);
begin
IdTCPServer1.Active := True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
IdTCPServer1.Active := False;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
IdTCPClient1.Connect;
end;
////////////
// EVENT
////////////
(in IDE environment)
Step 1: Button1.Click;
Step 2: Button3.Click;
Step 3: Button2.Click;
Then a violation memory error occur.
I want to know what cause this ???
//////////////////////////////solution////////////// |
procedure TForm1.Button2Click(Sender: TObject);
var
List: TList;
i: Integer;
begin
List := IdTCPServer1.Contexts.LockList;
try
for i := 0 to List.Count - 1 do
begin
TIdContext(List.Items[i]).Connection.Disconnect;
end;
finally
IdTCPServer1.Contexts.UnlockList;
end;
IdTCPServer1.Active := False;
end;
|
|
| Back to top |
|
 |
Martin James Guest
|
Posted: Tue Mar 02, 2004 4:07 pm Post subject: Re: Solution, btw why not add these code to idtcpserver.seta |
|
|
Not in Indy 10 as well!
Rgds,
Martin
|
|
| Back to top |
|
 |
Chad Z. Hower aka Kudzu Guest
|
Posted: Tue Mar 02, 2004 6:41 pm Post subject: Re: [INDY 10]What cause this so simple demo error(in IDE env |
|
|
"child" <child (AT) 88oo (DOT) com> wrote in news:404499f4 (AT) newsgroups (DOT) borland.com:
| Quote: | Then a violation memory error occur.
I want to know what cause this ???
|
I fixed this last night actually. You need to get the new dev snapshot (note
that the FTP mirror is 24 hours delayed)
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Is Indy useful to you? Send a postcard please!
http://www.hower.org/kudzu/indypost.html
|
|
| Back to top |
|
 |
child Guest
|
Posted: Thu Mar 04, 2004 1:58 am Post subject: Re: Why old dev snapshot can access VCL ? |
|
|
| Quote: | New dev snapshot fixed ago error, but new error occur:
///////////////// CODE /////////////
procedure TForm1.IdTCPServer1Disconnect(AContext: TIdContext);
begin
Caption := 'disconnected';
// Caption := AContext.Connection.Socket.Binding.PeerIP;
end;
///////////////////////////////////
with old dev snapshot, above event ok, but with new snap, above event
will
cause app hang........or memory error.
Duh.
You are in a thread, you cannot access Caption. Of course it hangs / AVs.
--
Chad Z. Hower (a.k.a. Kudzu)
|
Prev dev snapshot, in OnTCPServer1Disconnect(AContext: TIdContext); event,
can continual access VCL...
New Dev snapshot changed thread methold ?
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Mar 04, 2004 2:16 am Post subject: Re: Why old dev snapshot can access VCL ? |
|
|
"child" <child (AT) 88oo (DOT) com> wrote
| Quote: | Prev dev snapshot, in OnTCPServer1Disconnect(AContext:
TIdContext); event, can continual access VCL...
|
You merely got lucky, nothing more. You were never guaranteed even with the
older version that the event handler would ever be executed in the context
of the main VCL thread. You should have *always* been synching access to
VCL components regardless.
Gambit
|
|
| Back to top |
|
 |
child Guest
|
Posted: Thu Mar 04, 2004 7:18 am Post subject: So, how to use Synchronize methold ? |
|
|
TIdContext have no Synchronize.....
|
|
| Back to top |
|
 |
Chad Z. Hower aka Kudzu Guest
|
Posted: Thu Mar 04, 2004 7:45 am Post subject: Re: So, how to use Synchronize methold ? |
|
|
"child" <child (AT) 88oo (DOT) com> wrote in news:4046d709$1 (AT) newsgroups (DOT) borland.com:
| Quote: | TIdContext have no Synchronize.....
|
See the demos here, Im pretty sure the 9 page still has some sync demos:
www.atozed.com/indy
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Need extra help with an Indy problem?
http://www.atozed.com/indy/experts/
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Mar 04, 2004 8:22 pm Post subject: Re: So, how to use Synchronize methold ? |
|
|
"child" <child (AT) 88oo (DOT) com> wrote
| Quote: | TIdContext have no Synchronize.....
|
Derive a class from TIdSync instead. It has an overloaded constructor which
will create a thread internally for the purposes of having a Synchronize()
method available for use, if no other thread is already available from the
calling code.
Gambit
|
|
| Back to top |
|
 |
|