Traduction C++ vers Delphi
Voilà, j'ai entrepris de traduire une fonction c++ en delphi et je bloque sur 3 lignes qui me disent vraiment rien, voilà la fonction C++
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
DWORD WINAPI ThreadLireCom(void)
{
int i=2,j=0;bool bBits;nbCom=0;int Tps=0;DWORD Errors;
LONGLONG PerformanceCount=0,PerformanceCountOld=0;
SetCommMask(hCom,EV_DSR);
while(IsActif)
{
WaitCommEvent(hCom,&Errors,0);nbCom++;
PerformanceCountOld=PerformanceCount;
QueryPerformanceCounter((LARGE_INTEGER *)&PerformanceCount);
Tps = (int)((float)(PerformanceCount-PerformanceCountOld)*1000000/Frequency);
if(Tps > 13337)
{
nbCom=1;i=2;j=0;
memset(&szCom,0,sizeof(szCom));
memset(&szComOld,0,sizeof(szComOld));
}
if(nbCom==i)
{
bBits=(nbCom%2==0);
szCom[j++]=(bBits) ? 0x31:0x30;
if(Tps > 1333 && nbCom!=1)
{
i++;
szCom[j]=(!bBits) ? 0x31:0x30;
}
else
{
i+=2;
if(!bBits) szCom[j]=0x30;
}
}
}
return 0;
} |
Et voilà ma traduction
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
procedure TThreadRC5.ecoute;
var
i, j, tps : integer;
bBits : boolean;
nbCom : integer;
Errors : DWord;
PerformanceCount, PerformanceCountOld, Frequency : TLargeInteger;
szCom : array [0..256] of char;
szComOld : array [0..256] of char;
begin
i := 2;
j := 0;
nbCom := 0;
tps := 0;
PerformanceCount :=0;
PerformanceCountOld :=0;
SetCommMask(hCom,EV_DSR);
QueryPerformanceFrequency(Frequency);
while connect do
begin
WaitCommEvent(hCom,Errors,nil);
inc(nbCom);
PerformanceCountOld := PerformanceCount;
QueryPerformanceCounter(PerformanceCount);
Tps := Trunc((PerformanceCount-PerformanceCountOld)*1000000/Frequency);
if (Tps > 13337)then
begin
nbCom :=1;
i :=2;
j :=0;
FillChar(szCom, 0, sizeof(szCom));
FillChar(szComOld, 0, sizeof(szComOld));
end;
if nbCom = i then
begin
bBits :=(nbCom mod 2 =0);
inc(j);
szCom[j]:=(bBits) ? 0x31:0x30; //<-- ici
if(Tps > 1333) and ( nbCom <> 1) then
begin
inc(i);
szCom[j] :=(bBits = false) ? $31:$30; //<-- ici
end
else
begin
inc(i,2);
if(bBits = false) then szCom[j]:= $30; //<-- ici
end;
end;
end;
end; |
Est ce que qqn peut me dire a quoi correspondent les trois lignes marquée "ici" dans ma procedure svp, je crois comprendre que c'est une conversion en binaire, j'ai cherché partout mais j'ai vraiment rien trouvé, merci. Et au passage si vous voyez qqchose de louche faites moi signe. :wink: