Entwickler-Ecke

Delphi Language (Object-Pascal) / CLX - Was bedeutet disese Fehler?


Moritz M. - Fr 17.01.03 14:59
Titel: Was bedeutet disese Fehler?
Hi

Ich bekomm vom Compiler folgende Warnungen:

Quelltext
1:
2:
3:
4:
[Warning] Unit1.pas(165): Combining signed and unsigned types - widened both operands
[Warning] Unit1.pas(167): Combining signed and unsigned types - widened both operands
[Warning] Unit1.pas(169): Combining signed and unsigned types - widened both operands
[Warning] Unit1.pas(171): Combining signed and unsigned types - widened both operands


Was kann ich dagegen tun?


Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
function Tprog.UpTime: string;
const
  ticksperday: Integer    = 1000 * 60 * 60 * 24;
  ticksperhour: Integer   = 1000 * 60 * 60;
  ticksperminute: Integer = 1000 * 60;
  tickspersecond: Integer = 1000;
var
  t:          Longword;
  d, h, m, s: Integer;
begin
  t:=GetTickCount;
  d:=t div ticksperday;        //Zeile 165
  Dec(t, d * ticksperday);
  h:=t div ticksperhour;      //Zeile 167
  Dec(t, h * ticksperhour);
  m:=t div ticksperminute;  //Zeile 189
  Dec(t, m * ticksperminute);
  s:=t div tickspersecond;    //Zeile 171
  Result:=IntToStr(d)+' Tage '+IntToStr(h)+' Stunden '+IntToStr(m)+' Minuten '+IntToStr(s)+' Sekunden';
end;


Simon Joker - Fr 17.01.03 15:37

Hi

du weiset einem LongWord (soweit ich weis vorzeichenlos) einen Integer (Vorzeichen behaftet) zu. Das geht in die Hose, wenn der Negativ ist. Passe einfach deine Variablen an.


Moritz M. - Fr 17.01.03 15:39

Danke, jetzt gehts einwandfrei!