Search results for 'Delphi Networking'. 7 post(s) found.

  1. 2007/09/18 Retrieving all image links from an HTML document
  2. 2007/09/18 List All Network Drives
  3. 2007/09/18 How to set the "home page" for the Internet Explorer from Delphi code
  4. 2007/09/18 How to get get IE favorites
  5. 2007/09/18 Extracting the domain (host) name from an e-mail address
  6. 2007/09/18 Download a file from the Internet with progress indicator
  7. 2007/09/18 Are we connected to the Internet?
2007/09/18 08:34

Retrieving all image links from an HTML document


Here's how to obtain all image links from an HTML document. The GetImageLinks procedure fills a TStrings object with the value of the SRC property of the IMG HTML element.
Note: if the images have relative links, you will have to parse the document url and prepend that to the image src.

Tip submitted by "mrbaseball34" (an About Delphi Programming member).

uses ... mshtml, ActiveX, COMObj, IdHTTP, idURI;

procedure GetImageLinks(AURL: String; AList: TStrings) ;
var
  IDoc : IHTMLDocument2;
  strHTML : String;
  v : Variant;
  x : integer;
  ovLinks : OleVariant;
  DocURL : String;
  URI : TidURI;
  ImgURL : String;
  IdHTTP : TidHTTP;
begin
  AList.Clear;
  URI := TidURI.Create(AURL) ;
  try
    DocURL := 'http://' + URI.Host;
    if URI.Path <> '/' then
      DocURL := DocURL + URI.Path;
  finally
    URI.Free;
  end;
  Idoc:=CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
  try
    IDoc.designMode:='on';
    while IDoc.readyState<>'complete' do
      Application.ProcessMessages;
    v:=VarArrayCreate([0,0],VarVariant) ;
    IdHTTP := TidHTTP.Create(nil) ;
    try
      strHTML := IdHTTP.Get(AURL) ;
    finally
      IdHTTP.Free;
    end;
    v[0]:= strHTML;
    IDoc.write(PSafeArray(System.TVarData(v).VArray)) ;
    IDoc.designMode:='off';
    while IDoc.readyState<>'complete' do
      Application.ProcessMessages;
    ovLinks := IDoc.all.tags('IMG') ;
    if ovLinks.Length > 0 then
    begin
      for x := 0 to ovLinks.Length-1 do
      begin
        ImgURL := ovLinks.Item(x).src;
        // The stuff below will probably need a little tweaking
        // Deteriming and turning realtive URLs into absolute URLs
        // is not that difficult but this is all I could come up with
        // in such a short notice.
        if (ImgURL[1] = '/') then
        begin
          // more than likely a relative URL so
          // append the DocURL
          ImgURL := DocURL + ImgUrl;
        end
        else
        begin
          if (Copy(ImgURL, 1, 11) = 'about:blank') then
          begin
            ImgURL := DocURL + Copy(ImgUrl, 12, Length(ImgURL)) ;
          end;
        end;
        AList.Add(ImgURL) ;
      end;
    end;
  finally
    IDoc := nil;
  end;
end;

//Usage
procedure TForm1.Button1Click(Sender: TObject) ;
begin
  GetImageLinks('http://kurapa.com', Memo1.Lines) ;
end;
Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/28 23:05 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 07:09 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:40 delete

    moneyideas

2007/09/18 08:31

List All Network Drives


To show a list of all mapped Network Drives, use the GetNetworkDriveMappings function. Example usage:

GetNetworkDriveMappings(Memo1.Lines) ;

function GetNetworkDriveMappings (SList: TStrings): integer;
var
  c: Char;
  ThePath: string;
  MaxNetPathLen: DWord;
begin
  SList.Clear;
  MaxNetPathLen := MAX_PATH;
  SetLength(ThePath, MAX_PATH) ;
  for c := 'A' to 'Z' do
    if WNetGetConnection(PChar('' + c + ':'), PChar(ThePath),MaxNetPathLen) = NO_ERROR then sList.Add(c + ': ' + ThePath) ;
  Result := SList.Count;
end;
Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 02:56 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 12:03 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:40 delete

    moneyideas

2007/09/18 08:29

How to set the "home page" for the Internet Explorer from Delphi code


Here's how to change the home page for the IE from Delphi code (IE-Tools-Internet options...)

uses Registry;
...
function SetIEHomePage(PageName: string): Boolean;
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_CURRENT_USER;
    OpenKey('Software\Microsoft\Internet Explorer\Main', False) ;
    try
      WriteString('Start Page', PageName) ;
      Result := True;
    except
      Result := False;
    end;
    CloseKey;
  finally
    Free;
  end;
end;
//Usage:
SetIEHomePage('http://kurapa.com')

Trackback 4 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject Tramadol drug concerns.

    Tracked from Tramadol. 2009/06/28 08:33 delete

    Tramadol hydrochloride. Cheapest tramadol. Tramadol withdraw. Tramadol side affects. Tramadol. Hydrocodone vs tramadol.

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/28 23:22 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 07:27 delete

    moneyideas

  4. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:40 delete

    moneyideas

2007/09/18 08:28

How to get get IE favorites


The GetIEFavourites function called from the OnClick event of a button returns a list of all the favorites from your Internet Explorer in a ListBox.

