Ignore:
Timestamp:
Jan 3, 2011, 7:22:47 AM (14 years ago)
Author:
george
Message:
  • Added: TGMatrix implode.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Generic/GenericMatrix.inc

    r107 r109  
    66  TGMatrixToStringConverter = function(Item: TGMatrixItem): string;
    77  TGMatrixFromStringConverter = function(Text: string): TGMatrixItem;
     8  TGMatrixRow = array of TGMatrixItem;
    89
    910  TGMatrixIndex = record
     
    2829  public
    2930    function Add(Item: TGMatrixItem): TGMatrixIndex;
    30     procedure AddArray(Values: array of TGMatrixItem);
     31    procedure AddMatrix(Values: array of TGMatrixRow);
    3132    procedure AddList(List: TGMatrix);
    3233    procedure Assign(Source: TGMatrix);
     
    4243    property First: TGMatrixItem read GetFirst write SetFirst;
    4344    procedure Fill(Start, Count: TGMatrixIndex; Value: TGMatrixItem);
    44     function Implode(Separator: string; Converter: TGMatrixToStringConverter): string;
     45    function Implode(RowSeparator, ColSeparator: string; Converter: TGMatrixToStringConverter): string;
    4546    procedure Explode(Text, Separator: string; Converter: TGMatrixFromStringConverter; SlicesCount: Integer = -1);
    4647    function IndexOf(Item: TGMatrixItem; Start: TGMatrixIndex = 0): TGMatrixIndex;
     
    363364end;
    364365
    365 procedure TGMatrix.AddArray(Values: array of TGMatrixItem);
     366procedure TGMatrix.AddMatrix(Values: array of TGMatrixRow);
    366367var
    367368  I: TGMatrixIndex;
     
    397398end;
    398399
    399 function TGMatrix.Implode(Separator: string; Converter: TGMatrixToStringConverter): string;
    400 var
    401   I: TGMatrixIndex;
    402 begin
    403 (*  Result := '';
    404   I := 0;
    405   while I < Count do begin
    406     Result := Result + Converter(Items[I]);
    407     if I < (Count - 1) then
    408       Result := Result + Separator;
    409     I := I + 1;
    410   end; *)
     400function TGMatrix.Implode(RowSeparator, ColSeparator: string; Converter: TGMatrixToStringConverter): string;
     401var
     402  Y: TGMatrixIndexY;
     403  X: TGMatrixIndexX;
     404begin
     405  Result := '';
     406  Y := 0;
     407  while Y < Count.Y do begin
     408    X := 0;
     409    while X < Count.X do begin
     410      Result := Result + Converter(Items[Y, X]);
     411      if X < (Count.X - 1) then
     412        Result := Result + ColSeparator;
     413      X := X + 1;
     414    end;
     415    if Y < (Count.Y - 1) then
     416      Result := Result + RowSeparator;
     417    Y := Y + 1;
     418  end;
    411419end;
    412420
Note: See TracChangeset for help on using the changeset viewer.