Mega Code Archive

 
Categories / Delphi / Examples
 

Arraysearch

function TPerformanceDBMS.NameSearch(searchName: String): String; {iterate through all seat booking records looking for customer_name values} {that match the name input by the user... return a single string that holds} {search results in the form 'first_booked_seat_name, number_of_booked_seats} {-clearly if the program was going to be all singing and dancing this wouldn't} {be enough -the BEST way to implement it might be to temporarily clear the} {seat display to show (in red) only those seats booked by the given customer...} var row : Char; column : Integer; tempRow, tempColumn, details: String; numBookedInt: Integer; numBookedStr: String; begin numBookedInt := 0; for row := 'A' to last_row do begin for column := 1 to last_column do begin if SeatArray[row,column].customer_name = searchName then begin if numBookedInt = 0 then begin tempRow := row; tempColumn := IntToStr(column); details := tempRow + tempColumn; end; Inc(numBookedInt); end; {outer if} end; {for} end; {for} if numBookedInt > 0 then begin numBookedStr := IntToStr(numBookedInt); details := details + ','; details := details + numBookedStr; end else begin details := 'NONE'; end; Result := details; end;