Solved

Search TList

Posted on 2004-08-29
4
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
code issue 8 188
Delphi inherited method 6 80
Is there any way to treat Lock record in table with clientdataset? 3 32
TlistView is Really heavy on Android 3 22
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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