Subject Re: [IBO] Re: IB_ComboBox as parameters
Author Helen Borrie
At 04:00 PM 11/05/2006, you wrote:

>Hello Helen!
>
>It's always a priviledge to talk to people who knows what they're
>doing. ;-)
>All the tips were great. But, I'm afraid I've left out some important
>information in order to simplify things.
>
>Here goes the whole story:
>
>The "main" table here is indeed a detail from a master-detail,
>connected via MasterLinks (although this may not do any difference).
>
>The real table has 3 date fields and 2 foreign keys, any of these
>folks may be "parameterized" and that's the origin of my use of
>SQLWhereItems/InvalidateSQL.
>
>The complete OnPrepareSQL follows:
>//---------------------------------------------------------------------------
>void __fastcall TFormCadInstalacoes::IB_QueryOcorrenciasPrepareSQL(
> TIB_Statement *Sender)
>{
> AnsiString fieldName;
>
> switch (ListBoxDateFields->ItemIndex) {
>
> case 0: fieldName = "DATA_ENTRADA";
> break;
> case 1: fieldName = "DATA_RECONHECIMENTO";
> break;
> case 2: fieldName = "DATA_ATENDIMENTO";
> break;
> }
>
> IB_QueryOcorrencias->SQLWhereItems->Add(fieldName + " >=
>:data_inicial");
> IB_QueryOcorrencias->SQLWhereItems->Add(fieldName + " <=
>:data_final");
>
> if (IB_CBClasseOcorrencia->ItemIndex != -1)
> IB_QueryOcorrencias->SQLWhereItems->Add("id_classe_ocorrencia
>= :id_classe_ocorrencia");
>
> if (IB_CBCodigoOcorrencia->ItemIndex != -1)
> IB_QueryOcorrencias->SQLWhereItems->Add("id_ocorrencia =
>:id_ocorrencia");
>
>}
>//---------------------------------------------------------------------------
>
>The tricky part is that the date fields are working but the Combos
>don't. I didn't found many docs about the use of these features but
>may be I'm missing the right ordering of events (or perhaps just
>completely lost and confused %-).

Well, now you're not the only one. :-)

But - the main thing to keep in mind is that the ParamName property
of the combobox has to be the _Name_ of a parameter in the main query
that the combobox's Datasource property points to. So, it follows,
that a parameter of that _Name_ must exist in the WHERE clause. The
ParamName in your previous details, which would resolve to {one of }
ItemValues[], didn't look anything like a date field....ID_CLASSE is a string.

Helen