Thema: Delphi Autocomplete (Combobox)

Einzelnen Beitrag anzeigen

hathor
(Gast)

n/a Beiträge
 
#5

AW: Autocomplete (Combobox)

  Alt 25. Nov 2014, 08:56
Im Anhang Source + EXE.
Hier ist der vollständige Sourcecode:

Delphi-Quellcode:
program AutoComplete_Example;

uses
  Forms,
  Main in 'Main.pas{MainForm},
  UAutoComplete in 'UAutoComplete.pas';

{$R *.res}
{$R WindowsXP.res}

begin
  Application.Initialize;
  Application.Title := 'Example AutoComplete';
  Application.CreateForm(TMainForm, MainForm);
  Application.Run;
end.
//------------------------------------------------
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UAutoComplete, StdCtrls, ExtCtrls;

type
  TMainForm = class(TForm)
    InfoLbl: TLabel;
    EditControl: TEdit;
    OptionsBox: TGroupBox;
    FileBox: TCheckBox;
    HistoryBox: TCheckBox;
    RecentBox: TCheckBox;
    QuitBtn: TButton;
    SepBevel: TBevel;
    AppendBox: TCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure QuitBtnClick(Sender: TObject);
    procedure OptionChange(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  MainForm: TMainForm;
  Params: TCompleteParams;

implementation

{$R *.dfm}

procedure TMainForm.FormCreate(Sender: TObject);
begin
 DoubleBuffered := True;
 OptionsBox.DoubleBuffered := True;
 with Params do
  begin
   Options := [coeFileSystem,coeURLHistory,coeRecent];
   Append := True;
  end;
 if not AutoComplete(EditControl.Handle, Params) then raise
 Exception.Create('ERROR: Definition Auto-Complete');
end;

procedure TMainForm.QuitBtnClick(Sender: TObject);
begin
 Close;
end;

function ElementFromTag(Value: Integer): TCompleteOptionsElements;
begin
 case Value of
  1: Result := coeFileSystem;
  2: Result := coeURLHistory;
  3: Result := coeRecent;
  else Result := coeFileSystem;
 end;
end;

procedure TMainForm.OptionChange(Sender: TObject);
begin
 if Sender is TCheckBox then
  with TCheckBox(Sender), Params do
   begin
    if (Tag in [1..3]) then if Checked then
    Include(Options, ElementFromTag(Tag)) else Exclude(Options, ElementFromTag(Tag));
    if Tag = 4 then Append := Checked;
    if not AutoComplete(EditControl.Handle, Params) then raise
    Exception.Create('ERROR: Definition Auto-Complete');
   end;
end;

end.
//------------------------------------------------------
unit UAutoComplete;

interface

uses ComObj;

type
 Longword = Cardinal;

 TCompleteOptionsElements = (coeFileSystem, coeURLHistory, coeRecent);
 TCompleteOptions = set of TCompleteOptionsElements;

 TCompleteParams = record
  Options: TCompleteOptions;
  Append: Boolean;
 end;

function AutoComplete(Handle: Longword; Params: TCompleteParams): Boolean;

implementation

function SHAutoComplete(hwndEdit, dwFlags: Longword): Longword; stdcall; external 'shlwapi.dll';

const
 SHACF_AUTOAPPEND_FORCE_OFF = $80000000;
 SHACF_AUTOAPPEND_FORCE_ON = $40000000;
 SHACF_FILESYSTEM = $00000001;
 SHACF_URLHISTORY = $00000002;
 SHACF_URLMRU = $00000004;
 SHACF_NOAUTOCOMPLETE = $00000008;

 AppendConsts: array [Boolean] of Longword = (SHACF_AUTOAPPEND_FORCE_OFF, SHACF_AUTOAPPEND_FORCE_ON);

function CompleteOptionsToFlags(Value: TCompleteOptions): Longword;
begin
 if Value = [] then Result := SHACF_NOAUTOCOMPLETE else
  begin
   Result := 0;
   if coeFileSystem in Value then Result := Result or SHACF_FILESYSTEM;
   if coeURLHistory in Value then Result := Result or SHACF_URLHISTORY;
   if coeRecent in Value then Result := Result or SHACF_URLMRU;
  end;
end;

function AutoComplete(Handle: Longword; Params: TCompleteParams): Boolean;
begin
 with Params do Result := (SHAutoComplete(Handle, CompleteOptionsToFlags(Options) or AppendConsts[Append]) = 0);
end;

end.
Angehängte Dateien
Dateityp: zip AUTOCOMPLETE-1.zip (556,7 KB, 62x aufgerufen)

Geändert von hathor (25. Nov 2014 um 18:16 Uhr)
  Mit Zitat antworten Zitat