I'm suspecting that your EDICOES_ID
field is an integer value, in which case you don't need to quote it in your filter expression and the LIKE
operator isn't supported AFAIK. If it is a string field, you do need the quotes and LIKE
is supported, but you typically want a wildcard in the expression as well. (LIKE is only supported for character (string) type fields. For numerics or dates, you need to use the usual comparison operators >, <, >=, <=, = or BETWEEN.)
Do yourself a favor, too, and declare a local variable, and making sure that there's actually an item selected in the ComboBox
before trying to access its Objects
. I've added one both for the ItemIndex
and for intermediate storage of the typecast Object
you're retrieving, which makes it much easier to debug if you need to do so.
Here's a solution either way (whether it's an integer field, or a string that needs quoting).
var
Idx, Value: Integer;
begin
Idx := ComboBox1.ItemIndex;
if Idx > -1 then
begin
CDSIndicados.Filtered := False;
Value := Integer(cxComboBox1.Properties.Items.Objects[Idx]);
// If the field is an integer, you don't need a quoted value,
// and LIKE isn't supported in the filter.
CDSIndicados.Filter := 'EDICOES_ID = ' + IntToStr(Value);
// Not relevant here, but LIKE isn't supported for date values
// either. For those, use something like this
CDSIndicados.Filter := 'EDICOES_DATE = ' + QuotedStr(DateToStr(Value));
// or, if the field is string and you want LIKE, you need to
// quote the value and include a wildcard inside that quoted
// string.
CDSIndicados.Filter := 'EDICOES_ID LIKE ' + QuotedStr(IntToStr(Value) + '%');
CDSIndicados.Filtered := True;
end;
end;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…