Thema: Delphi Thread in dll

Einzelnen Beitrag anzeigen

clownxx

Registriert seit: 18. Jun 2003
63 Beiträge
 
#13

Re: Thread in dll

  Alt 12. Dez 2007, 10:01
mh ok. Es geht ja eigentlich bei dem Datenspeicher um diese TComport komponenten, da kann ich nun nicht so wirklich feststellen was da nun der Datenspeicher ist....Ich habe es nun so gemacht:

Delphi-Quellcode:
procedure TComThread.DispatchComMsg;
begin
  FComPort.FSynchronizer.beginRead;
  DoEvents;
  FComPort.FSynchronizer.EndREad;
end;
DoEvents macht dann folgendes:

Delphi-Quellcode:
procedure TComThread.DoEvents;
begin
  FComPort.CallRxChar;
end;
und in Call RxChar (wo die Callback aufgerufen wird) passiert das:

Delphi-Quellcode:
procedure TCustomComPort.CallRxChar;
var
  Count: Integer;

  // read from input buffer
  procedure PerformRead(var P: Pointer);
  begin
    GetMem(P, Count);
    Read(P^, Count);
    // call OnRxBuf event
    DoRxBuf(P^, Count);
  end;

  // check if any component is linked, to OnRxChar event
  procedure CheckLinks;
  {$WARNINGS OFF}
  var
    I: Integer;
    P: Pointer;
    ComLink: TComLink;
    ReadFromBuffer: Boolean;
  begin
    // examine links
    if (Count > 0) and (not TriggersOnRxChar) then
    begin
      ReadFromBuffer := False;
      try
        // cycle through links
        for I := 0 to FLinks.Count - 1 do
        begin
          ComLink := TComLink(FLinks[I]);
          if Assigned(ComLink.OnRxBuf) then
          begin
            // link to OnRxChar event found
            if not ReadFromBuffer then
            begin
              // TCustomComPort must read from comport, so OnRxChar event is
              // not triggered
              ReadFromBuffer := True;
              PerformRead(P);
            end;
            // send data to linked component
            ComLink.OnRxBuf(Self, P^, Count);
          end
        end;
        if (not ReadFromBuffer) and (not FTriggersOnRxChar) then
        begin
          ReadFromBuffer := True;
          PerformRead(P);
        end;
      finally
        if ReadFromBuffer then
        begin
          FreeMem(P);
          // data is already out of buffer, prevent from OnRxChar event to occur
          Count := 0;
        end;
      end;
    end;
  end;

begin
  Count := InputCount;
  //@clownxx
  FSynchronizer.BeginRead;
  ///
  if Count > 0 then
    SendSignalToLink(leRx, True);
  CheckLinks;
  if Count > 0 then
    DoRxChar(Count);
  //@clownxx
  FSynchronizer.EndRead;
  ///
end;
Viel Code, aber vielleicht ist es so verständlicher wie das Teil aufgebaut ist.
  Mit Zitat antworten Zitat