Problem with TwwDBComboBox not showing similar Items in Delphi (InfoPower2012)

347 views
Skip to first unread message

Paul Ross

unread,
Oct 15, 2013, 3:32:19 AM10/15/13
to woll2woll...@googlegroups.com
Using InfoPower 2012 (Oct2012) with Delphi XE2.
 
I've placed a TwwDBCombobox on a form. I'm using it without a DB connection and have added items manually (see attached image). I want the displayed value to be the person's first name, but the stored data is a payroll number. Although the stored payroll values are unique, it's possible that some people will have the same first name. For example, David and Paul are listed twice with different payroll numbers in this example.
 
The problem is that when 'Map Displayed Value' is turned on, the drop-down list shows the payroll number for the first 'Paul' against each instance of 'Paul'. The other Paul with payroll 18 isn't listed (see bottom left of attached image).
 
Am I missing something?
 
twwcombobox.jpg

Roy Woll

unread,
Oct 15, 2013, 6:12:01 PM10/15/13
to woll2woll...@googlegroups.com
The TwwDBComboBox requires that the display value be unique. It does not support the mode you are using. I suggest using the TwwDBLookupCombo instead for this as it is more capable in this situation. If you don't want to have to create a physical dataset, you don't have to as you can create an in-memory dataset for this.  For instance drop in a TwwDBLookupCombo and TwwClientDataSet and set the fielddefs to the fieldnames that you want, or copy the following text to the clipboard and paste it into your form to create the in-memory dataset. 

object ClientDataSet2: TClientDataSet
  Active = True
  Aggregates = <>
  FieldDefs = <
    item
      Name = 'Description'
      DataType = ftString
      Size = 20
    end
    item
      Name = 'Code'
      DataType = ftInteger
    end>
  IndexDefs = <>
  Params = <>
  StoreDefs = True
  Left = 296
  Top = 88
  Data = {
    600000009619E0BD010000001800000002000000000003000000600014436C69
    656E7444617461536574324669656C6431010049000000010005574944544802
    000200140014436C69656E7444617461536574324669656C6432040001000000
    00000000}
end

The set your lookupfield to code and lookuptable to your newly created clientdataset.  Finally the only remaining step is to initialize the data in your form's OnShow event. For instance....

procedure TComboDemoForm.FormShow(Sender: TObject);
begin
  clientdataset2.Insert;
  clientdataset2.fieldbyname('description').AsString:= 'David';
  clientdataset2.fieldbyname('code').AsString:= '12';

  clientdataset2.Insert;
  clientdataset2.fieldbyname('description').AsString:= 'David';
  clientdataset2.fieldbyname('code').AsString:= '14';
  clientdataset2.Post;

  clientdataset2.Insert;
  clientdataset2.fieldbyname('description').AsString:= 'Paul';
  clientdataset2.fieldbyname('code').AsString:= '16';
  clientdataset2.Post;

  clientdataset2.Insert;
  clientdataset2.fieldbyname('description').AsString:= 'John';
  clientdataset2.fieldbyname('code').AsString:= '17';
  clientdataset2.Post;

  clientdataset2.Insert;
  clientdataset2.fieldbyname('description').AsString:= 'Paul';
  clientdataset2.fieldbyname('code').AsString:= '18';
  clientdataset2.Post;

end;


-Roy

Reply all
Reply to author
Forward
0 new messages