Lots of thanks, Taazz

Okay I know where the problem comes from but I can't fix it:
I got a Trackbar on form1. When changing the trackbar OFF/ON (0/1) something is executed. The problem is that the function was executing twice when I was changing the TrackBar.Position. I said, I'll add a public variable named TBar1 which will take the value on form create
Tbar1:=TrackBar_OnOff.Position
This Tbar1 will hold the last value of the Trackbar.Position so if Tbar1 and Trackbar Position are the same, the code does not execute=>
procedure TForm1.TrackBar_OnOffChange(Sender: TObject);
begin
if Tbar1 <> TrackBar_OnOff.Position then
if TrackBar_OnOff.Position = 0 then
begin
MData.mesaj := '0';
Showmessage('At 0');
end
else
begin
MData.mesaj := '1';
Showmessage('At 1');
end;
Tbar1:=Trackbar_OnOff.Position;
end;
The problem is that, it still executes twice and for some reason it doesn't pass the first if =>
if Tbar1 <> TrackBar_Mode.Position thenThis is all the code. Nothing more to it. The threads will be added later... I want a trackbar which turns ON/OFF but using trackbar as is, it will send the same command twice...
Got it fixed... Sort of.... It's still sending two messages... Any ideas?
Another question: How can I sync data with the main Thread? I have this procedure in the second thread:
procedure TMyThread.SyncData;
begin
Form1.ID:=ID;
Form1.OP:=OP;
Form1.Addr:=Addr;
Form1.DL:=DL;
Form1.Msg:=Msg;
Form1.Chk:=Chk;
Form1.Calc_chk:=calc_chk;
Form1.ack:=ack;
end; I call this at the last line of the secondary thread. Still, it's not doing it ...
And I tried to read on the event handlers but nothing's cleared... Can you provide a link or something where I could read about them? As I said, I'm new to this ...

I want to process data that gets from the RS232 interface into a new thread. I have the LazSerial defined in Form1 and I tried to do
procedure TForm1.LS1RxData(Sender: TObject);
var
receivedbyte: byte; //The variable which stores the received byte
begin
receivedbyte:=LS1.Readbyte;
Showmessage('Rec_app='+IntToStr(receivedbyte));
MThread.Run(receivedbyte); In MThread.Run(receivedbyte) there is:
procedure TMyThread.Run(receivedbyte:byte);
begin
Showmessage('In Thread='+IntToStr(receivedbyte));
if (receivedbyte = StrToInt('0x' + ff)) then
begin
if (not MRec.write_msg(receivedbyte, Count, ID, OP, DL, CHK, Addr, Msg)) then
ShowMessage('Could not write to message.' + sLineBreak +
'Counter=' + IntToStr(Count));
Count := Count + 1; //Count is the counter of bytes received.
alt := receivedbyte; //Alt is used to store the last received Byte
Showmessage('Byte is equal to 255');
end;
end
Still, there is a problem. I only get the 1st byte. Not the rest of them... At the first byte it all works great. After that, total silence...