Modifying Delphi internet code

Please discuss general Delphi programming topics here.

Modifying Delphi internet code

Postby Bridger » June 10th, 2014, 10:50 am

Hello All,

I've been using Delphi for my programs for a while now and I'm comfortable with the stuff I know but have never tried any internet things so the code is not intuitive to me.
I came across this code which I would like to include in my program.
What I would like is to be able to get the Website the user visits and store it in say a list e.g. listbox1.items[0] might show as Anysite.com
And also get the file the User downloads
e.g. listbox2.items[0] might display as Anyzip.zip

Can anyone show me how to modify the following code to achieve this?

Thanks

Mike

implementation

{$R *.DFM}
const
NotAllowed: set of Char = ['"'] + ['/'] + ['\'] + ['?'] + [':'] + ['*'] +
['<'] + ['>'] + ['|'];

function Load(Path, Key: string): string;
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey(Path, False);
try
Result := Reg.ReadString(Key);
except
Result := '';
end;
Reg.CloseKey;
finally
Reg.Free;
end;
end;

function WinDir: string;
var
WinDir: PChar;
begin
WinDir := StrAlloc(MAX_PATH);
GetWindowsDirectory(WinDir, MAX_PATH);
Result := string(WinDir);
if Result[Length(Result)] <> '\' then
Result := Result + '\';
StrDispose(WinDir);
end;

function GetSysDir: string;
var
dir: array [0..MAX_PATH] of Char;
begin
GetSystemDirectory(dir, MAX_PATH);
Result := StrPas(dir);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Webbrowser1.Navigate(edit1.Text);
end;



procedure TForm1.Button2Click(Sender: TObject);
var
url: TStringList;
fav: string;
title, b: string;
i: Integer;
c: Char;

begin
fav := Load('Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Favorites');
url := TStringList.Create;
try
url.Add('[InternetShortcut]');
url.Add('URL=' + webbrowser1.LocationURL);
url.Add('WorkingDirectory=' + WinDir());
url.Add('IconIndex=0');
url.Add('ShowCommand=7');
url.Add('IconFile=' + GetSysDir() + '\url.dll');
title := Webbrowser1.LocationName;
b := '';
for i := 1 to Length(title) do
begin
c := title[i];
if not (c in NotAllowed) then
begin
b := b + Webbrowser1.LocationName[i];
end;
end;
url.SaveToFile(fav + '\' + b + '.url');

finally
url.Free;
end;
end;
Bridger
Member
Member
 
Posts: 4
Joined: June 10th, 2014, 10:46 am

Re: Modifying Delphi internet code

Postby dec » June 13th, 2014, 7:36 pm

Hello,

The code you shown it's not very clear. Probably a try to get the URL the user visit in a WebBrowser control. If you want to use such WebBrowser control, probably you only need to take care of certain events that probably allows you to take the URL the user wanted for. If, on the contrary, what you want is to get the URL the user visit in some browser (Internet Explorer, Firefox, Opera, etc., etc., etc.) probably you can search for some code to do that, but, I think we have not an standard way and therefore all the code are based in more or less complicated tricks, which can fail in certain browsers, browsers versions, etc.
dec
Senior Member
Senior Member
 
Posts: 56
Joined: July 17th, 2011, 12:33 am

Re: Modifying Delphi internet code

Postby Bridger » June 15th, 2014, 12:28 pm

Thanks Dec,

The reason I asked this question is because I'd written a program to allow Users to keep a record of Files that they had downloaded and from which site.
I tried to automate this program as much as I could but the downloaded file name had to be entered manually by the User as well as the sites address.

I hoped that the code that I uploaded in my previous post could be modified to achieve what I wanted but even with my limited knowledge I thought it might prove difficult.
Thanks again for your input.

Bridger
Bridger
Member
Member
 
Posts: 4
Joined: June 10th, 2014, 10:46 am

Re: Modifying Delphi internet code

Postby dec » June 16th, 2014, 12:29 pm

Hello,

Certainly what you need is not easy, at least to me. Honestly I can't help you this time. Probably you need to investigate how to hook into certain low level Windows API's in order to get informed about something like that. Something like if you want to do your own Firewall or something like that. Maybe you can do a search around this on Google and found some kind of information you can use. Sorry.
dec
Senior Member
Senior Member
 
Posts: 56
Joined: July 17th, 2011, 12:33 am

Re: Modifying Delphi internet code

Postby Bridger » June 16th, 2014, 3:02 pm

Dec,
I've just been re-reading your first post and what I would like to make clear is that I don't want to try and monitor the User when they are browsing with Chrome or Firefox or whatever. They would use WebBrowser in my program- What I would like is to be able to get the name of the File that they are downloading and from which site they are downloading it from.
Something like Anyfile.zip from Anysite.com

I'm using Delphi 5 and it reports that no help is available for this component.
I have been trying to find some code on the Internet. That's how I came across the code that I posted but I haven't found anything more promising yet.
Thanks again, I appreciate your taking an interest.

Bridger
Bridger
Member
Member
 
Posts: 4
Joined: June 10th, 2014, 10:46 am

Re: Modifying Delphi internet code

Postby arhangelsoft » June 24th, 2014, 7:28 pm

Query DWebBrowserEvents interface from IWebBrowser2 Interface, and use it event to handle whatever you need.
arhangelsoft
Junior Member
Junior Member
 
Posts: 39
Joined: February 16th, 2012, 9:56 pm
Location: Belarus, Minsk

Re: Modifying Delphi internet code

Postby Bridger » June 26th, 2014, 8:46 am

Thanks arhangelsoft,
I'll take a look .
My immediate observation would be that when a user chooses to download a file from a site a Windows dialog box appears asking them if they wan't to open or save the file. I still can't see how I can get the filename from that dialog.

Bridger
Bridger
Member
Member
 
Posts: 4
Joined: June 10th, 2014, 10:46 am


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron