BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Indy 10 Synchronise problem.

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
chuayongquan@hotmail.com
Guest





PostPosted: Sun Feb 06, 2005 5:30 am    Post subject: Indy 10 Synchronise problem. Reply with quote



How to I use Synchronise method in IdTCPServer??? It is (AContext:
TIdContext) instead of TIdThread. I have tried using this code:

TSyncClass = class(TIdSync)
protected
FData : string;
protected
procedure DoSynchronize; override;
public
procedure Create(AData: String); reintroduce;
class procedure Update(AData: String);
end;

procedure TSyncClass.Create(AData: String);
begin
inherited Create;
FData := AData;
end;

procedure TSyncClass.DoSynchronize;
begin
Form1.ListBox1.ItemIndex := Form1.ListBox1.Items.Add(FData);
end;

class procedure TSyncClass.Update(AData: String);
begin
with Create(AData) do
try
Synchronize;
finally
Free;
end;
end;

procedure TForm1.IdTCPServer1Connect(AContext: TIdContext);
begin
TSyncClass.Update(Format('Le client %s se connecte...',
[AContext.Connection.Socket.Binding.PeerIP]));
end;

But I got error on 'with Create(AData) do' line. Does anyone has code
sample to show me???

Back to top
Rob Kennedy
Guest





PostPosted: Sun Feb 06, 2005 7:33 pm    Post subject: Re: Indy 10 Synchronise problem. Reply with quote



[email]chuayongquan (AT) hotmail (DOT) com[/email] wrote:
Quote:
How to I use Synchronise method in IdTCPServer???

Have you tried asking on one of the Indy newsgroups? Have you looked at
example uses of the class in the Indy code and demos?

Quote:
procedure TSyncClass.Create(AData: String);
begin
inherited Create;
FData := AData;
end;

procedure TSyncClass.DoSynchronize;
begin
Form1.ListBox1.ItemIndex := Form1.ListBox1.Items.Add(FData);
end;

class procedure TSyncClass.Update(AData: String);
begin
with Create(AData) do
try
Synchronize;
finally
Free;
end;
end;

procedure TForm1.IdTCPServer1Connect(AContext: TIdContext);
begin
TSyncClass.Update(Format('Le client %s se connecte...',
[AContext.Connection.Socket.Binding.PeerIP]));
end;

But I got error on 'with Create(AData) do' line.

It expedites the process if you take the time to tell us *what* error
you get.

My guess is that the compiler doesn't like that you're using a
*procedure* in a "with" statement. Procedures don't have return values,
so there is no value upon which to use "with."

Rewrite your code without the "with" crutch and you should see the
error. The compiler error, anyway. I have no idea whether you're using
the class correctly. It looks pretty strange.

--
Rob

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.