Ignore:
Timestamp:
Dec 20, 2011, 9:37:35 AM (13 years ago)
Author:
chronos
Message:
  • Opraveno: Generování výstupu u TQueryForm a THtmlTable.
  • Přidáno: Mimo přihlašovací formulář přidán také registrační.
File:
1 edited

Legend:

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

    r65 r66  
    7070  end;
    7171
     72  { THtmlElement }
     73
    7274  THtmlElement = class
    73   private
     75  protected
    7476    function GetAsXmlElement: TXmlElement; virtual;
    7577  public
     
    7880    ClassId: string;
    7981    Style: string;
     82    procedure Assign(Source: THtmlElement); virtual;
    8083    property AsXmlElement: TXmlElement read GetAsXmlElement;
    8184  end;
     
    8386  TBlockType = (btNoTag, btBlockLevel, btInline);
    8487
     88  { THtmlString }
     89
    8590  THtmlString = class(THtmlElement)
    8691  private
     
    8893  public
    8994    Text: string;
     95    procedure Assign(Source: THtmlElement); override;
    9096  end;
    9197
     
    100106
    101107  THtmlBlock = class(THtmlElement)
    102   private
     108  protected
    103109    function GetAsXmlElement: TXmlElement; override;
    104110  public
     
    149155    InputType: THtmlInputType;
    150156    Value: Variant;
     157    procedure Assign(Source: THtmlElement); override;
    151158    constructor Create;
    152159    destructor Destroy; override;
     
    156163
    157164  THtmlForm = class(THtmlBlock)
    158   private
     165  protected
     166    function GetAsXmlElement: TXmlElement; override;
    159167  public
    160168    Method: string;
    161169    Action: TURL;
    162     function GetAsXmlElement: TXmlElement; override;
    163170    constructor Create;
    164171    destructor Destroy; override;
     
    183190
    184191  THtmlCell = class(THtmlElement)
     192  private
     193    function GetAsXmlElement: TXmlElement; override;
     194  public
    185195    RowSpan: Integer;
    186196    ColSpan: Integer;
    187197    Value: THtmlElement;
    188198    constructor Create;
     199    destructor Destroy; override;
    189200  end;
    190201
     
    192203
    193204  THtmlRow = class(THtmlElement)
     205  private
     206    function GetAsXmlElement: TXmlElement; override;
     207  public
    194208    Cells: TListObject; // TListObject<THtmlCell>
    195209    constructor Create;
     
    199213  { THtmlTable }
    200214
    201   THtmlTable = class
    202   private
    203     function GetAsXmlDocument: TXmlDocument;
     215  THtmlTable = class(THtmlElement)
     216  protected
     217    function GetAsXmlElement: TXmlElement; override;
    204218  public
    205219    Rows: TListObject; // TListObject<THtmlRow>
    206     property AsXmlDocument: TXmlDocument read GetAsXmlDocument;
    207220    constructor Create;
    208221    destructor Destroy; override;
     
    280293{ THtmlCell }
    281294
     295function THtmlCell.GetAsXmlElement: TXmlElement;
     296begin
     297  Result := inherited GetAsXmlElement;
     298  TXmlTag(Result).Name := 'td';
     299  with TXmlTag(Result).Attributes do begin
     300    if ColSpan > 1 then Add('colspan', IntToStr(ColSpan));
     301    if RowSpan > 1 then Add('rowspan', IntToStr(RowSpan));
     302  end;
     303  TXmlTag(Result).SubElements.Add(Value.AsXmlElement);
     304end;
     305
    282306constructor THtmlCell.Create;
    283307begin
     
    286310end;
    287311
     312destructor THtmlCell.Destroy;
     313begin
     314  Value.Free;
     315  inherited Destroy;
     316end;
     317
    288318{ THtmlRow }
     319
     320function THtmlRow.GetAsXmlElement: TXmlElement;
     321var
     322  Column: Integer;
     323begin
     324  Result := inherited GetAsXmlElement;
     325  TXmlTag(Result).Name := 'tr';
     326  for Column := 0 to Cells.Count - 1 do
     327    TXmlTag(Result).SubElements.AddNew(THtmlCell(Cells[Column]).AsXmlElement);
     328end;
    289329
    290330constructor THtmlRow.Create;
     
    301341{ THtmlTable }
    302342
    303 function THtmlTable.GetAsXmlDocument: TXmlDocument;
     343function THtmlTable.GetAsXmlElement: TXmlElement;
    304344var
    305345  Row, Column: Integer;
    306346begin
     347  Result := inherited;
    307348  with TXmlTag(Result) do begin
    308349    Name := 'table';
    309350    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;
     351      SubElements.AddNew(THtmlRow(Rows[Row]).AsXmlElement);
    318352  end;
    319353end;
     
    363397    Attributes.Add('type', InputTypeString);
    364398    Attributes.Add('value', Value);
    365     Attributes.Add('name', Name);
    366   end;
     399    if Self.Name <> '' then
     400      Attributes.Add('name', Self.Name);
     401  end;
     402end;
     403
     404procedure THtmlInput.Assign(Source: THtmlElement);
     405begin
     406  inherited Assign(Source);
     407  InputType := THtmlInput(Source).InputType;
     408  Value := THtmlInput(Source).Value;
    367409end;
    368410
     
    523565end;
    524566
     567procedure THtmlElement.Assign(Source: THtmlElement);
     568begin
     569  Id := Source.Id;
     570  Name := Source.Name;
     571  ClassId := Source.ClassId;
     572  Style := Source.Style;
     573end;
     574
    525575{ TIpAddress }
    526576
     
    707757end;
    708758
     759procedure THtmlString.Assign(Source: THtmlElement);
     760begin
     761  inherited Assign(Source);
     762  Text := THtmlString(Source).Text;
     763end;
     764
    709765{ THostAddress }
    710766
Note: See TracChangeset for help on using the changeset viewer.