The Master/Detail relation between two queries with FireDac will fail when these conditions are met:
a) Binding is through SQL parameters.
b) Parameter names contain special characters, for example locale ones.
The fail symptom is that the relation will not be created, both queries will remain separated, no compile or runtime error appears.
For example, this relation will fail (please pay attention to the "note" tags and the involved special characters):
// // (Not functional code, just for reference) // Master query, to be linked through field 'CódigoProyecto' (**note** the special character 'ó'): object qryMaster: TFDQuery [...other query data...] object qryMaster: TWideStringField FieldName = 'C'#243'digoProyecto' // **note!** (1) Origin = '[C'#243'digoProyecto]' SQL.Strings = ('SELECT C'#243'digoProyecto FROM tableMaster') end end // Detail table, linked through field 'CódigoProyecto': object qryDetail: TFDQuery [...other query data...] MasterFields = 'C'#243'digoProyecto' MasterSource = [your master TDatasource] SQL.Strings = ('SELECT C'#243'digoProyecto FROM tableDetail') ParamData = < item Name = 'C'#211'DIGOPROYECTO' // **note!** (2) DataType = ftString ParamType = ptInput end> end
This relation will not be created at runtime.
The reason is that detail parameter name (see note (2), uppercase 'Ó') has been internally converted to uppercase. However, master field name (see note(1), lowercase 'ó') will remain lowercase.
When at runtime delphi tries to match detail parameter name (uppercase 'Ó') with master field name (lowercase 'ó'), it will use an internal function that does not deal with special characters.
This function is:
// function CompareText(const S1, S2: string): Integer;
located in unit
// System.SysUtils
(You will note that this function only works in the ranges [a..z] and [A..Z])
This function is called from:
// TFDParams.FindParam(const AValue: String): TFDParam;
located in unit
// FireDAC.Stan.Param
A quick workaround is to look for your database components that contain field names that will be used as MASTER fields and also have SPECIAL CHARACTERS, and manually turn those fields to UPPERCASE.
In the sample above, just converting qryMaster.FieldName to 'CÓDIGOPROYECTO' will do.
Another option may be correcting the said FindParam function so that it will compare using locale.