interface type TMonThread = class(TThread) private FLeCompo: TJvHidControllerClass; public procedure OnData(les paramètres que j'ignore); constructor Create(CreateSuspended: Boolean); reintroduce; destructor Destroy; override; end; implementation procedure TMonThread.OnData(les paramètres que j'ignore); begin // traiter la réception des trames, fait au sein du thread end; constructor TMonThread.Create(CreateSuspended: Boolean); begin inherited; // trucs à l'initialisation FLeCompo := TJvHidControllerClass.Create(nil); FLeCompo.OnData := OnData; // affecter la méthode appartenant au thread au compo end; destructor TMonThread.Destroy; begin FLeCompo.Free; inherited; end;
procedure TJvHidDeviceReadThread.Execute; var SleepRet: DWORD; begin SleepRet := WAIT_IO_COMPLETION; while not Terminated do begin // read data SleepRet := WAIT_IO_COMPLETION; FillChar(Report[0], Device.Caps.InputReportByteLength, #0); if Device.ReadFileEx(Report[0], Device.Caps.InputReportByteLength, @DummyReadCompletion) then begin // wait for read to complete repeat SleepRet := SleepEx(Device.ThreadSleepTime, True); until Terminated or (SleepRet = WAIT_IO_COMPLETION); // show data read if not Terminated then begin NumBytesRead := Device.HidOverlappedReadResult; if NumBytesRead > 0 then // synchronizing only works if the component is not instanciated in a DLL if IsLibrary then DoData else Synchronize(DoData); end; end else begin FErr := GetLastError; Synchronize(DoDataError); end; end; // cancel ReadFileEx call or the callback will // crash your program if SleepRet <> WAIT_IO_COMPLETION then Device.CancelIO(omhRead); end;
begin EnterCriticalSection(PrimeFrm.StringSection); PrimeFrm.StringBuf.Add(IntToStr(CurrentNum) + ' is prime.'); LeaveCriticalSection(PrimeFrm.StringSection); PostMessage(PrimeFrm.Handle, WM_DATA_IN_BUF, 0, 0); end;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question