Solved

OnWork event for idTHCPClient

Posted on 2006-07-06
3
214 Views
Last Modified: 2010-04-05
Hi!

I am writing a TCP client application and i am using indy9.
The server works as following:
When the connection established the server starts sending data messages. A message could look something like this:
<start>STX</start>
<configuration>.......</configuration>
<record>
          <paramcode>1</paramcode>
          <time>12:00</time>
         <mesurevalue>10</mesurevalue>
</record>
<record>
          <paramcode>12</paramcode>
          <time>12:00</time>
         <mesurevalue>10</mesurevalue>
</record>
The message is not really in xml.


number of record is changing. If a record has the right paramcode i should plot it on a graph. I have managed to do this by reading the hole message and then go through the records and plot it.
My question is is it possible to use onwork and check the records as they arrive on by one?
I would like to have my graph as a advanced progressbar so that u can watch the graph in realtime and se the values beeing ploted when they arrive.

Thanks
0
Comment
Question by:mikrodidakt
3 Comments
 
LVL 10

Expert Comment

by:atul_parmar
ID: 17048838
Can you tell me how you are reading the message.

If you are reading it in full, then change it so that it reads specified number of chars e.g. read one record at time. or character by character.
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 17049047
add
<rec_count>140</rec_count>

then you know that you are expecting 140 records and you can make a progress bar for example.
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 250 total points
ID: 17052780
if you are using WriteStream (or Write(Stream) ) then yes, you will need to look in your stream during the OnWork() event and get the data to plot it
eg. use the stream's position, and work out where the last <mesurevalue> would be in it. make sure you have not already plotted this one (ie. buffer has increased to include the next measure, and plot it

If however, you are just using

WriteLn('<record>');
WriteLn('          <paramcode>1</paramcode>');
WriteLn('          <time>12:00</time>');
WriteLn('         <mesurevalue>10</mesurevalue>');
WriteLn('</record>');

then there is no need for the OnWork event.
As you receive each line, chek it and plot the data
eg.
S := TCPCLient1.IOHandler.ReadLN;
i := pos('<mesurevalue>', s);
if i > 0 then
begin // plot it
  delete(s, 1, i _ length('<mesurevalue');
  s := copy(s, 1, pos('</mesurevalue>', s)-1);
  PlotValue(IntToStr(s));
end;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use Hashing sha1 in Delphi 2010 4 203
build html 5 client that connect to indy Tidtcpserver 3 355
code issue 8 100
Dynamically Created Query 3 50
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now