Solved

Delphi Indy tcp server

Posted on 2014-03-21
1
910 Views
Last Modified: 2014-03-24
Hello.

I try to create an application
that takes all  data from a printout and save to a uniqe filename (or insert into a database)

it seems to work  as long as I don't try to print two documents at the same time.
How can I solve this...

My code::


 private
 
    sl : TstringList;
    MyDataStr : string;



.....


procedure TfForm1.IdTCPServer1Connect(AContext: TIdContext);
begin
   sl :=TstringList.Create;
  MyDataStr:= '';

end;

procedure TForm1.IdTCPServer1Disconnect(AContext: TIdContext);
begin
  sl.Text:= MyDataStr;
  sl.SaveToFile(MyDir+ \GetUniqeFileName);
  sl.Free;
  end;
0
Comment
Question by:pucko73
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39946684
You need create string list by context (create separate string list by each client connected)

procedure TfForm1.IdTCPServer1Connect(AContext: TIdContext);
begin
   AContext.Data := TstringList.Create;
end;

procedure TForm1.IdTCPServer1Disconnect(AContext: TIdContext);
var
  CliContext: TStringList;
begin
    CliContext:=TStringList(AContext.Data);
    CliContext.SaveToFile(MyDir+ \GetUniqeFileName); 
    AContext.Data.Free;
    AContext.Data := nil;
end; 

procedure TfForm1.IdTCPServer1Execute(AContext: TIdContext);
begin
...
    if not AContext.Connection.IOHandler.InputBufferIsEmpty then
      ...read bytes here and store in string list as 
      ...TStringList(AContext.Data).Add(....) 
end;

Open in new window


sl  and MyDataStr is no longer needed ...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question