Ignore:
Timestamp:
Dec 19, 2011, 3:48:33 PM (13 years ago)
Author:
chronos
Message:
  • Přidáno: Třídy pro modelování HTML tabulky.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Components/CoolWeb/Common/UHtmlClasses.pas

    r61 r65  
    175175    Styles: TStringList;
    176176    Scripts: TStringList;
     177    property AsXmlDocument: TXmlDocument read GetAsXmlDocument;
     178    constructor Create;
     179    destructor Destroy; override;
     180  end;
     181
     182  { THtmlCell }
     183
     184  THtmlCell = class(THtmlElement)
     185    RowSpan: Integer;
     186    ColSpan: Integer;
     187    Value: THtmlElement;
     188    constructor Create;
     189  end;
     190
     191  { THtmlRow }
     192
     193  THtmlRow = class(THtmlElement)
     194    Cells: TListObject; // TListObject<THtmlCell>
     195    constructor Create;
     196    destructor Destroy; override;
     197  end;
     198
     199  { THtmlTable }
     200
     201  THtmlTable = class
     202  private
     203    function GetAsXmlDocument: TXmlDocument;
     204  public
     205    Rows: TListObject; // TListObject<THtmlRow>
    177206    property AsXmlDocument: TXmlDocument read GetAsXmlDocument;
    178207    constructor Create;
     
    247276    Result := False;
    248277  end;
     278end;
     279
     280{ THtmlCell }
     281
     282constructor THtmlCell.Create;
     283begin
     284  ColSpan := 1;
     285  RowSpan := 1;
     286end;
     287
     288{ THtmlRow }
     289
     290constructor THtmlRow.Create;
     291begin
     292  Cells := TListObject.Create;
     293end;
     294
     295destructor THtmlRow.Destroy;
     296begin
     297  Cells.Free;
     298  inherited Destroy;
     299end;
     300
     301{ THtmlTable }
     302
     303function THtmlTable.GetAsXmlDocument: TXmlDocument;
     304var
     305  Row, Column: Integer;
     306begin
     307  with TXmlTag(Result) do begin
     308    Name := 'table';
     309    for Row := 0 to Rows.Count - 1 do
     310    with TXmlTag(SubElements.AddNew(TXmlTag.Create)) do begin
     311      Name := 'tr';
     312      for Column := 0 to THtmlRow(Rows[Row]).Cells.Count - 1 do
     313      with TXmlTag(SubElements.AddNew(TXmlTag.Create)) do begin
     314        Name := 'td';
     315        SubElements.Add(THtmlCell(THtmlRow(Rows[Row]).Cells[Column]).Value);
     316      end;
     317    end;
     318  end;
     319end;
     320
     321constructor THtmlTable.Create;
     322begin
     323  Rows := TListObject.Create;
     324end;
     325
     326destructor THtmlTable.Destroy;
     327begin
     328  Rows.Free;
     329  inherited Destroy;
    249330end;
    250331
Note: See TracChangeset for help on using the changeset viewer.