Link to home
Start Free TrialLog in
Avatar of foxjax
foxjax

asked on

Search TList

I have a TList that is used to store records

Type

   TRecord = ^TCard;

   TCard = packed record

           Item           : Integer;
           Name           : String;
           Limit          : Boolean;
           Period         : String;


end;


   Group  : TList;
   Record : TRecord;

Question - how can i search through each of the records for an item number or a name and return the record number ( ie: user can search by using an item number or the name of a product)?
Avatar of kretzschmar
kretzschmar
Flag of Germany image

function findrecord(sType : Integer; sName : String; sNumber : Integer) : Integer;
var i : integer;
begin
  i := 0;
  case sType of
    1 : begin  //search by name
            while (i < group.count) and (TRecord.name <> sName) do inc(i);
         end;
    2 : begin  //search by item
            while (i < group.count) and (TRecord.item<> sNumber) do inc(i);
         end;
  end;
  if (i < group.count) then
    result := i
  else
    result := -1
end;

just from head, just as sample

meikl ;-)
sorry a typo

instead of

TRecord.name
use
TRecord(groups[i]).name

also for the item section

meikl ;-)
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of foxjax
foxjax

ASKER

TRecord(groups[i])^.name made it work - thanks Meikl, i learned a lot from that.