Mega Code Archive

 
Categories / Delphi / Examples
 

Enable autocomplete feature

Title: Enable autocomplete feature. Question: How do I add the autocomplete feature I've seen in IE text fields? Answer: There is a little known function called SHAutoComplete that resides in the shwlapi.dll. Calling this function with the handle of an edit field and the appropriate flags enables the IE autocomplete feature. One important thing to keep in mind is that this function works only after you call the ole-related CoInitialize (or CoInitializeEx) function. This task is accomplished by the initialization section of the ComObj unit. Here is a sample unit that shows how to use such feature: unit AutoCompleteUnit; interface uses Windows, StdCtrls, ComObj; Const SHACF_DEFAULT = $0; SHACF_FILESYSTEM = $1; SHACF_URLHISTORY = $2; SHACF_URLMRU = $4; SHACF_URLALL = (SHACF_URLHISTORY Or SHACF_URLMRU); SHACF_AUTOSUGGEST_FORCE_ON = $10000000; SHACF_AUTOSUGGEST_FORCE_OFF = $20000000; SHACF_AUTOAPPEND_FORCE_ON = $40000000; SHACF_AUTOAPPEND_FORCE_OFF = $80000000; function AutoComplete(editField: TEdit; dwFlags: DWORD): Boolean; implementation function SHAutoComplete(hwndEdit: HWND; dwFlags: dWord): LongInt; stdcall; external 'shlwapi.dll'; function AutoComplete(editField: TEdit; dwFlags: DWORD): Boolean; begin Result := (SHAutoComplete(editField.Handle, dwFlags) = 0); end; end.