bazzer747 25 Posted February 16, 2021 Hi, I'm aware that you can use a macro substitution in a select statement when you don't know some value until runtime (like a fieldname). If there a similar function that can be used in a Locate? I am developing a 'Search' on an accounts program where the user first selects a fieldname in which he looks for a value, maybe a 'Payee' fieldname or an 'Account' fieldname or a 'Deposit' fieldname. So the field on which to conduct the locate isn't known until runtime. A usual locate might look like this: if fdqA.Locate('Payee', cPayee ), []) then ShowMessage('Located!') else ShowMessage('Failed!'); But the user might want to search on 'Account' or 'Deposit'. Share this post Link to post
Stano 143 Posted February 16, 2021 I created a function for this, which has a field name in the argument. Share this post Link to post
Virgo 18 Posted February 16, 2021 1 hour ago, bazzer747 said: I'm aware that you can use a macro substitution in a select statement when you don't know some value until runtime (like a fieldname). If there a similar function that can be used in a Locate? What is the actual question? That is what locate function does. You pass fieldname and search value at runtime and it searches. Share this post Link to post
Stano 143 Posted February 16, 2021 For me, the question is quite unclear. I tried to give at least some answer. if fdqA.Locate (AFieldName, cPayee), []) then ShowMessage ('located!') else ShowMessage ('Failed!'); Share this post Link to post
Guest Posted February 16, 2021 (edited) 11 hours ago, bazzer747 said: But the user might want to search on 'Account' or 'Deposit'. FireDAC can works better than "LOCATE" method! Just read your HELP for "FireDAC" and "MACRO" replacement!!! here your sample using "LOCATE" - basic method for any DATASET descendent! my sample used in "Footman" project - BDE and Paradox file-tables! function TForm1.fncFindItRecord: boolean; var lFindOptions : TLocateOptions; lFieldNames : string; lValuesToFind: Variant; // because "VarArrayOf()" use!!! begin result := false; // lFindOptions := [TLocateOption.loCaseInsensitive]; lFindOptions := [TLocateOption.loPartialKey, TLocateOption.loCaseInsensitive]; // more flexible search... // begin case rdgrpNationalCompetitions.ItemIndex of 0: begin lFieldNames := 'FieldName1'; lValuesToFind := 'Value1 desired'; // qryCompetitionsFindItCompetitionName.AsString; end; 1: begin lFieldNames := 'FieldName1;FieldName2'; // see VarArrayOf() function on HELP SYSTEM lValuesToFind := VarArrayOf(['Value1', 'Value2-string']); // values according with "Fields" definitions on table: string, integer, boolean, datatime, etc... // lValuesToFind := VarArrayOf(['Value1', true]); // lValuesToFind := VarArrayOf(['Value1', 1000]); // lValuesToFind := VarArrayOf(['Value1', 1.25]); end; end; // if not FDQuery1.Locate(lFieldNames, lValuesToFind, lFindOptions) then begin ShowMessage('None record was founded with this information! Try it again...'); end else begin // waht you want do? result := true; end; end; end; hug Edited February 16, 2021 by Guest Share this post Link to post