我以前没自己写过组件,今天上午写了玩,不想给我当头一棒???
我晕 ̄!@#! ̄部分代码如下:
unit PerTypeLabel;interfaceuses
  Windows, Messages, SysUtils, Classes, Controls, StdCtrls,ExtCtrls,MMSystem;type
  PerTypeLabel = class(TCustomLabel)//******
  private
    { Private declarations }
    perTextTimer:TTimer;
    PerSoundTimer:TTimer;
    tmpTextFile:TextFile;
    LabelCaption:String;
  protected
    { Protected declarations }
    procedure UpdateCaption(Sender:TObject);
    procedure UpdateSound(Sender:TObject);    function CheckFileName(FileName:String):Boolean;
    function ReadChar:char;
        procedure SetTextFileName(Value:String);
    procedure SetSoundFileName(Value:String);
    procedure SetTextSpeed(Value:Integer);
    procedure SetSoundSpeed(Value:Integer);
    procedure SetPerEnabled(Value:Boolean);
    function GetTextFileName:String;
    function GetSoundFileName:String;
    function GetTextSpeed:Integer;
    function GetSoundSpeed:Integer;
    function GetPerEnabled:Boolean;
  public
    { Public declarations }
    constructor Create(AOwner:TComponent);override;
  published
    { Published declarations }
    property Align;
    property Alignment;
    property color;
    property ParentColor;
    property ParentFont;
    property ParentShowHint;
    property popupMenu;
    Property ShowHint;
    property Transparent;
    property Visible;
    property perTextFileName:String read GetTextFileName write SetTextFileName;
    property perSoundFileName:String read GetSoundFileName Write SetSoundFileName;
    property perTextSpeed:Integer read GetTextSpeed write SetTextSpeed default 250;
    property perSoundSpeed:Integer read GetSoundSpeed write SetSoundSpeed default 80;
    property perEnabled:Boolean read GetPerEnabled write SetPerEnabled default False;
  end;procedure Register;implementation
procedure Register;
begin
  RegisterComponents('per', [PerTypeLabel]);//******
end;
procedure PerTypeLabel.Create(AOwner:TComponent);//******
begin
  inherited Create(AOwner);//******  perTextTimer:=TTimer.Create(Self);//******//******
  perTextTimer.Name:='TextTimer';//******
  perTextTimer.OnTimer:=UpdateCaption;//******
  perTextTimer.Enabled:=GetEnabled;//******  perSoundTimer:=TTimer.Create(Self);//******
  perSoundTimer.Name:='SoundTimer';//******
  perSoundTimer.OnTimer:=UpdateSound;//******
  perTextTimer.Enabled:=GetEnabled;//******
end;
procedure PerTypeLabel.SetTextFileName(Value:String);//******
begin
  perTextFileName:=Value;//******//******
end;……
错误提示如下:(对应每条错误,我在相应的代码行后加****注释)[Error] PerTypeLabel.pas(18): Identifier redeclared: 'PerTypeLabel'
[Error] PerTypeLabel.pas(77): '.' expected but ']' found
[Error] PerTypeLabel.pas(83): Identifier redeclared: 'PerTypeLabel'
[Error] PerTypeLabel.pas(85): This form of method call only allowed in methods of derived types
[Error] PerTypeLabel.pas(87): Undeclared identifier: 'perTextTimer'
[Error] PerTypeLabel.pas(87): Undeclared identifier: 'Self'
[Error] PerTypeLabel.pas(88): Missing operator or semicolon
[Error] PerTypeLabel.pas(89): Missing operator or semicolon
[Error] PerTypeLabel.pas(90): Missing operator or semicolon
[Error] PerTypeLabel.pas(92): Undeclared identifier: 'perSoundTimer'
[Error] PerTypeLabel.pas(93): Missing operator or semicolon
[Error] PerTypeLabel.pas(94): Missing operator or semicolon
[Error] PerTypeLabel.pas(95): Missing operator or semicolon
[Error] PerTypeLabel.pas(103): Identifier redeclared: 'PerTypeLabel'
[Error] PerTypeLabel.pas(105): Undeclared identifier: 'perTextFileName'
[Error] PerTypeLabel.pas(105): Undeclared identifier: 'Value'
……请各位大侠帮忙!!!

解决方案 »

  1.   

    对   同名了!
    unit PerTypeLabel;type
      PerTypeLabel = class(TCustomLabel)//******
      

  2.   


     ehom(?!)兄说的对,是同名了,其它错误都搞定了,只剩下面三个,不知什么回事 
    [Error] PerTypeLabel.pas(32): Unsatisfied forward or external declaration: 'TPerTypeLabel.CheckFileName'
    [Error] PerTypeLabel.pas(33): Unsatisfied forward or external declaration: 'TPerTypeLabel.ReadChar'
    [Error] PerTypeLabel.pas(186): Undeclared identifier: 'tmpTextFile'
    声明部份还是上面我贴来的代码,第三个错误Error] PerTypeLabel.pas(186): 所涉及的代码如下:
    function perReadChar:char;
    var
      tmpChar:Char;
    begin
      read(tmpTextFile,tmpChar);//从文本文件中读一个字符//******
      result:=tmpChar;
    end;
      

  3.   

    前两个错误表明,你申明了成员函数,确没有在下面写出来第三个:
    function perReadChar:char;
    =>
    function TPerTypeLabel.perReadChar:char;read(tmpTextFile,tmpChar);//tmpTextFile是TPerTypeLabel的成员,这里当然会出错所以要把perReadChar也写为类的成员函数
      

  4.   

    我在前面的private中声明的tmpTextFile变量,在protected中声明的CheckFileName和ReadChar函数,也在后面的代码中写了呀!!! ehom(?!) 兄,能否再详细点!!!十分感谢你前面的回答!!