Thanks Mark (and James)

the CB_FINDSTRING message does the trick

Steve

> -----Original Message-----
> From: Mark Howard [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, 24 May 2001 10:44
> To: Multiple recipients of list delphi
> Subject: Re: [DUG]: TComboBox keys
> 
> 
> Stephen
> 
> This is what I use, based on some useful code from someone else in the
> group.
> There may me more elegant solutions around.
> 
> procedure TMainForm.DocEntryCBEnter(Sender: TObject);
> begin
>   GS := '';
>   GCOUNT := 0;
>   TComboBox(Sender).ItemIndex := 0;
> end;
> 
> procedure TMainForm.DocEntryCBKeyPress(Sender: TObject; var 
> Key: Char);
> begin
>   AutoMatch(TComboBox(Sender), Key);
> end;
> 
> 
> procedure AutoMatch(cbo: TComboBox; var keyascii: char);
> var
>   sbuffer: pchar;
>   s: string;
>   retval: longint;
> begin
>   getmem(sbuffer, 255);
>   if Keyascii = #8 then
>   begin
>     dec(GCOUNT);
>     s := copy(GS, 1, GCOUNT);
>   end
>   else
>     s := copy(GS, 1, GCOUNT) + (Keyascii);
>   try
>     strpcopy(sbuffer, s);
>     retval := sendmessage(cbo.Handle, CB_FINDSTRING, word(-1),
>       longint(sbuffer));
>     if retval <> CB_ERR then
>     begin
>       cbo.ItemIndex := Retval;
>       GS := cbo.Text;
>       Inc(GCOUNT);
>       Keyascii := chr(0);
>     end
>     else
>     begin
>       messagebeep(0);
>       cbo.Text := GS;
>     end;
>   finally
>     freemem(sbuffer, 255);
>   end;
> end;
> 
> Mark
> 
> ----- Original Message -----
> From: "Stephen Barker" <[EMAIL PROTECTED]>
> To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
> Sent: Tuesday, May 22, 2001 8:42 PM
> Subject: [DUG]: TComboBox keys
> 
> 
> > Hi,
> >
> > does anyone know how to make a TComboBox do incremental searching?
> >
> > by default it only seems to search on the first character.
> >
> > I tried concatenating key values and setting the itemindex 
> to the correct
> > item, but the default behaviour still takes over.
> >
> > in the keydown event I have:
> >
> > procedure TfrmMain.cboProjectKeyDown(Sender: TObject; var Key: Word;
> >   Shift: TShiftState);
> > var
> >   i : integer;
> > begin
> >   if (Key >= ord('0')) and (Key <= ord('9')) then begin
> >     ProjKey := ProjKey + chr(Key);
> >     i := 0;
> >     while (i < cboProject.Items.Count) and
> > (copy(cboProject.Items[i],1,length(ProjKey)) <> ProjKey) do
> >       inc(i);
> >     // i := cboProject.Items.IndexOf(ProjKey);
> >     if i = cboProject.Items.Count then i := 0;
> >     cboProject.ItemIndex := i;
> >     Key := 0;
> >   end;
> > end;
> >
> > thanks,
> > Steve
> > 
> --------------------------------------------------------------
> ------------
> -
> >     New Zealand Delphi Users group - Delphi List - 
> [EMAIL PROTECTED]
> >                   Website: http://www.delphi.org.nz
> > To UnSub, send email to: [EMAIL PROTECTED]
> > with body of "unsubscribe delphi"
> >
> 
> --------------------------------------------------------------
> -------------
>     New Zealand Delphi Users group - Delphi List - 
> [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED] 
> with body of "unsubscribe delphi"
> 
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to