Fix for Mantis #23909.

gvector.pp, TVector.TVectorEnumerator:
  * the size of a vector is of type SizeUInt which is LongWord on 32 bit systems and QWord on 64 bit systems and which is in both cases not the same as Integer which is LongInt
  + add a boolean property to detect whether the first call to MoveNext was done
  * check in MoveNext whether the first call was done and return approbiate results
gvector.pp, TVector:
  + declare GetEnumerator as inline as well

git-svn-id: trunk@23645 -
This commit is contained in:
svenbarth 2013-02-22 10:52:50 +00:00
parent 354ebb822a
commit c21b34daf1

View File

@ -45,10 +45,11 @@ type
TVectorEnumerator = class
private
FVector: TVector;
FPosition: Integer;
FPosition: SizeUInt;
FFirstDone: Boolean;
function GetCurrent: T; inline;
public
constructor Create(AVector: TVector);
function GetCurrent: T; inline;
function MoveNext: Boolean; inline;
property Current: T read GetCurrent;
end;
@ -67,7 +68,7 @@ type
procedure Reserve(Num: SizeUInt); inline;
procedure Resize(Num: SizeUInt); inline;
function GetEnumerator: TVectorEnumerator;
function GetEnumerator: TVectorEnumerator; inline;
property Items[i : SizeUInt]: T read getValue write setValue; default;
property Mutable[i : SizeUInt]: PT read getMutable;
@ -80,7 +81,6 @@ implementation
constructor TVector.TVectorEnumerator.Create(AVector: TVector);
begin
FVector := AVector;
FPosition := -1;
end;
function TVector.TVectorEnumerator.GetCurrent: T;
@ -90,9 +90,14 @@ end;
function TVector.TVectorEnumerator.MoveNext: Boolean;
begin
Result := FPosition < FVector.Size - 1;
if Result then
inc(FPosition);
if not FFirstDone then begin
Result := FVector.Size > 0;
FFirstDone := True;
end else begin
Result := FPosition < FVector.Size - 1;
if Result then
inc(FPosition);
end;
end;
{ TVector }