Solved

Delphi Indy tcp server

Posted on 2014-03-21
1
897 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
1 Comment
 
LVL 26

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Working this component WebCopy with proxy, help 3 92
Delphi Yen format 3 45
Base1 Encode/Decode 3 82
Firemonkey webbrowser scrollbars ? 1 50
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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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