Solved

Need help with a component trying to use Lookup

Posted on 2006-07-12
2
204 Views
Last Modified: 2010-04-05
Ok,

I'm using Absolute DB (componentace.com) with a table that is setup in the following way:

------------------------------------------------------|
BLink | OLink | Option                       | PBCode|
------------------------------------------------------|
201   | 1001  | 'Integral Dust Drawer' | 'IDD'    |
------------------------------------------------------|

So, this is a price book table, with BLink(book link), OLink(option link) and a PBCode which is a string value, and option text.  

I have a combo box component that I'm trying to automatically fill with option text based on an array that is passed to it.  Here's the code that I build the combo box with:

Var
  modelArray: Array [0..2] of String;
Begin

    modelArray[0] := 'GSMBASE';
    modelArray[1] := 'HOPPER';
    modelArray[2] := 'IDD';

    //_Configuration is the combo box I'm trying to build....
    _Configuration.LoadItemsFromCodes(modelArray);

//Here's the code for the combo box.  It has properties of BLink and OLink, which are integer values.  So in this case the BLink is set to 201:

Function TPBxComboBox.LoadItemsFromCodes(codeArray: Array Of String): Integer;
Var
    i,daOLink: Integer;
     SearchList, SearchList2: Variant;
Begin
    Result := -1; // error code for NIL value for datasets
    ErrMsg := 'Nil Datasets';
    If Not Assigned(dsOptions) Then
        Exit;
    If Not Assigned(PItem) Then
        Exit;

    xOLinkTrack := False;

    For i := 0 To High(codeArray) Do
    Begin
        With dsOptions As TABSTable Do
        Begin
           
            If State = dsInactive Then
                Open;

            Self.Items.Clear;
            xOLinkList.Clear; //this is a string list that contains an olink for each item in the combo box

            //lookup the OLink for the PBCode that was passed via the codeArray[] array:
            daOLink := dsOptions.Lookup('BLink;PBCode', VarArrayOf([BLink,codeArray[i]]), 'OLink');

            Self.xOLinkList.Add(IntToStr(daOLink));
           
            //use the Olink we just found to lookup the Option text for placing in the combo box
            Items.Add(dsOptions.Lookup('BLink;OLink', VarArrayOf([BLink, daOLink]), 'Option'));

            Self.ItemIndex := 0;
            Result := Items.Count;

            //other various code....
            If Items.Count > 0 Then
            Begin
                xOLinkTrack := True;
                ziHold      := ihOptions;
                Self.Change;
            End;
        End;
    End;
End;

As you can see, this should find an olink for the each of the values that I pass to the LoadItemsFromCodes function, then use that olink to find the option text and load that text into the combo box.  However, it only puts the 'IDD' or Integral Dust Drawer option in.  The two other array values are simply not present in the combo box, even though they are present in the dsOptions table and should be in the combo box.  I cannot figure out why.  This is my first time using the Lookup method, so I may be missing something easy here.

Thanks!
0
Comment
Question by:light_bulb
[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
2 Comments
 
LVL 3

Author Comment

by:light_bulb
ID: 17091334
Oh shoot, I found the problem.  I should have put the following lines before the loop instead of inside it:

Self.Items.Clear;
xOLinkList.Clear;

I was clearing the lists every time through the loop.  Oh well, not the first time I've made that mistake.
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 500 total points
ID: 17106729
Damn! I was about to say that too. :-)

You might want to put the line "If State = dsInactive Then Open;" also a bit higher, outside the loop. No need to check if it's inactive for every item in the array, is it? This will probably speed up your code with about 5 clock cycles, which on a 1 GHz computer will save you... Well, it's not much, I know...

Go ask for a refund and have this question deleted before someone else sees your mistake... ;-)

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
Delphi Form ownership 4 157
find a node in VST 2 92
creating threads in delphi 1 201
DBGrid or StringGrid ? 6 136
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 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