Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Link to a url? 1

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
I would like to ass an option under my help menu to say "Visit my web site". How do i code the button to redirect to an url?
Also, i would like to add a button to see if there's a new version available. I was thinking about putting a file on my web site that would have the latest version. The code would read this text file and compare it to the current version. If it is different, a message would say to visit the web site for a new update.
Is there another way to do a thing like that?
Thanks.
PO
 
The first question:
Code:
begin
  ShellExecute(Handle,'open',PCHAR('[URL unfurl="true"]http://www.mysite.com'),[/URL] PChar(''), PChar(''), SW_SHOWNORMAL);
end;

of course Uses ShellApi

Steven
 
Question 2:
You could use this function:

Code:
function GetInetFile 
(const fileURL, FileName: String): boolean; 
const BufferSize = 1024; 
var 
  hSession, hURL: HInternet; 
  Buffer: array[1..BufferSize] of Byte; 
  BufferLen: DWORD; 
  f: File; 
  sAppName: string; 
begin 
Result:=False; 
sAppName := ExtractFileName(Application.ExeName); 
hSession := InternetOpen(PChar(sAppName), 
                INTERNET_OPEN_TYPE_PRECONFIG, 
               nil, nil, 0); 
try 
  hURL := InternetOpenURL(hSession, 
            PChar(fileURL), 
            nil,0,0,0); 
  try 
   AssignFile(f, FileName); 
   Rewrite(f,1); 
   repeat 
    InternetReadFile(hURL, @Buffer, 
                     SizeOf(Buffer), BufferLen); 
    BlockWrite(f, Buffer, BufferLen) 
   until BufferLen = 0; 
   CloseFile(f); 
   Result:=True; 
  finally 
   InternetCloseHandle(hURL) 
  end 
finally 
  InternetCloseHandle(hSession) 
end 
end;

then make a button:
Code:
procedure TForm1.button1Click(Sender: TObject); 
var  InternetFile,LocalFile,T,V: string;
F: TextFile; 
begin
V:= '1.0.1'; //Current version 
InternetFile:=' [URL unfurl="true"]http://www.domain.com/version.txt;[/URL] 
LocalFile:='c:\temp\version.txt';
AssignFile(f, 'c:\temp\version.txt.txt');
Reset(f);
while not EOF(f) do begin
readln(f, S);

if V=S then 
   ShowMessage('Software up to date') 
else 
  ShowMessage('Download new version!'); 
end;

Something like that.
I don't have delphi here so I just wrote it by hand, without testing.
You could just tweak it some if it doesn't work as it should.
 
Forgot to mention.
Add
Code:
if V=S then 
   ShowMessage('Software up to date') 
   CloseFile(f);
   DeleteFile(f);
else 
  ShowMessage('Download new version!'); //Add your own downloadable thingie, You can use the GetInetFile function for this too.
  CloseFile(f);
  DeleteFile(f);
end;
 
Ugh, post #3 from me... Ignore the other code I posted, it does not work as it should.

Here's the typoless and working version.



Code:
Uses
WinInet,...;

function GetInetFile
(const fileURL, FileName: String): boolean;
const BufferSize = 1024;
var
  hSession, hURL: HInternet;
  Buffer: array[1..BufferSize] of Byte;
  BufferLen: DWORD;
  f: File;
  sAppName: string;
begin
Result:=False;
sAppName := ExtractFileName(Application.ExeName);
hSession := InternetOpen(PChar(sAppName),
                INTERNET_OPEN_TYPE_PRECONFIG,
               nil, nil, 0);
try
  hURL := InternetOpenURL(hSession,
            PChar(fileURL),
            nil,0,0,0);
  try
   AssignFile(f, FileName);
   Rewrite(f,1);
   repeat
    InternetReadFile(hURL, @Buffer,
                     SizeOf(Buffer), BufferLen);
    BlockWrite(f, Buffer, BufferLen)
   until BufferLen = 0;
   CloseFile(f);
   Result:=True;
  finally
   InternetCloseHandle(hURL)
  end
finally
  InternetCloseHandle(hSession)
end
end;

procedure TForm1.Button1Click(Sender: TObject);
var
InternetFile,LocalFile,T,V: string;
F: TextFile;
begin
V:= '1.0.1'; //Current version (compares to value in v.html)
InternetFile:='[URL unfurl="true"]http://ante0.site90.com/new/v.html';[/URL]
LocalFile:='c:\v.html';
try
AssignFile(f, 'c:\v.html');
Reset(f);
readln(f, T);
if V=T then
   ShowMessage('Software up to date')
else
  ShowMessage('Download new version!');

Finally
CloseFile(f);
end;
end;
 
Thanks let me try it tomorrow. I am still using delphi 7 so I hope it's going to work.
Sincerely,
 
Same here, Delphi 7 :p
Delphit 6/7 = best versions in my opinion. hehe
I just don't like the new layout of the newer versions, takes too long to find components :(
Well, let me know how it goes.
You could also add "download file if it's not up to date" after ShowMessage('Download new version!');.
It shouldn't be too tough to add :p
Just make a new InternetFile := that points to your update and LocalFile, then Shellexecute it to install. Or just point it to a Download page on your website.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top