1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56:
| uses ClipBrd;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); var InetIP: string; WebAddress, SearchString: string; Buff, P, FT: PChar; BuffLen: Word; StartPos, StringLength, TempInt: Integer; begin WebAddress := 'http://www.whatismyip.com/'; SearchString := 'Your ip is '; Memo1.Clear; try NMHTTP1.Get(WebAddress); except on E: Exception do begin MessageDlg('Could not get IP Address! ' + 'Please ensure you are connected to ' + 'the Internet.', mtError, [mbOK], 0); end; end; Memo1.Text := NMHTTP1.Body; Memo1.SelStart := 0; GetMem(FT, Length(SearchString) + 1); StrPCopy(FT, SearchString); BuffLen := Memo1.GetTextLen + 1; GetMem(Buff, BuffLen); Memo1.GetTextBuf(Buff, BuffLen); P := Buff + Memo1.SelStart + Memo1.SelLength; P := StrPos(P, FT); if P = nil then MessageBeep(0) else begin Memo1.SelStart := P - Buff; Memo1.SelLength := Length(SearchString); end; StringLength := Memo1.SelLength; StartPos := Memo1.SelStart + StringLength; tempint := StartPos; InetIP := ''; while ((Buff[TempInt] in ['0'..'9']) or (Buff[TempInt] = '.')) do begin InetIP := InetIP + Buff[TempInt]; tempint := tempint + 1; end; FreeMem(FT, Length(SearchString) + 1); FreeMem(Buff, BuffLen); Edit1.Text := InetIP; end;
end. |