Changeset 68 for trunk/Components/CoolWeb/Common/UHtmlClasses.pas
- Timestamp:
- Dec 26, 2011, 12:07:37 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Components/CoolWeb/Common/UHtmlClasses.pas
r67 r68 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; … … 589 597 end; 590 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; 616 end; 617 591 618 function TIpAddress.GetAddrClass: TAddrClass; 592 619 begin … … 704 731 705 732 function TDomainAddress.GetAsString: string; 706 var 707 I: Integer; 708 begin 709 Result := ''; 710 for I := High(Levels) downto 0 do Result := Result + '.' + Levels[I]; 711 Delete(Result, 1, 1); 733 begin 734 try 735 Levels.Reverse; 736 Result := Levels.Implode('.', StrToStr); 737 finally 738 Levels.Reverse; 739 end; 712 740 end; 713 741 714 742 procedure TDomainAddress.SetAsString(const Value: string); 715 var 716 StrArray: TListString; 717 I: Integer; 718 begin 719 try 720 StrArray := TListString.Create; 721 StrArray.Explode(Value, '.', StrToStr); 722 SetLength(Levels, StrArray.Count); 723 for I := 0 to StrArray.Count - 1 do 724 Levels[StrArray.Count - 1 - I] := StrArray[I]; 725 finally 726 StrArray.Free; 727 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; 728 757 end; 729 758 … … 792 821 procedure THostAddress.SetAsString(const Value: string); 793 822 begin 794 State := asIpAddress;795 try823 if IpAddress.IsAddressString(Value) then begin 824 State := asIpAddress; 796 825 IpAddress.AsString := Value; 797 e xcept798 on EConvertError doState := asDomainName;799 end;800 if State = asDomainName then DomainName.AsString := Value;826 end else begin 827 State := asDomainName; 828 DomainName.AsString := Value; 829 end; 801 830 end; 802 831
Note:
See TracChangeset
for help on using the changeset viewer.