我已经按照一些关于创建自定义属性编辑器对话框的教程,但涉及的内容很多,我无法正常工作.我想要完成的是一个自定义表单,带有日期选择器(日历),时间选择器,以及确定和取消按钮.表单完全没问题,但是我如何实现这一点,以便我可以使用按钮发布属性编辑器的某个类型的任何组件中的属性?
我想完全覆盖TDateTime
类型并将我的自定义编辑器放在其位置,因此无论在何处TDateTime
发布并在Object Inspector中可见,我都可以使用此编辑器在同一窗口中同时修改日期和时间.
问题是关于创建自定义属性编辑器的文档很差,尽管有些资源非常透彻,但它们会详细介绍这些功能,并且在最常见的场景中缺乏重点.
我应该如何配置类以将三个下拉列表(日期,月份,年份)绑定到单个Date属性,以使其按照"每个属性的单个请求参数"方案的工作方式工作?我想应该通过重写initBinder方法添加一些自定义PropertyEditors.还有什么 ?
IDE Object Inspector使用下拉ColorBox显示TColor属性,颜色可以通过名称选择 - clBlack等,如图形单元中所定义.问题是在图形单元中定义的clWeb颜色不存在,我定义的任何自定义颜色也不存在.
那么如何扩展Object Inspector中可选择的已定义颜色?
PS Delphi XE
我正在使用Spring CustomNumberEditor编辑器来绑定我的浮点值,并且我已经尝试过,如果值不是数字,有时它可以解析该值并且不返回任何错误.
所以似乎编辑器会解析它的值,直到它能够并省略其余的值.有没有办法配置这个编辑器所以验证是严格的(所以数字像10a或10a25导致错误)或我是否必须构建我的自定义实现.我在CustomDateEditor/DateFormat中看起来像设置lenient为false,因此无法将日期解析为最可能的日期.
我注册编辑器的方式是:
@InitBinder
public void initBinder(WebDataBinder binder){
NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setGroupingUsed(false);
binder.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, numberFormat, true));
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
请考虑这样的场景:
我有一个被调用的组件TMenuItemSelector
,它有两个已发布的属性:PopupMenu
- 允许TPopupMenu
从表单中选择一个实例,并MenuItem
允许从表单中选择任何实例TMenuItem
.
我想以MenuItem
一种方式修改属性的属性编辑器,在PopupMenu
分配时,只有菜单项PopupMenu
才能在下拉列表中看到.
我知道我需要编写自己的后代TComponentProperty
和覆盖GetValues
方法.问题是我不知道如何访问TMenuItemSelector
正在撒谎的表单.
Original TComponentProperty
使用此方法迭代所有可用实例:
procedure TComponentProperty.GetValues(Proc: TGetStrProc);
begin
Designer.GetComponentNames(GetTypeData(GetPropType), Proc);
end;
Run Code Online (Sandbox Code Playgroud)
但是,Designer
似乎是预编译的,所以我不知道它是如何GetComponentNames
工作的.
这就是我到目前为止所做的,我想我唯一缺少的是实现GetValues
:
unit uMenuItemSelector;
interface
uses
Classes, Menus, DesignIntf, DesignEditors;
type
TMenuItemSelector = class(TComponent)
private
FPopupMenu: TPopUpMenu;
FMenuItem: TMenuItem;
procedure SetPopupMenu(const Value: TPopUpMenu);
procedure SetMenuItem(const Value: TMenuItem);
published
property PopupMenu: TPopUpMenu read FPopupMenu write SetPopupMenu; …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring 3.2.0。我已经注册了一些自定义属性编辑器以满足一些基本需求,如下所示。
import editors.DateTimeEditor;
import editors.StrictNumberFormatEditor;
import java.math.RoundingMode;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.joda.time.DateTime;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.beans.propertyeditors.URLEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.context.request.WebRequest;
@ControllerAdvice
public final class GlobalDataBinder
{
@InitBinder
public void initBinder(WebDataBinder binder, WebRequest request)
{
binder.setIgnoreInvalidFields(true);
binder.setIgnoreUnknownFields(true);
//binder.setAllowedFields(someArray);
NumberFormat numberFormat=DecimalFormat.getInstance();
numberFormat.setGroupingUsed(false);
numberFormat.setMaximumFractionDigits(2);
numberFormat.setRoundingMode(RoundingMode.HALF_UP);
binder.registerCustomEditor(DateTime.class, new DateTimeEditor("MM/dd/yyyy HH:mm:ss", true));
binder.registerCustomEditor(Double.class, new StrictNumberFormatEditor(Double.class, numberFormat, true));
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
binder.registerCustomEditor(URL.class, new URLEditor());
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我已经注册了这么多编辑。其中两个DateTimeEditor
已StrictNumberFormatEditor
通过重写各自的方法进行定制,以满足数字格式和Joda-Time的自定义需求。
由于我使用的是 Spring 3.2.0,因此我可以利用@ControllerAdvice …
spring-mvc ×4
delphi ×3
java ×2
spring ×2
annotations ×1
components ×1
data-binding ×1
databinder ×1
delphi-2009 ×1
delphi-xe ×1
delphi-xe2 ×1
ide ×1
javabeans ×1
spring-3 ×1