Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在自定义Delphi组件中实现Columns.Columns属性_Delphi - Fatal编程技术网

在自定义Delphi组件中实现Columns.Columns属性

在自定义Delphi组件中实现Columns.Columns属性,delphi,Delphi,我正在将几个Delphi 2005应用程序转换为XE2,它们使用了一个不再可用的组件,因此我编写了自己的自定义组件来处理基本问题,当您将组件放到表单上时,这通常是正常的,但是,当我打开一个包含这个组件的VCL表单时,遇到了一个问题,该组件的属性已经在DFM中设置 Delphi 2005 DFM包含以下内容: object ExtendedGrid1: TExtendedGrid Left = 32 Top = 16 Width = 577 Height = 2

我正在将几个Delphi 2005应用程序转换为XE2,它们使用了一个不再可用的组件,因此我编写了自己的自定义组件来处理基本问题,当您将组件放到表单上时,这通常是正常的,但是,当我打开一个包含这个组件的VCL表单时,遇到了一个问题,该组件的属性已经在DFM中设置

Delphi 2005 DFM包含以下内容:

  object ExtendedGrid1: TExtendedGrid
    Left = 32
    Top = 16
    Width = 577
    Height = 257
    TabOrder = 0
    Columns.Columns = (
      'OE6.02'
      (
        'Test1'
        64
        False
        0
        'clWindowText'
        -11
        'Tahoma'
        0
        8
        False
        False
        False
        False
        0
        1
        0
        0
        0
        1
        0
        'clWindowText'
        -11
        'Tahoma'
        0
        8
        False
        False
        False
        False
        0
        1
        0
        'test2'
        64
        False
        0
        'clWindowText'
        -11
        'Trebuchet MS'
        0
        8
        True
        True
        False
        False
        0
        1
        0
        0
        0
        1
        0
        'clWindowText'
        -11
        'Tahoma'
        0
        8
        False
        False
        False
        False
        0
        1
        0
        ''
        '0'))
    RowHeights = (
      19
      19)
  end
尽管我的组件有一个基于从TCollection继承的类的Columns属性,并且我已经向使用继承项的集合添加了Columns属性,但当我尝试在设计器中打开表单时,会出现以下错误:

创建表单时出错:读取MyGrid1.Columns时出错。Columns:属性列不存在

如果我创建组件的新副本,然后设置列,我会在DFM中看到完全不同的东西:

Columns = <
  item
    Title = 'Test1'
    Width = 64
    Editable = False
    HeaderClipStyle = csClip
    HeaderFont.Charset = DEFAULT_CHARSET
    HeaderFont.Color = clWindowText
    HeaderFont.Height = -11
    HeaderFont.Name = 'Tahoma'
    HeaderFont.Style = []
    HeaderHAlign = haRight
    HeaderInnerBevel = bvNone
    HeaderOuterBevel = bvNone
    HeaderBorderWidth = 0
    HeaderBevelWidth = 0
    ContentsClipStyle = csClip
    ContentsFont.Charset = DEFAULT_CHARSET
    ContentsFont.Color = clWindowText
    ContentsFont.Height = -11
    ContentsFont.Name = 'Tahoma'
    ContentsFont.Style = []
    ComboFilled = False
    ComboEditable = False
  end
  item
    Title = 'test2'
    Width = 64
    Editable = False
    HeaderClipStyle = csClip
    HeaderFont.Charset = DEFAULT_CHARSET
    HeaderFont.Color = clWindowText
    HeaderFont.Height = -11
    HeaderFont.Name = 'Trebuchet MS'
    HeaderFont.Style = []
    HeaderInnerBevel = bvNone
    HeaderOuterBevel = bvNone
    HeaderBorderWidth = 0
    HeaderBevelWidth = 0
    ContentsClipStyle = csClip
    ContentsFont.Charset = DEFAULT_CHARSET
    ContentsFont.Color = clWindowText
    ContentsFont.Height = -11
    ContentsFont.Name = 'Tahoma'
    ContentsFont.Style = []
    ComboFilled = False
    ComboEditable = False
  end
  end>
列=<
项目
Title='Test1'
宽度=64
可编辑=假
HeaderClipStyle=csClip
HeaderFont.Charset=默认字符集
HeaderFont.Color=clWindowText
头部高度=-11
HeaderFont.Name='Tahoma'
HeaderFont.Style=[]
HeaderAlign=haRight
封头坡口=bvNone
头部外斜角=bvNone
HeaderBorderWidth=0
头部水平宽度=0
ContentsClipStyle=csClip
ContentsFont.Charset=默认字符集
ContentsFont.Color=clWindowText
ContentsFont.Height=-11
ContentsFont.Name='Tahoma'
ContentsFont.Style=[]
ComboFilled=False
comboediate=False
结束
项目
Title='test2'
宽度=64
可编辑=假
HeaderClipStyle=csClip
HeaderFont.Charset=默认字符集
HeaderFont.Color=clWindowText
头部高度=-11
HeaderFont.Name='Trebuchet MS'
HeaderFont.Style=[]
封头坡口=bvNone
头部外斜角=bvNone
HeaderBorderWidth=0
头部水平宽度=0
ContentsClipStyle=csClip
ContentsFont.Charset=默认字符集
ContentsFont.Color=clWindowText
ContentsFont.Height=-11
ContentsFont.Name='Tahoma'
ContentsFont.Style=[]
ComboFilled=False
comboediate=False
结束
结束>

有人能给我指出一些文章或解释吗?这些文章或解释允许我编写自定义组件,以便它能够处理旧的Delphi2005 DFM?谢谢。

这不是一个完整的答案,但可能会让您开始(您需要将所有必需的属性添加到
TColumn
中,并在
ReadColumn
/
WriteColumn
方法中实现它们的读/写):

此代码在.dfm中生成以下结果:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 282
  ClientWidth = 418
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object TestComponent1: TTestComponent
    Columns.Columns = (
      'OE6.02'
      (
        'Test1'
        64
        'Test2'
        128))
    Left = 200
    Top = 144
  end
end

我怀疑您需要使用WriteListBegin/WriteListEnd和ReadListBegin/ReadListEnd。看看在TCustomGrid中如何处理RowHeights和ColWidths属性。看看TCustomGrid.DefineProperties.com,它能够从旧的Delphi 2005表单中读取列属性信息,效果非常好。但是,我最初使用的是TCollection和TCollectionItem,它自动包含组件的集合属性编辑器,而新的实现不允许我通过设计器更改单个列对象属性。Columns属性不再具有。。。在对象检查器中查看栅格时单击。我是否需要编写自己的属性编辑器?
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 282
  ClientWidth = 418
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object TestComponent1: TTestComponent
    Columns.Columns = (
      'OE6.02'
      (
        'Test1'
        64
        'Test2'
        128))
    Left = 200
    Top = 144
  end
end