Extract URL Parts << Back



The Windows API InternetCrackUrl allows you to extract different part of an URL. It all stemmed from the post here. You have to put some elbow grease in if you want it to work with DF20+.

Use UI
Use DLL.pkg
Use GlobalFunctionsProcedures.pkg

#IF !@>191
	#ERROR DFERR_COMP_OBSOLETE_UNSUPPORTED_FEATURE The code is not compatible with DataFlex 20.0 or above
#ENDIF

Struct URL_COMPONENTS
	UInteger			dwStructSize
	Pointer 			lpszScheme
	UInteger			dwSchemeLength
	UInteger			nScheme
	Pointer 			lpszHostName
	UInteger			dwHostNameLength
	UShort				nPort
	UShort				uMissingAlignment1
	Pointer 			lpszUserName
	UInteger			dwUserNameLength
	Pointer 			lpszPassword
	UInteger			dwPasswordLength
	Pointer 			lpszUrlPath
	UInteger			dwUrlPathLength
	Pointer 			lpszExtraInfo
	UInteger			dwExtraInfoLength
End_Struct

External_Function InternetCrackUrl "InternetCrackUrlA" WININET.DLL String lpszURL UInteger dwUrlLength UInteger dwFlags Pointer lpUrlComponents Returns Integer

Enum_List
	Define CRACKURL_SCHEME
	Define CRACKURL_HOST
	Define CRACKURL_PATH
	Define CRACKURL_QUERY
End_Enum_List

Function CrackUrl Global String sURL Integer iFlag Returns String
	URL_COMPONENTS c
	String sResult sExtra
	Integer iResult
	ZeroString 8192 to sResult
	Move (ToANSI(sURL)) to sURL
	Move (SizeOfType(URL_COMPONENTS)) to c.dwStructSize
	If (iFlag = CRACKURL_SCHEME) Begin
		Move (AddressOf(sResult)) to c.lpszScheme
		Move 8192 to c.dwSchemeLength
	End
	Else If (iFlag = CRACKURL_HOST) Begin
		Move (AddressOf(sResult)) to c.lpszHostName
		Move 8192 to c.dwHostNameLength
	End
	Else If (iFlag = CRACKURL_PATH) Begin
		Move (AddressOf(sResult)) to c.lpszUrlPath
		Move 8192 to c.dwUrlPathLength
		ZeroString 1024 to sExtra
		Move (AddressOf(sExtra)) to c.lpszExtraInfo
		Move 1024 to c.dwExtraInfoLength
	End
	Else If (iFlag = CRACKURL_QUERY) Begin
		Move (AddressOf(sResult)) to c.lpszExtraInfo
		Move 8192 to c.dwExtraInfoLength
	End
	Move (InternetCrackUrl(sURL, Length(sURL), 0, AddressOf(c))) to iResult
	If (iResult) Function_Return (CString(ToOEM(sResult)))
	Function_Return ""
End_Function

// ============= This is for testing purpose =================
// Define TESTURL For "https://support.dataaccess.com/Forums/newthread.php?do=newthread&f=6"
// Showln (CrackUrl(TESTURL, CRACKURL_SCHEME))  // https                 
// Showln (CrackUrl(TESTURL, CRACKURL_HOST))    // support.dataaccess.com
// Showln (CrackUrl(TESTURL, CRACKURL_PATH))    // /Forums/newthread.php 
// Showln (CrackUrl(TESTURL, CRACKURL_QUERY))   // ?do=newthread&f=6     
// InKey FieldIndex                                                   





Free Web Hosting