Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.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
如何从Delphi7中的Grids类继承?_Delphi_Delphi 7 - Fatal编程技术网

如何从Delphi7中的Grids类继承?

如何从Delphi7中的Grids类继承?,delphi,delphi-7,Delphi,Delphi 7,这是我从TStringGrid类继承的类。我想创建一个网格,该网格将填充来自数据库的数据。但现在这只是一个简单的类存根: unit clsTCustomStringGrid; interface uses Grids, Dialogs; type TCustomStringGrid = class (TStringGrid) public procedure SayHello (); e

这是我从TStringGrid类继承的类。我想创建一个网格,该网格将填充来自数据库的数据。但现在这只是一个简单的类存根:

unit clsTCustomStringGrid;

interface

    uses Grids, Dialogs;

    type
        TCustomStringGrid = class (TStringGrid)
            public
                procedure SayHello ();
        end;

implementation

    procedure TCustomStringGrid.SayHello ();
    begin
        ShowMessage('Hello World!');
        // procedure body
    end;

end.
这是我的主要形式:

uses ...
     ...
    TCustomStringGrid; // here is where the compilation stops

    ...
    ...
    ...

    procedure TMyForm.FormShow (Sender: TObject);
    var
        MySG: TCustomStringGrid;
    begin
        MySG := TCustomStringGrid.Create(self);
        MySG.Left := 100;
        MySG.Top := 40;
        MySG.Parent := self;
        MySG.SayHello();
    end;
我得到的错误是:

File not found: 'TCustomStringGrid.dcu'

请帮我找出我做错了什么。

在uses子句中添加clsTCustomStringGrid,而不是TCustomStringGrid

您的类在
单元clsTCustomStringGrid中声明
,但您的
uses
子句正在使用
TCustomStringGrid
(这是类名)

更改您的使用条款:

uses ...
  ...
  clsCustomStringGrid; 
  ...

这是倒退。您永远不会实例化名为TCustomStringGrid的类。你会从中得到什么。如果您想要一个数据绑定的网格,那么从TStringGrid派生感觉是错误的。我猜想使用现成的数据绑定网格会更好。至少你需要复习一下组件编写。你为什么不想读一本组件编写器指南之类的东西呢?TCustomStringGrid是我从Delphi TStringGrid类派生的派生类的用户名。怎么了?问题是我实际上不想在我的应用程序中有一个数据绑定网格。我想从数据库中获取数据,但我不希望它具有数据感知功能。我想自己填充它。这实际上比标准的Delphi数据感知组件在网格上提供了更多的灵活性。@MikhailRybkin:因为
TCustomStringGrid
是现有VCL类的名称;它是
TStringGrid
本身的祖先类。(它在
网格
单元中。)从维护和组件用户的角度来看,使用与VCL基类相同的名称是一个糟糕的主意。(实际上,它没有任何意义,可能也不会编译:您的
TCustomStringGrid
继承自
TStringGrid
,它继承自
TCustomStringGrid
。想想看。)我查了一下,它说Lazarus的组件库中有这个组件。但是我在Delphi帮助系统中找不到任何关于TCustomStringGrid的信息。