destructor TEnumString.Destroy; begin FStrings.Free; inherited; end;
function TEnumString.Next(celt: Integer; out elt; pceltFetched: PLongint): HResult; var I: Integer; wStr: WideString; begin I := 0; while (I < celt) and (FCurrIndex < FStrings.Count) do begin wStr := FStrings[FCurrIndex]; TPointerList(elt)[I] := CoTaskMemAlloc(2 * (Length(wStr) + 1)); StringToWideChar(wStr, TPointerList(elt)[I], 2 * (Length(wStr) + 1)); Inc(I); Inc(FCurrIndex); end; if pceltFetched <> nilthen pceltFetched^ := I; if I = celt then Result := S_OK else Result := S_FALSE; end;
function TEnumString.Reset: HResult; begin FCurrIndex := 0; Result := S_OK; end;
function TEnumString.Skip(celt: Integer): HResult; begin if (FCurrIndex + celt) <= FStrings.Count then begin Inc(FCurrIndex, celt); Result := S_OK; end else begin FCurrIndex := FStrings.Count; Result := S_FALSE; end; end;
procedure TACEdit.CreateWnd; var Dummy: IUnknown; Strings: IEnumString; begin inherited; if HandleAllocated then begin try Dummy := CreateComObject(CLSID_IAutoComplete); if (Dummy <> nil) and (Dummy.QueryInterface(IID_IAutoComplete, FAutoComplete) = S_OK) then begin case FACSource of acsHistory: Strings := CreateComObject(CLSID_ACLHistory) as IEnumString; acsMRU: Strings := CreateComObject(CLSID_ACLMRU) as IEnumString; acsShell: Strings := CreateComObject(CLSID_ACListISF) as IEnumString; else Strings := FACList as IEnumString; end; if S_OK = FAutoComplete.Init(Handle, Strings, nil, nil) then begin SetACEnabled(FACEnabled); SetACOptions(FACOptions); end; end; except {CLSID_IAutoComplete is not available} end; end; end;
destructor TACEdit.Destroy; begin FACList := nil; inherited; end;
procedure TACEdit.DestroyWnd; begin if (FAutoComplete <> nil) then begin FAutoComplete.Enable(false); FAutoComplete := nil; end; inherited; end;
function TACEdit.GetACStrings: TStringList; begin Result := FACList.FStrings; end;
procedure TACEdit.SetACEnabled(const Value: boolean); begin if (FAutoComplete <> nil) then begin FAutoComplete.Enable(FACEnabled); end; FACEnabled := Value; end;
procedure TACEdit.SetACOptions(const Value: TACOptions); const Options: array[TACOption] of integer = (ACO_AUTOAPPEND, ACO_AUTOSUGGEST, ACO_UPDOWNKEYDROPSLIST); var Option: TACOption; Opt: DWORD; AC2: IAutoComplete2; begin if (FAutoComplete <> nil) then begin if S_OK = FAutoComplete.QueryInterface(IID_IAutoComplete2, AC2) then begin Opt := ACO_NONE; for Option := Low(Options) to High(Options) do begin if (Option in FACOptions) then Opt := Opt or DWORD(Options[Option]); end; AC2.SetOptions(Opt); end; end; FACOptions := Value; end;
procedure TACEdit.SetACSource(const Value: TACSource); begin if FACSource <> Value then begin FACSource := Value; RecreateWnd; end; end;
initialization finalization end. Взято с Delphi Knowledge Base http://www.baltsoft.com/