我需要动态创建TDBText控件,如下代码为什么有错?
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, StdCtrls, ExtCtrls;type
  TForm1 = class(TForm)
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }  public
    { Public declarations }
  end;var
  Form1: TForm1;
  I,J,Flag :Integer;
implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
Lab: Array[0..10] of TDBText;
begin
for i:=0 to 9 do
begin
    Lab[i] := TDBText.Create(self);
    Lab[i].Caption:='aaa';
    Lab[i].Parent := form1;
    Lab[i].Top:=i*10;end;end.
错误为:
[Error] Unit1.pas(30): Undeclared identifier: 'TDBText'
[Warning] Unit1.pas(32): For loop control variable must be simple local variable
[Error] Unit1.pas(34): Record, object or class type required
[Error] Unit1.pas(35): Missing operator or semicolon
[Error] Unit1.pas(36): Missing operator or semicolon
[Error] Unit1.pas(37): Missing operator or semicolon
[Error] Unit1.pas(41): ';' expected but '.' found
[Error] Unit1.pas(43): Declaration expected but end of file found
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DBCtrls;type
      TForm1 = class(TForm)
        DBText1: TDBText;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    var
    i:integer;
    Lab: Array[0..10] of TDBText;
    begin
    for i:=0 to 9 do
    begin
        Lab[i] := TDBText.Create(self);
        Lab[i].Name :='DBText_'+Inttostr(i+1);
        Lab[i].Caption:='aaa';
        Lab[i].Parent := form1;
        Lab[i].Top:=i*10;end;end;end.