Changeset 19 for IPAddress/UIPAddress.pas
- Timestamp:
- May 14, 2010, 6:59:30 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
IPAddress/UIPAddress.pas
r17 r19 1 1 unit UIPAddress; 2 3 // Date: 2010-05-14 2 4 3 5 {$mode objfpc}{$H+} … … 19 21 procedure SetString(Value: string); 20 22 constructor Create; 23 procedure Assign(Source: TObject); 21 24 property AsString: string read GetString write SetString; 22 25 end; … … 41 44 var 42 45 Part: string; 46 Octet: Integer; 47 TempValue: Integer; 43 48 begin 44 49 if Pos('/', Value) > 0 then begin 45 Prefix := StrToInt(Copy(Value, Pos('/', Value) + 1, Length(Value))); 50 if TryStrToInt(Copy(Value, Pos('/', Value) + 1, Length(Value)), TempValue) then 51 Prefix := TempValue else Prefix := 32; 46 52 Delete(Value, Pos('/', Value), Length(Value)); 47 53 end else Prefix := 32; 48 Part := Copy(Value, 1, Pos('.', Value) - 1); 49 Delete(Value, 1, Pos('.', Value)); 50 Address := Cardinal(StrToInt(Part) and $ff) shl 24; 51 Part := Copy(Value, 1, Pos('.', Value) - 1); 52 Delete(Value, 1, Pos('.', Value)); 53 Address := Address or Cardinal((StrToInt(Part) and $ff) shl 16); 54 Part := Copy(Value, 1, Pos('.', Value) - 1); 55 Delete(Value, 1, Pos('.', Value)); 56 Address := Address or Cardinal((StrToInt(Part) and $ff) shl 8); 57 Address := Address or Cardinal((StrToInt(Value) and $ff) shl 0); 54 if Pos('.', Value) > 0 then begin 55 Part := Copy(Value, 1, Pos('.', Value) - 1); 56 Delete(Value, 1, Pos('.', Value)); 57 if TryStrToInt(Part, TempValue) then Octet := TempValue 58 else Octet := 0; 59 Address := Address or Cardinal((Octet and $ff) shl 24); 60 end; 61 if Pos('.', Value) > 0 then begin 62 Part := Copy(Value, 1, Pos('.', Value) - 1); 63 Delete(Value, 1, Pos('.', Value)); 64 if TryStrToInt(Part, TempValue) then Octet := TempValue 65 else Octet := 0; 66 Address := Address or Cardinal((Octet and $ff) shl 16); 67 end; 68 if Pos('.', Value) > 0 then begin 69 Part := Copy(Value, 1, Pos('.', Value) - 1); 70 Delete(Value, 1, Pos('.', Value)); 71 if TryStrToInt(Part, TempValue) then Octet := TempValue 72 else Octet := 0; 73 Address := Address or Cardinal((Octet and $ff) shl 8); 74 end; 75 if TryStrToInt(Value, TempValue) then Octet := TempValue 76 else Octet := 0; 77 Address := Address or Cardinal((Octet and $ff) shl 0); 58 78 end; 59 79 … … 64 84 end; 65 85 86 procedure TIPAddress.Assign(Source: TObject); 87 begin 88 if Source is TIPAddress then begin 89 Address := TIPAddress(Source).Address; 90 Prefix := TIPAddress(Source).Prefix; 91 end; 92 end; 93 66 94 end. 67 95
Note:
See TracChangeset
for help on using the changeset viewer.