Solved

Search TList

Posted on 2004-08-29
4
260 Views
Last Modified: 2010-08-05
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)?
0
Comment
Question by:foxjax
  • 3
4 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 11928816
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 ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 11928844
sorry a typo

instead of

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

also for the item section

meikl ;-)
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
ID: 11928846
maybe it must be

TRecord(groups[i])^.name

just no time for testing

meikl ;-)

0
 

Author Comment

by:foxjax
ID: 11928912
TRecord(groups[i])^.name made it work - thanks Meikl, i learned a lot from that.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now