unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TKeyGen = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  KeyGen: TKeyGen;implementation{$R *.dfm}procedure TKeyGen.Button1Click(Sender: TObject);  function KeyGen(Name: string): string;
var
      n, tmp, Len: integer;
      res: string;
begin
      Len := Length(Name);
      if Len < 6 then      begin
          Result := '用户名太短...';
          exit;
      end;
      if Trim(Name) <> Name then
      begin
          Result := '用户名前后不能含空格';
          exit;
      end;
      Name := UpperCase(Name);
      for n := 1 to Len do
      begin
          if n mod 2 = 0 then 
              tmp := n * 3 + ord(Name[n])
          else
              tmp := n * (-3) + ord(Name[n]);
          if (tmp < $30) then
              res := res + '@'
          else if (tmp > $69) then res := res + '*'
          else
              res := res + Chr(tmp);
      end;
      Result := res;end;
=====================
错误[Error] Unit1.pas(83): Declaration expected but end of file found
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'看看错在哪里? 

解决方案 »

  1.   

    楼上说得没错~~结尾少了一个end.
      

  2.   

    Unit1.pas(83): Declaration expected but end of file found 这里说明需要一个描述。83是行号
      

  3.   

    加了end
    错误[Error] Unit1.pas(63): BEGIN expected but END found
      

  4.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TKeyGen = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      KeyGen: TKeyGen;implementation{$R *.dfm}procedure TKeyGen.Button1Click(Sender: TObject);  //function KeyGen(Name: string): string;这里的嵌套函数没有函数体?
    var
          n, tmp, Len: integer;
          res: string;
    begin
          Len := Length(Name);
          if Len < 6 then      begin
              Result := '用户名太短...';
              exit;
          end;
          if Trim(Name) <> Name then
          begin
              Result := '用户名前后不能含空格';
              exit;
          end;
          Name := UpperCase(Name);
          for n := 1 to Len do
          begin
              if n mod 2 = 0 then
                  tmp := n * 3 + ord(Name[n])
              else
                  tmp := n * (-3) + ord(Name[n]);
              if (tmp < $30) then
                  res := res + '@'
              else if (tmp > $69) then res := res + '*'
              else
                  res := res + Chr(tmp);
          end;
          Result := res;end; end.
      

  5.   

    明白了。
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TKeyGen = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      KeyGen: TKeyGen;implementation{$R *.dfm}procedure TKeyGen.Button1Click(Sender: TObject);
      function KeyGen(Name: string): string;
      var
          n, tmp, Len: integer;
          res: string;
      begin
          Len := Length(Name);
          if Len < 6 then
          begin
              Result := '用户名太短...';
              exit;
          end;
          if Trim(Name) <> Name then
          begin
              Result := '用户名前后不能含空格';
              exit;
          end;
          Name := UpperCase(Name);
          for n := 1 to Len do
          begin
              if n mod 2 = 0 then
                  tmp := n * 3 + ord(Name[n])
              else
                  tmp := n * (-3) + ord(Name[n]);
              if (tmp < $30) then
                  res := res + '@'
              else if (tmp > $69) then res := res + '*'
              else
                  res := res + Chr(tmp);
          end;
          Result := res;
      end;
    begin
      //在这里写事件处理程序。
    end;
    end.
      

  6.   

    begin
      //在这里写事件处理程序。---------这里没有的吧
    end;
    end.
      

  7.   

    没看清楚,不过结尾处是少了个 end.
    6楼正解,你用的是嵌套函数