Changeset 26 for trunk/UXmlClasses.pas


Ignore:
Timestamp:
Sep 10, 2022, 8:03:08 PM (2 years ago)
Author:
chronos
Message:
  • Removed: TemplateGenerics as required package. Used Generics.Collections instead.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        77heaptrclog.trc
        88MyData.exe
         9MyData.dbg
         10
  • trunk/UXmlClasses.pas

    r19 r26  
    11unit UXmlClasses;
    2 
    3 {$mode delphi}{$H+}
    42
    53interface
    64
    7 uses Classes, SysUtils, StrUtils, SpecializedList,
    8   SpecializedDictionary;
     5uses
     6  Classes, SysUtils, StrUtils, Generics.Collections, UGenerics;
    97
    108type
     
    1412  public
    1513    property AsString: string read GetAsString;
     14  end;
     15
     16  TXmlTag = class;
     17  TXmlString = class;
     18
     19  { TXmlElements }
     20
     21  TXmlElements = class(TObjectList<TXmlElement>)
     22    function AddTag(Name: string): TXmlTag;
     23    function AddString(Text: string): TXmlString;
    1624  end;
    1725
     
    3139    Name: string;
    3240    Attributes: TDictionaryStringString;
    33     SubElements: TListObject; // TListObject<TXmlElement>;
     41    SubElements: TXmlElements;
    3442    constructor Create;
    3543    destructor Destroy; override;
     
    5159  end;
    5260
     61
    5362implementation
     63
     64{ TXmlElements }
     65
     66function TXmlElements.AddTag(Name: string): TXmlTag;
     67begin
     68  Result := TXmlTag.Create;
     69  Result.Name := Name;
     70  Add(Result);
     71end;
     72
     73function TXmlElements.AddString(Text: string): TXmlString;
     74begin
     75  Result := TXmlString.Create;
     76  Result.Text := Text;
     77  Add(Result);
     78end;
    5479
    5580{ THtmlElement }
     
    5984  ShringEmpty := True;
    6085  Attributes := TDictionaryStringString.Create;
    61   SubElements := TListObject.Create;
     86  SubElements := TXmlElements.Create;
    6287  EndTagSymbol := '/';
    6388end;
     
    6590destructor TXmlTag.Destroy;
    6691begin
    67   Attributes.Free;
    68   SubElements.Free;
     92  FreeAndNil(Attributes);
     93  FreeAndNil(SubElements);
    6994  inherited;
    7095end;
     
    75100  I: Integer;
    76101  Content: string;
     102  Attribute: TPair<string, string>;
    77103begin
    78104  Content := '';
     
    81107
    82108  AttributesText := '';
    83   for I := 0 to Attributes.Count - 1 do
    84     AttributesText := AttributesText + ' ' + Attributes.Keys[I] + '="' + Attributes[I].Value + '"';
     109  for Attribute in Attributes do
     110    AttributesText := AttributesText + ' ' + Attribute.Key + '="' + Attribute.Value + '"';
    85111
    86112  if Name <> '' then begin
     
    124150destructor TXmlDocument.Destroy;
    125151begin
    126   Content.Free;
    127   MainTag.Free;
     152  FreeAndNil(Content);
     153  FreeAndNil(MainTag);
    128154  inherited;
    129155end;
Note: See TracChangeset for help on using the changeset viewer.