Changeset 51 for trunk/Packages/TemplateGenerics/Generic/GenericMatrix.inc
- Timestamp:
- Dec 20, 2021, 6:45:12 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/TemplateGenerics/Generic/GenericMatrix.inc
r34 r51 30 30 procedure PutItem(Index: TGMatrixIndex; const AValue: TGMatrixItem); virtual; 31 31 procedure SetCount(const AValue: TGMatrixIndex); 32 procedure CheckRange(X: TGMatrixIndexX; Y: TGMatrixIndexY); inline; 32 33 public 34 constructor Create; virtual; 33 35 function Add(Item: TGMatrixItem): TGMatrixIndex; 34 36 procedure AddMatrix(Values: array of TGMatrixRow); … … 140 142 begin 141 143 if (Capacity.X <> AValue.X) and (Capacity.Y <> AValue.Y) then begin 142 (*SetLength(FItems, AValue.Y);144 SetLength(FItems, AValue.Y); 143 145 Y := 0; 144 146 while Y < Length(FItems) do begin … … 146 148 Y := Y + 1; 147 149 end; 148 end; 149 *) 150 SetLength(FItems, AValue.Y, AValue.X); 150 151 { SetLength(FItems, AValue.Y, AValue.X);} 151 152 end; 152 153 end; 153 154 154 155 function TGMatrix.GetItemXY(X: TGMatrixIndexX; Y: TGMatrixIndexY): TGMatrixItem; 156 begin 157 CheckRange(X, Y); 158 Result := FItems[Y, X]; 159 end; 160 161 function TGMatrix.GetItem(Index: TGMatrixIndex): TGMatrixItem; 162 begin 163 CheckRange(Index.X, Index.Y); 164 Result := FItems[Index.Y, Index.X]; 165 end; 166 167 procedure TGMatrix.PutItemXY(X: TGMatrixIndexX; Y: TGMatrixIndexY; const AValue: TGMatrixItem); 168 begin 169 CheckRange(X, Y); 170 FItems[Y, X] := AValue; 171 end; 172 173 procedure TGMatrix.PutItem(Index: TGMatrixIndex; const AValue: TGMatrixItem); 174 begin 175 CheckRange(Index.X, Index.Y); 176 FItems[Index.Y, Index.X] := AValue; 177 end; 178 179 procedure TGMatrix.SetCount(const AValue: TGMatrixIndex); 180 begin 181 Capacity := AValue; 182 FCount := AValue; 183 end; 184 185 procedure TGMatrix.CheckRange(X: TGMatrixIndexX; Y: TGMatrixIndexY); 155 186 begin 156 187 if (X < 0) or (X >= Count.X) or 157 188 (Y < 0) or (Y >= Count.Y) then 158 189 raise EListError.CreateFmt(SMatrixIndexError, [X, Y]); 159 Result := FItems[Y, X];160 end;161 162 function TGMatrix.GetItem(Index: TGMatrixIndex): TGMatrixItem;163 begin164 if (Index.X < 0) or (Index.X >= Count.X) or165 (Index.Y < 0) or (Index.Y >= Count.Y) then166 raise EListError.CreateFmt(SMatrixIndexError, [Index.X, Index.Y]);167 Result := FItems[Index.Y, Index.X];168 end;169 170 procedure TGMatrix.PutItemXY(X: TGMatrixIndexX; Y: TGMatrixIndexY; const AValue: TGMatrixItem);171 begin172 if (X < 0) or (X >= Count.X) or173 (Y < 0) or (Y >= Count.Y) then174 raise EListError.CreateFmt(SMatrixIndexError, [X, Y]);175 FItems[Y, X] := AValue;176 end;177 178 procedure TGMatrix.PutItem(Index: TGMatrixIndex; const AValue: TGMatrixItem);179 begin180 if (Index.X < 0) or (Index.X >= Count.X) or181 (Index.Y < 0) or (Index.Y >= Count.Y) then182 raise EListError.CreateFmt(SMatrixIndexError, [Index.X, Index.Y]);183 FItems[Index.Y, Index.X] := AValue;184 end;185 186 procedure TGMatrix.SetCount(const AValue: TGMatrixIndex);187 begin188 Capacity := AValue;189 FCount := AValue;190 190 end; 191 191 … … 555 555 end; 556 556 557 constructor TGMatrix.Create; 558 begin 559 SetLength(FItems, 0, 0); 560 FCount := CreateIndex(0, 0); 561 end; 562 557 563 procedure TGMatrix.Clear; 558 564 begin
Note:
See TracChangeset
for help on using the changeset viewer.