TInternet
Source: source/classes/internet.prg
Inherits from: none (base class)
TInternet is the base class for WinInet-based internet access in FWH. It manages a global WinInet session handle and provides a factory method for creating TFTP connections. The class uses a reference-counted singleton pattern for the WinINet session handle.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
hWinINet | Handle | (Class data) Handle to the opened WinINet.dll |
hSession | Handle | (Class data) Handle of the current WinINet session (InternetOpen) |
nCount | Numeric | (Class data) Reference count of active TInternet objects |
aFTPs | Array | (Class data) Array of all TFTP objects currently in use |
Methods
| Method | Description |
|---|---|
New() | Create a new TInternet object; increments the session reference count and opens the WinINet session on first use |
End() | Release the internet object; decrements the reference count and closes the WinINet session when the count reaches zero |
FTP( cFTPSite, cUserName, cPassword ) | Create and return a new TFTP object connected to the specified FTP site |
Example: FTP File Upload via WinInet
#include "FiveWin.ch"
function Main()
local oInet := TInternet():New()
local oFtp := oInet:FTP( "ftp.example.com", "user", "pass" )
if oFtp:hFTP != nil
oFtp:SetCurrentDirectory( "/uploads" )
FtpPutFile( oFtp:hFTP, "c:\data\report.txt", "report.txt" )
MsgInfo( "File uploaded successfully" )
else
MsgAlert( "FTP connection failed" )
endif
oFtp:End()
oInet:End()
return nil
Notes
- TInternet uses a class-data singleton pattern: the
hSessionhandle is shared across all TInternet instances. The session is opened on the firstNew()and closed on the lastEnd(). - The
FTP()method creates aTFTPobject (defined intftp.prg) which usesInternetConnectwithINTERNET_SERVICE_FTPon port 21. - All active TFTP connections are tracked in
aFTPsand properly closed when the TInternet reference count reaches zero. - Direct WinINet API calls (
InternetOpen,InternetConnect,InternetCloseHandle,FtpPutFile, etc.) are available for advanced usage beyond the wrapper methods.