| View previous topic :: View next topic |
| Author |
Message |
chuayongquan@hotmail.com Guest
|
Posted: Sun Feb 06, 2005 5:30 am Post subject: Indy 10 Synchronise problem. |
|
|
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
|
Posted: Sun Feb 06, 2005 7:33 pm Post subject: Re: Indy 10 Synchronise problem. |
|
|
[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 |
|
 |
|