- Timestamp:
- Jan 4, 2012, 2:21:31 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Network/CoolWeb/Common/UHtmlClasses.pas
r104 r309 9 9 10 10 type 11 12 { TDomainAddress } 13 11 14 TDomainAddress = class(TPersistent) 12 15 private … … 14 17 procedure SetAsString(const Value: string); 15 18 public 16 Levels: array of string; 19 Levels: TListString; 20 constructor Create; 21 destructor Destroy; override; 17 22 property AsString: string read GetAsString write SetAsString; 18 23 end; 19 24 20 25 TAddrClass = (acA, acB, acC, acD, acE); 26 27 { TIpAddress } 21 28 22 29 TIpAddress = class(TPersistent) … … 32 39 Octets: array[0..3] of Byte; 33 40 procedure Assign(Source: TPersistent); override; 41 function IsAddressString(Value: string): Boolean; 34 42 property AsCardinal: Cardinal read GetAsCardinal write SetAsCardinal; 35 43 property AsString: string read GetAsString write SetAsString; … … 70 78 end; 71 79 80 { THtmlElement } 81 72 82 THtmlElement = class 73 pr ivate83 protected 74 84 function GetAsXmlElement: TXmlElement; virtual; 75 85 public … … 78 88 ClassId: string; 79 89 Style: string; 90 procedure Assign(Source: THtmlElement); virtual; 80 91 property AsXmlElement: TXmlElement read GetAsXmlElement; 81 92 end; … … 83 94 TBlockType = (btNoTag, btBlockLevel, btInline); 84 95 96 { THtmlString } 97 85 98 THtmlString = class(THtmlElement) 86 99 private … … 88 101 public 89 102 Text: string; 103 procedure Assign(Source: THtmlElement); override; 90 104 end; 91 105 … … 100 114 101 115 THtmlBlock = class(THtmlElement) 102 pr ivate116 protected 103 117 function GetAsXmlElement: TXmlElement; override; 104 118 public … … 149 163 InputType: THtmlInputType; 150 164 Value: Variant; 165 ItemName: string; 166 procedure Assign(Source: THtmlElement); override; 151 167 constructor Create; 152 168 destructor Destroy; override; … … 156 172 157 173 THtmlForm = class(THtmlBlock) 158 private 174 protected 175 function GetAsXmlElement: TXmlElement; override; 159 176 public 160 177 Method: string; 161 178 Action: TURL; 162 function GetAsXmlElement: TXmlElement; override;163 179 constructor Create; 164 180 destructor Destroy; override; … … 176 192 Scripts: TStringList; 177 193 property AsXmlDocument: TXmlDocument read GetAsXmlDocument; 194 constructor Create; 195 destructor Destroy; override; 196 end; 197 198 { THtmlCell } 199 200 THtmlCell = class(THtmlElement) 201 private 202 function GetAsXmlElement: TXmlElement; override; 203 public 204 RowSpan: Integer; 205 ColSpan: Integer; 206 Value: THtmlElement; 207 constructor Create; 208 destructor Destroy; override; 209 end; 210 211 { THtmlRow } 212 213 THtmlRow = class(THtmlElement) 214 private 215 function GetAsXmlElement: TXmlElement; override; 216 public 217 Cells: TListObject; // TListObject<THtmlCell> 218 constructor Create; 219 destructor Destroy; override; 220 end; 221 222 { THtmlTable } 223 224 THtmlTable = class(THtmlElement) 225 protected 226 function GetAsXmlElement: TXmlElement; override; 227 public 228 Rows: TListObject; // TListObject<THtmlRow> 178 229 constructor Create; 179 230 destructor Destroy; override; … … 247 298 Result := False; 248 299 end; 300 end; 301 302 { THtmlCell } 303 304 function THtmlCell.GetAsXmlElement: TXmlElement; 305 begin 306 Result := inherited GetAsXmlElement; 307 TXmlTag(Result).Name := 'td'; 308 with TXmlTag(Result).Attributes do begin 309 if ColSpan > 1 then Add('colspan', IntToStr(ColSpan)); 310 if RowSpan > 1 then Add('rowspan', IntToStr(RowSpan)); 311 end; 312 TXmlTag(Result).SubElements.Add(Value.AsXmlElement); 313 end; 314 315 constructor THtmlCell.Create; 316 begin 317 ColSpan := 1; 318 RowSpan := 1; 319 end; 320 321 destructor THtmlCell.Destroy; 322 begin 323 Value.Free; 324 inherited Destroy; 325 end; 326 327 { THtmlRow } 328 329 function THtmlRow.GetAsXmlElement: TXmlElement; 330 var 331 Column: Integer; 332 begin 333 Result := inherited GetAsXmlElement; 334 TXmlTag(Result).Name := 'tr'; 335 for Column := 0 to Cells.Count - 1 do 336 TXmlTag(Result).SubElements.AddNew(THtmlCell(Cells[Column]).AsXmlElement); 337 end; 338 339 constructor THtmlRow.Create; 340 begin 341 Cells := TListObject.Create; 342 end; 343 344 destructor THtmlRow.Destroy; 345 begin 346 Cells.Free; 347 inherited Destroy; 348 end; 349 350 { THtmlTable } 351 352 function THtmlTable.GetAsXmlElement: TXmlElement; 353 var 354 Row, Column: Integer; 355 begin 356 Result := inherited; 357 with TXmlTag(Result) do begin 358 Name := 'table'; 359 for Row := 0 to Rows.Count - 1 do 360 SubElements.AddNew(THtmlRow(Rows[Row]).AsXmlElement); 361 end; 362 end; 363 364 constructor THtmlTable.Create; 365 begin 366 Rows := TListObject.Create; 367 end; 368 369 destructor THtmlTable.Destroy; 370 begin 371 Rows.Free; 372 inherited Destroy; 249 373 end; 250 374 … … 282 406 Attributes.Add('type', InputTypeString); 283 407 Attributes.Add('value', Value); 284 Attributes.Add('name', Name); 285 end; 408 if Self.ItemName <> '' then 409 Attributes.Add('name', Self.ItemName); 410 end; 411 end; 412 413 procedure THtmlInput.Assign(Source: THtmlElement); 414 begin 415 inherited Assign(Source); 416 InputType := THtmlInput(Source).InputType; 417 Value := THtmlInput(Source).Value; 418 ItemName := THtmlInput(Source).ItemName; 286 419 end; 287 420 … … 442 575 end; 443 576 577 procedure THtmlElement.Assign(Source: THtmlElement); 578 begin 579 Id := Source.Id; 580 Name := Source.Name; 581 ClassId := Source.ClassId; 582 Style := Source.Style; 583 end; 584 444 585 { TIpAddress } 445 586 … … 454 595 end else inherited; 455 596 end else inherited; 597 end; 598 599 function TIpAddress.IsAddressString(Value: string): Boolean; 600 var 601 Parts: TListString; 602 begin 603 Result := True; 604 try 605 Parts := TListString.Create; 606 Parts.Explode(Value, '.', StrToStr); 607 if Parts.Count = 4 then begin 608 if (StrToInt(Parts[3]) < 0) or (StrToInt(Parts[3]) > 255) then Result := False; 609 if (StrToInt(Parts[2]) < 0) or (StrToInt(Parts[2]) > 255) then Result := False; 610 if (StrToInt(Parts[1]) < 0) or (StrToInt(Parts[1]) > 255) then Result := False; 611 if (StrToInt(Parts[0]) < 0) or (StrToInt(Parts[0]) > 255) then Result := False; 612 end else Result := False; 613 finally 614 Parts.Free; 615 end; 456 616 end; 457 617 … … 571 731 572 732 function TDomainAddress.GetAsString: string; 573 var 574 I: Integer; 575 begin 576 Result := ''; 577 for I := High(Levels) downto 0 do Result := Result + '.' + Levels[I]; 578 Delete(Result, 1, 1); 733 begin 734 try 735 Levels.Reverse; 736 Result := Levels.Implode('.', StrToStr); 737 finally 738 Levels.Reverse; 739 end; 579 740 end; 580 741 581 742 procedure TDomainAddress.SetAsString(const Value: string); 582 var 583 StrArray: TListString; 584 I: Integer; 585 begin 586 try 587 StrArray := TListString.Create; 588 StrArray.Explode(Value, '.', StrToStr); 589 SetLength(Levels, StrArray.Count); 590 for I := 0 to StrArray.Count - 1 do 591 Levels[StrArray.Count - 1 - I] := StrArray[I]; 592 finally 593 StrArray.Free; 594 end; 743 begin 744 Levels.Explode(Value, '.', StrToStr); 745 Levels.Reverse; 746 end; 747 748 constructor TDomainAddress.Create; 749 begin 750 Levels := TListString.Create; 751 end; 752 753 destructor TDomainAddress.Destroy; 754 begin 755 Levels.Free; 756 inherited Destroy; 595 757 end; 596 758 … … 626 788 end; 627 789 790 procedure THtmlString.Assign(Source: THtmlElement); 791 begin 792 inherited Assign(Source); 793 Text := THtmlString(Source).Text; 794 end; 795 628 796 { THostAddress } 629 797 … … 653 821 procedure THostAddress.SetAsString(const Value: string); 654 822 begin 655 State := asIpAddress;656 try823 if IpAddress.IsAddressString(Value) then begin 824 State := asIpAddress; 657 825 IpAddress.AsString := Value; 658 e xcept659 on EConvertError doState := asDomainName;660 end;661 if State = asDomainName then DomainName.AsString := Value;826 end else begin 827 State := asDomainName; 828 DomainName.AsString := Value; 829 end; 662 830 end; 663 831
Note:
See TracChangeset
for help on using the changeset viewer.