Menu

#18 Doonread is called twice under different contexes in unit NoDaveComponent.pas for Delphi, Lazarus

v1.0 (example)
open
None
5
2014-05-06
2014-05-06
Christian
No

Hi,

when using several connection the values were mixed. To solve this problem i found the following solution:

The Funtion DoOnread is called in TNodave.Readbytes and in TNoDaveReadThread.Execute.
TNoDaveReadThread.Execute however calls TNodave.Readbyte too so DoOnread is called twice.
One call is in the cantext of the thread the other is Synchronized.
So the values to be worked with can come from other connections.

procedure TNoDave.ReadBytes(Buffer: Pointer);
begin
If not Assigned(Buffer) then Buffer:=FBuffer;
If Active then
begin
DoReadBytes(FArea, FDBNumber, FBufOffs, FBufLen, Buffer);
//DoOnRead; <- commending out solves the problem
end;
end;

procedure TNoDaveReadThread.Execute;
var
StartTime: Cardinal;
NextTime: Cardinal;
begin
While NoDave.Active and (NoDave.Interval > 0) do
begin
StartTime:=GetTickCount;
NextTime:=StartTime + NoDave.Interval;
try
NoDave.ReadBytes; // read in context of thread
If NoDave.LastError = 0
then Synchronize(DoOnRead) // read in context of main thread
else
....

I use Lazarus 1.0.13 with FPC 2.6.2 in Windows 7
and hope this helps.

Christian

Discussion


Log in to post a comment.