Reputation:
I'm using this code to filter my table with dblookupCombobox:
ADOTable1.Filtered:=False;
ADOTable1.Filter:='Section=' + ADOTable2.FieldByName('Section').AsString;
ADOTable1.Filtered:=True;
but it raises this exception:
the arguments are of the wrong type outside the allowed limits.
Where is the problem please?
Upvotes: 1
Views: 187
Reputation: 30715
The problem you are getting happens because of this:
Suppose the value of AdoTable2.FieldByName('Section').AsString is SomeValue
. Then, the value you assign to AdoTable1.Filter is
Section = SomeValue
AdoTable1 tries to interpret SomeValue as a field name, but this fails because AdoTable1 does not have a field of that name.
To overcome the problem, you simply need to surround SomeValue in the Filter expression in quotes. Delphi has a utility function QuotedStr
which will do that for you (and correctly deal with the situation where the string passed into it contains embedded quotes (e.g. where the value is a name like O'Brien').
So replace your current assignment of the filter by:
ADOTable1.Filter := 'Section=' + QuotedStr(ADOTable2.FieldByName('Section').AsString);
Upvotes: 1