Solved

OnWork event for idTHCPClient

Posted on 2006-07-06
3
215 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 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

13 Experts available now in Live!

Get 1:1 Help Now