![]() |
Delphi-Version: 5
Codestelle erklären (Tapi / shl)?
Hallo,
kann mir jemand die folgende Funktion einmal erklären? Es ist eine Funktion um den Zustand eines mit der Tapi überwachten Calls auszulesen, aber ich versteh nicht wie das funktioniert (die for-schleife):
Delphi-Quellcode:
TAPI_LineCallState ist ein String Array:
function TMyCall.get_CallState: string;
var i: integer; begin try if priv_LineCallStatus.MyCallStatus.dwCallState = 0 then begin Result := '*** false ***'; end else begin Result := ''; for i := low(TAPI_LineCallState) to High(TAPI_LineCallState) do if (priv_LineCallStatus.MyCallStatus.dwCallState and (1 shl i)) > 0 then Result := Result + TAPI_LineCallState[i] + ', '; if Length(Result) > 0 then Result := Copy(Result, 1, Length(Result) - 2); end; except MyTapi.ShowWarning('Error: TMyLine.get_CallState', 'uMyTapiObj'); end; end;
Delphi-Quellcode:
dwCallState kommt aus der Tapi:
TAPI_LineCallState: array [0..15] of string =
( 'LINECALLSTATE_IDLE', 'LINECALLSTATE_OFFERING', 'LINECALLSTATE_ACCEPTED', 'LINECALLSTATE_DIALTONE', 'LINECALLSTATE_DIALING', //usw.
Delphi-Quellcode:
PLineCallStatus = ^TLineCallStatus;
linecallstatus_tag = packed record dwTotalSize, dwNeededSize, dwUsedSize, dwCallState, dwCallStateMode, dwCallPrivilege, dwCallFeatures, dwDevSpecificSize, dwDevSpecificOffset: DWORD; {$IFDEF TAPI20} dwCallFeatures2: DWORD; // TAPI v2.0 {$IFDEF WIN32} tStateEntryTime: TSystemTime; // TAPI v2.0 {$ELSE} tStateEntryTime: array[0..7] of WORD; // TAPI v2.0 {$ENDIF} {$ENDIF} end; {$EXTERNALSYM linecallstatus_tag} TLineCallStatus = linecallstatus_tag; LINECALLSTATUS = linecallstatus_tag; {$EXTERNALSYM LINECALLSTATUS} |
AW: Codestelle erklären (Tapi / shl)?
mit dem dwCallState and (1 shl i) wird geprüft ob das entsprechende Bit gesetzt ist im Anruferstatus. Shl (shift left) verschiebt alle Bits in einem Wert um die angegebene Anzahl nach links, a shl b antspricht also a := a*2^b.
|
AW: Codestelle erklären (Tapi / shl)?
Das ist einfach ein Vergleich mit einer Bitmaske, siehe auch
![]() |
AW: Codestelle erklären (Tapi / shl)?
Delphi-Quellcode:
Noch Fragen?
for i := low(TAPI_LineCallState) to High(TAPI_LineCallState) do {all poss. states}
if (priv_LineCallStatus.MyCallStatus.dwCallState and (1 shl i)) > 0 {is Bit set? } then Result := Result + TAPI_LineCallState[i] + ', '; {add the statustext } Gruß K-H ist der rote Kasten im Urlaub? |
AW: Codestelle erklären (Tapi / shl)?
Habs glaub ich verstanden:
(1 shl i) hat nur an iter Stelle eine 1 sonst überall 0. Das and ist hier nicht eine logische Operation sondern die bitweise Addition. Somit kommt da nur was >0 raus, wenn auch dwCallstate in binärer Darstellung an iter Position eine 1 hat. Danke und bitte ein Bit für alle :cheers: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:03 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz