I am using a VCL TCPServer components which fires events everytime a data is received on a tcp port. Within the event data is available into text parameter of the procedure. Because I want to save this data into mysql database I am wondering which is the best approach to this problem. Directly use an INSERT SQL command within the procedure for every data received or store the data in a memory (i.e. TStrings) and then calling a function every X (using Timer) minutes excute the INSERT command?
Thanks
Well,
You should not save your data inside the event, because you are breaking the component execution flow when you do that. Instead:
1 - You can buffer all data you want to save, and from time to time you save them (not good, you can lost a lot of data if something happens with your app).
2 - Inside the event, create a thread that will receive the data and save them to the database. This way you are not breaking the event flow execution and you will have all data saved on the fly. Also you will be using one more core of your CPU if you do so. That is what i would do.
Code for solution 2 (untested):
Check this out if you dont know threads: Multithreading - The Delphi Way