Jump to content


Photo

LookupValue Function


  • Please log in to reply
No replies to this topic

#1 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 18 March 2005 - 10:43 PM

Hi,

Another piece of code born today. A function to lookup a value from a column based on a value in another column. I use it to lookup values from a key=value list presented in a 2 column gridview.

Usage:
CODE
value:=LookupValue(GridView2, 'ParameterNames', 'aKey', 'ParameterValues');

It looks up the value in the 'ParameterValues' column in the row where the value in the 'ParameterNames column' is 'akey'.

Note: the following should also work:
CODE
value:=LookupValue(GridView2, 0 'aKey', 1);

Source:
CODE
function LookupValue(GridView: TGridView; lookupcolumnname, lookupvalue, valuecolumnname: OleVariant): OleVariant;

var

 i                 : Integer;

begin

 Result := '';

 with GridView do

   for i := 0 to Pred(RowCount) do

     if CompareText(CellByName[lookupcolumnname, i].AsString, VarToStr(lookupvalue)) = 0 then

       begin

         Result := CellByName[valuecolumnname, i].AsString;

         Break;

       end;

end;

G.W. van der Vegt




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users