Automating Inner Join using Lookupcombobox component

Asked

Viewed 117 times

3

Sometimes I use the Tdblookupcombobox component to bring a list of a dataset lookup field, this approach streamlines some things but is very limited.

For example I have a list of stores in one Tdblookupcombobox and in another a list of customers, however customers should appear according to the chosen store, so there is a component type data ware that Automatize this?

I do it in the traditional way using an Inner Join according to the chosen store and thus populating the second combobox, this being of the type Tcombobox.

  • Friend, in this line of your customers there is a field that identifies which store it belongs to?

  • @Giovaniracipaganini does exist.

1 answer

1


What you can do is the following, following your example, bring in consultation all customers and all stores, each of them in your dataset. Configure both lookup’s accordingly, now to do the effect you want without going again to make a query in the database configure the event AfterScroll in the dataset of the customer to stay that way:

procedure TMeuForm.MeuDatasetClienteAfterScroll(Dataset : TDataset);
begin
  MeuDatasetLoja.Filter := Format('idcliente = %d', [MeuDatasetCliente.FieldByName('idcliente').AsInteger]);
end;

this way to each roll in the dataset customer will be filtered the dataset store. remembering that in the dataset of the store it is necessary to enable the property filtered := True.

  • in case, I want to filter customers according to the store, then I could put in the event onExit of Dblookupcombobox that your code, that after I have chosen the store, it filters the customer dataset, so that way only appear the respective customers. But in this approach I always bring all customers and then filter

  • wanted to bring only the respective customers not to slow down the application

  • @user21051 you would have basically these two options to implement the functionality, everything falls on the cost analysis. what is better? bring everything and make the loading of the form slower or each modification go looking in the bank, I would make the decision depending on various aspects. if it is a client server application and normally the network structures are slow, I would choose to load everything at once and then filter location, if the application was local then I would choose to load on demand. then everything depends on your scenario. the option of how to execute is up to you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.