If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Delphi adoquery.locate with multiple keyfields and loPartialKey option

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-21-05, 19:52
doze doze is offline
Registered User
 
Join Date: Jul 2004
Posts: 19
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!!
Reply With Quote
  #2 (permalink)  
Old 10-10-10, 20:50
dfyhkjhl dfyhkjhl is offline
Registered User
 
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.
Reply With Quote
  #3 (permalink)  
Old 09-29-11, 12:24
AceOmega AceOmega is offline
Registered User
 
Join Date: Apr 2004
Location: Arizona
Posts: 49
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}
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On