Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Posts
    20

    Unanswered: Delphi adoquery.locate with multiple keyfields and loPartialKey option

    What I'm trying to do is a simple "realtime" search to the form.

    The form has 3 editboxes: id, firstname, surname

    Typing to those boxes fires up the "OnKeyUp"-event what should take the search keys from the editboxes and with adoquery.locate move the cursor to the matching row.

    The trouble is that when using multiple keyfields, only the last keyfield uses loPartialKey option. That option should be used in every keyfield. So what to do?

    I have now made this:

    Code:
    procedure TForm_users.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    var Edit_id_int, errorPos: Integer;
    begin
      Val(Edit1.Text, Edit_id_int, errorPos);
      if errorPos = 0 then
        begin
          ADOQuery1.Locate('user_id;firstname;surname;',VarArrayOf([edit_id_int,Edit2.Text,Edit3.Text]),[loCaseInsensitive,loPartialKey]);
        end
      else
        begin
          ADOQuery1.Locate('firstname;surname;',VarArrayOf([Edit2.Text,Edit3.Text]),[loCaseInsensitive,loPartialKey]);
          Edit1.Clear;
        end
    end;
    Please, pretty please, help me!!

  2. #2
    Join Date
    Oct 2010
    Posts
    3
    This article is meant toRS Gold provide an Aion class guide,

    giving players more information about the different classes in the game. Buy WOW

    Gold
    I hope you find this information useful in choosing the best class for your personal play

    style. Please********* Gold note that class balance and other

    factors constantly change, so what holds true today, might be*********

    Gold
    significantly different tomorrow already.

  3. #3
    Join Date
    Apr 2004
    Location
    Arizona
    Posts
    75
    I would not use the Locate method. It slow and dirty. I would instead write my SQL command with parameters like so...

    procedure TForm_users.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    var Edit_id_int, errorPos: Integer;
    begin
    Val(Edit1.Text, Edit_id_int, errorPos);

    With ADOQuery1 do {I hate to type and like to use withs so all I have to do is call the method}
    Begin {ADOQuery1}

    Close; {Close the query}
    SQL.clear; {Clear the SQL command}
    SQL.Add('Select *,lower(firstname) as firstname,lower(surname) as surname From YourTableblah'); {Select Statment. Note the lower}

    {Your where statment here. Note the collon before the object specifies that this is a variable paramater that you can change with code.}

    SQL.Add('where (');

    if errorPos = 0 then SQL.Add('user_id = :user_id_param and'); {Not sure what errorpos is but here it is}

    SQL.Add('firstname = :firstname_param and');
    SQL.Add('surname = :surname_param )');

    ParamaeterByName('firstname_param').text := LowerCase(Edit2.text);
    ParamaeterByName('surname_param').text := Lowercase(Edit2.text);

    if errorPos = 0 then ParamaeterByName('user_id_param').integer := StrToInt(edit_id_int.text);

    {This may not work because you really should write your SQL into the Object using the Object inspector and set the paramater initial settings using the object inspector instead of using code like this.}

    End; {ADOQuery1}
    end; {Procedure}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •