我在用着TObjectBindSourceAdapter
对对象使用实时绑定。
我正在使用的对象的属性之一TObjectBindSourceAdapter
具有枚举类型,但是当我在对象中使用枚举类型时,适配器中的字段永远不会生成
我目前找到的唯一解决方案是将枚举类型定义为对象中的整数并对其进行类型转换。这似乎工作正常,但您必须保持枚举类型和整数的类型转换和返回。
这是一些示例代码来解释我的意思。
第一个示例使用我最初尝试的枚举类型,但似乎不起作用:
uses Data.Bind.ObjectScope;
Type
TMyEnumtype = (meOne, meTwo, meThree);
TMyObject = class
public
MyEnumType: TMyEnumtype;
end;
procedure TForm9.But1Click(Sender: TObject);
var
MyObject: TMyObject;
aBindSourceAdapter: TBindSourceAdapter;
begin
MyObject := TMyObject.Create;
MyObject.MyEnumType := meTwo;
aBindSourceAdapter := TObjectBindSourceAdapter<TMyObject>.Create(nil, MyObject, False);
if aBindSourceAdapter.FindField('MyEnumType') <> nil then
ShowMessage('MyEnumType found')
else
showmessage('MyEnumType not found');
FreeAndNil(MyObject);
FreeAndNil(aBindSourceAdapter);
end;
第二个例子似乎通过类型转换为整数来工作
uses Data.Bind.ObjectScope;
Type
TMyEnumtype = (meOne, meTwo, meThree);
TMyObject = class
public
MyEnumType: integer;
end;
procedure TForm9.But1Click(Sender: TObject);
var
MyObject: TMyObject;
aBindSourceAdapter: TBindSourceAdapter;
aEnumType : TMyEnumtype;
begin
MyObject := TMyObject.Create;
MyObject.MyEnumType := Integer(meTwo);
aBindSourceAdapter := TObjectBindSourceAdapter<TMyObject>.Create(nil, MyObject, False);
if aBindSourceAdapter.FindField('MyEnumType') <> nil then
ShowMessage('MyEnumType found')
else
showmessage('MyEnumType not found');
aEnumType := TMyEnumtype(aBindSourceAdapter.FindField('MyEnumType').GetTValue.AsInteger);
if aEnumType = meTwo then
showmessage('meTwo');
FreeAndNil(MyObject);
FreeAndNil(aBindSourceAdapter);
end;
我想知道其他人是否遇到过这个问题,以及是否有其他解决方案可以解决这个问题,而无需恢复为整数并继续使用枚举类型。我也不确定我的解决方法是否是执行此操作的常用方法。