?
Solved

Delphi Indy tcp server

Posted on 2014-03-21
1
Medium Priority
?
919 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
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…
Suggested Courses
Course of the Month11 days, left to enroll

770 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