internet programming in Delphi or VB

Status
Not open for further replies.

wich

Wise, Aged Ars Veteran
160
Hi,

I'm looking for some example code (either Delpi 6 or VB6) to copy a webpage into a string array.

some pseudo code:

htmlpage=gethtml("http://www.somesite.com/index.html")

where htmlpage is a string array.

I checked various sites with samples, but found no simple solution for this problem.

I use Delphi 6 Enterprise and Visual Basic 6 Enterprise edition.

Although I programmed quite a lot in both Delphi and VB, I never made an 'web' application before.

Any help welcome.
 

russ-iha

Ars Praefectus
4,407
Subscriptor
code:<HR>
Code:
    hOpen = InternetOpen(scUserAgent, AccessType, Proxy, vbNullString, 0)
    
        hOpenUrl = InternetOpenUrl(hOpen, sUrl, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
    End If
    
    'this loop reads in the file that we downloaded, and places it into our string buffer.
    'this would be inefficient for files over 1 or 2 mb, but that isn't an issue at this time.
    'one could change it so that the buffer is immediately written out to disk after every read
    'which would negate the need for the large string buffer
    bDoLoop = True
    While bDoLoop
        sReadBuffer = vbNullString
        bRet = InternetReadFile(hOpenUrl, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
        sBuffer = sBuffer & Left$(sReadBuffer, lNumberOfBytesRead)
        If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
    Wend
      
    DoEvents
    
    'we MUST close the handles, or we'll leak resources!
    If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl)
    If hOpen <> 0 Then InternetCloseHandle (hOpen)
    
    
    
    'if we get here and there's more than a few CRLFs in the buffer, let's write the file.
    If Len(sBuffer) > 5 Then
        Kill sDest
        hFile = FreeFile()
        Open sDest For Binary Access Write As #hFile
            Put #hFile, , sBuffer
        Close #hFile
        GetFile = True
    End If


Here is a bit of basic code. If you want the full deal, go here and download WeatherDownloader -- it has full file download code. It also supports authenticated and non-auth'd proxy connections. You will find all the constants, API decls, and other stuff that you need there.
 

nottestuser

Ars Scholae Palatinae
1,049
Delphi has a suite of components in the VCL for doing just that. Their name escapes me at the moment but there's a http control right on the component pallet that you can drop on your form, set some basic properties (URL, authentication, etc.) and call the Open method. It's about 6 lines of code assuming you don't set the properties at design time.
 

Paul

Seniorius Lurkius
15
Can't really help with VB stuff since its been ages since I've done any. However, I could probably help with Delphi.

I'm not entirely sure what you're after doing, whether you want to write a website in Delphi (use CGIExpert www.cgiexpert.com) or a webbrowser type app, which I'd recommend Internet Professional from TurboPower (www.turbopower.com). Whatever you do, don't use the components that come with Delphi since they're not up to much.

The indy components are also meant to be good, but I've no personal experience with them.

russ-iha, adding components to your project only increases the size of your executable. No external dependencies. None required, anyway.

I think russ-iha was talking about the VB code he'd posted, some VB apps do need the external DLL's etc, but not the one suggested there. Now if it was Delphi it wouldn't, just like you said :)
 
Status
Not open for further replies.