我有客户端表,如果字段/项目是字符串类型,无论用户在 EdtSearch.Text 中输入什么类型,我想过滤用户选择的字段上的表,所有表字段包含在组合框组件中。用户选择的 id 是 firebird 整数 auto_inc 字段获取异常:
Exception class EVariantTypeCastError with message 'Could not convert variant of type (OleStr) into type (Boolean)'.
代码:
procedure Tfrm_Personnes.EdtSearchChange(Sender: TObject);
var
Pattern: string;
begin
if CbxSearchOptions.Text = 'Commence' then Pattern := QuotedStr(EdtSearch.Text + '*');
if CbxSearchOptions.Text = 'Contient' then Pattern := QuotedStr('*' + EdtSearch.Text + '*');
with TClientDataSet(dts_Tableau_Personnes.DataSet) do
begin
if EdtSearch.Text <> EmptyStr then
begin
Filter := DisplayToOriginName(dts_Tableau_Personnes, CbxField.Text)+' = ' + Pattern;
Filtered := True;
end else
Filtered := False;
end;
end;
function DisplayToOriginName(DataSource: TDataSource; DisplayName: string): string;
var
I: Integer;
begin
with TClientDataSet(DataSource.DataSet) do
for I := 0 to FieldCount - 1 do
begin
if SameStr(Fields[i].DisplayName, DisplayName) then
Result := Fields[i].FieldName;
end;
end;
什么是让过滤器在整数字段上工作的正确方法谢谢