我希望使用活动绑定将自定义delphi对象的TObjectList绑定到网格。我希望对象属性具有Nullable支持,以便如果它们没有值,则它们在网格中显示为空白,并编辑类似于数据集如何使用可空的db列。
我认为Delphi语言不支持可空类型?
TMyObject = class
private
FQuanitity: Nullable<Integer>;
FDescription: Nullable<string>;
public
property Quantity: Nullable<Integer> read FQuanitity write FQuanitity;
property Description: Nullable<string> read FDescription write FDescription;
end;
FMyObectList: TObjectList<TMyObject>;我将创建一个TPrototypeBindSource并使用OnCreateAdapeter绑定FMyObjectList
有人能指点我怎么做这种事吗?谢谢
编辑/回答:
Nullable类型的最佳选项是Spring4D,但无法使用Live直接绑定这些值。
发布于 2014-12-30 13:20:25
下面是如何在Nullable<string>引擎中注册string到string的类型转换,反之亦然:
procedure RegisterNullableConversions;
begin
TValueRefConverterFactory.UnRegisterConversion(TypeInfo(Nullable<string>), TypeInfo(string));
TValueRefConverterFactory.RegisterConversion(TypeInfo(Nullable<string>), TypeInfo(string),
TConverterDescription.Create(
procedure(const I: TValue; var O: TValue)
begin
if I.AsType<Nullable<string>>.HasValue then
O := I.AsType<Nullable<string>>.Value
else
O := 'null';
end,
'NullableToString', 'NullableToString', EmptyStr, True, EmptyStr, nil)
);
TValueRefConverterFactory.UnRegisterConversion(TypeInfo(string), TypeInfo(Nullable<string>));
TValueRefConverterFactory.RegisterConversion(TypeInfo(string), TypeInfo(Nullable<string>),
TConverterDescription.Create(
procedure(const I: TValue; var O: TValue)
begin
O := TValue.From<Nullable<string>>(I.AsString);
end,
'StringToNullable', 'StringToNullable', EmptyStr, True, EmptyStr, nil)
);
end;https://stackoverflow.com/questions/27692990
复制相似问题