function GetIEFavourites
(const favpath: string):TStrings;
var
  searchrec:TSearchrec;
  str:TStrings;
  path,dir,filename:String;
  Buffer: array[0..2047] of Char;
  found:Integer;
begin
  str:=TStringList.Create;
  try
  path:=FavPath+'\*.url';
  dir:=ExtractFilePath(path) ;
  found:=FindFirst(path,faAnyFile,searchrec) ;
  while found=0 do begin
   SetString(filename, Buffer,
           GetPrivateProfileString('InternetShortcut',
           PChar('URL'), NIL, Buffer, SizeOf(Buffer),
           PChar(dir+searchrec.Name))) ;
   str.Add(filename) ;
   found:=FindNext(searchrec) ;
  end;
  found:=FindFirst(dir+'\*.*',faAnyFile,searchrec) ;
  while found=0 do begin
   if ((searchrec.Attr and faDirectory) > 0)
     and (searchrec.Name[1]<>'.') then
   str.AddStrings(GetIEFavourites
                (dir+'\'+searchrec.name)) ;
   found:=FindNext(searchrec) ;
  end;
  FindClose(searchrec) ;
  finally
  Result:=str;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject) ;
var pidl: PItemIDList;
    FavPath: array[0..MAX_PATH] of char;
begin
  SHGetSpecialFolderLocation(Handle, CSIDL_FAVORITES, pidl) ;
  SHGetPathFromIDList(pidl, favpath) ;
  ListBox1.Items:=GetIEFavourites(StrPas(FavPath)) ;
end;

Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 06:03 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 14:35 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:40 delete

    moneyideas

2007/09/18 08:26

Extracting the domain (host) name from an e-mail address


If you have an email as a string value and want to extract only the domain (host) name from it, like in: "delphi.guide@about.com" - domain name = "about.com", you can use the next function:

//extract doman name from an email address
function EmailDomain(const email: string):string;
var
  Pos_AT : integer;
begin
  Pos_AT := Pos('@', email) ;
  Result := Copy(email, Pos_AT + 1, Length(email) - Pos_AT)
end;

Trackback 6 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject Lexapro.

    Tracked from Lexapro and alcohol. 2009/02/08 18:29 delete

    Can you take lexapro while pregnant.

  2. Subject Viagra.

    Tracked from Viagra canada. 2009/02/11 22:31 delete

    Buy viagra.

  3. Subject Viagra.

    Tracked from Re viagra cello. 2009/03/01 14:04 delete

    Viagra. Generic viagra no prescription. Buy viagra.

  4. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 02:55 delete

    moneyideas

  5. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 11:51 delete

    moneyideas

  6. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:40 delete

    moneyideas

2007/09/18 08:24

Download a file from the Internet with progress indicator


If you need to save the contents of a specified URL to a file - and be able to track the download progress, use the TDownloadURL Delphi action
While TDownloadURL is writing to the specified file, it periodically generates an OnDownloadProgress event, so that you can provide users with feedback about the process.

Here's an example - note that you must include the unit ExtActns in the uses clause.

uses ExtActns, ...

type
  TfrMain = class(TForm)
  ...
  private
    procedure URL_OnDownloadProgress
       (Sender: TDownloadURL;
        Progress, ProgressMax: Cardinal;
        StatusCode: TURLDownloadStatus;
        StatusText: String; var Cancel: Boolean) ;
  ...

implementation
...

procedure TfrMain.URL_OnDownloadProgress;
begin
  ProgressBar1.Max:= ProgressMax;
  ProgressBar1.Position:= Progress;
end;

function DoDownload;
begin
  with TDownloadURL.Create(self) do
  try
    URL:='http://z.about.com/6/g/delphi/b/index.xml';
    FileName := 'c:\ADPHealines.xml';
    OnDownloadProgress := URL_OnDownloadProgress;

    ExecuteTarget(nil) ;
  finally
    Free;
  end;
end;

{
Note:
URL property points to Internet
FileName is the local file
}
Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 04:06 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 12:54 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:40 delete

    moneyideas

2007/09/18 08:23

Are we connected to the Internet?


Here's how to check whether you are connected to the Internet

procedure TForm1.Button1Click(Sender: TObject) ;

  function FuncAvail(_dllname, _funcname: string; var _p: pointer): boolean;
  {return True if _funcname exists in _dllname}
  var _lib: tHandle;
  begin
  Result := false;
  if LoadLibrary(PChar(_dllname)) = 0 then exit;
  _lib := GetModuleHandle(PChar(_dllname)) ;
  if _lib <> 0 then begin
   _p := GetProcAddress(_lib, PChar(_funcname)) ;
   if _p <> NIL then Result := true;
  end;
  end;

  {
  Call SHELL32.DLL for Win < Win98
  otherwise call URL.DLL
  }
  {button code:}
  var
  InetIsOffline : function(dwFlags: DWORD):
                  BOOL; stdcall;
  begin
  if FuncAvail('URL.DLL', 'InetIsOffline',
               @InetIsOffline) then
   if InetIsOffline(0) = true
    then ShowMessage('Not connected')
    else ShowMessage('Connected!') ;
  end;

Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 02:08 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 10:14 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:40 delete

    moneyideas