Tuesday, 5 January 2010

TDBLookupComboBox

Yesterday I converted TDBEdit controls to TEdit. Today, I'm going to tackle the TDBLookupComboBox components on the form. These are a little more tricky as they have two associated datasources: one for the value and one for the list. I'm only really interested in removing the link to the main datasource as this is the one that updates data. The list datasource is read-only.

I'm now going to do a bit of R&D. I don't know if you can use a TDBLookupComboBox and in a non-data-aware way for the value, but data-ware for the list. If I can, this will make things much easier.

...

Cool, this can be done with little fuss.

Steps:
  1. Remove the datasource and DataField property values from the TDBLookupComboBox.
  2. Use the KeyValue property in lieu of the Text property to access and set the chosen selection
This is really neat as it means I do not have to manually populate the drop down list or do any ListField to KeyField lookups when writing to the DB.

Next up is to do some refactoring on the form code. It's all a bit mixed up at the moment. I want a clear separation between my user interface controls and the database component fields. I'm going to achieve this by creating an entity class which I can use to pass data between the Form and Datamodule (View and Model).

No comments:

Post a Comment