这是否意味着我无法在delphi 2007和2009之间共享表格?
DoubleBuffered已经在TWinControl中使用了一段时间.Delphi 2009的不同之处在于它现已发布.如果你只能忽略错误(而不是让属性工作),这里有一个可能的解决方案:
unit Delphi2009Form; interface uses Windows, Classes, SysUtils, Controls, Forms; type {$IFDEF VER200} TDelphi2009Form = class(TForm); {$ELSE} TDelphi2009Form = class(TForm) private procedure ReaderError(Reader: TReader; const Message: string; var Handled: Boolean); protected procedure ReadState(Reader: TReader); override; end; TReaderErrorProc = procedure(const Message: string); var ReaderErrorProc: TReaderErrorProc = nil; {$ENDIF} implementation {$IFNDEF VER200} type THackReader = class(TReader); procedure TDelphi2009Form.ReaderError(Reader: TReader; const Message: string; var Handled: Boolean); begin with THackReader(Reader) do Handled := AnsiSameText(PropName, 'DoubleBuffered') or AnsiSameText(PropName, 'ParentDoubleBuffered'); if Handled and Assigned(ReaderErrorProc) then ReaderErrorProc(Message); end; procedure TDelphi2009Form.ReadState(Reader: TReader); begin Reader.OnError := ReaderError; inherited ReadState(Reader); end; {$ENDIF} end.
然后将项目中表单的声明更改为继承自TDelphi2009Form,例如:
type TFormMain = class(TDelphi2009Form) ...
这将在运行时工作 - 属性错误将被忽略.要使其在设计时工作,也要创建一个仅设计包,将designide.dcp添加到其requires子句中,并将以下单元添加到其中:
unit Delphi2009FormReg; interface uses Delphi2009Form; procedure Register; implementation uses DesignIntf, DesignEditors, ToolsAPI; procedure ShowReaderError(const Message: string); begin with BorlandIDEServices as IOTAMessageServices do AddTitleMessage(Message); end; procedure Register; begin RegisterCustomModule(TDelphi2009Form, TCustomModule); ReaderErrorProc := ShowReaderError; end; initialization finalization ReaderErrorProc := nil; end.
在Delphi 2007 IDE中安装软件包,在IDE中打开表单时,将自动忽略DoubleBuffered和ParentDoubleBuffered属性的属性错误.在Delphi 2007中保存表单时,属性的值将丢失,因此您应该在代码中初始化它们.
编辑:我添加了代码将读取器错误消息输出到IDE消息窗口:
是.除非从DFM中删除未在Delphi 2007中发布的属性,否则无法实现.