我新建一个unit,没有窗体的。我想将我收集的一些函数和过程统一写进这个uint中,让他形成一个函数过程库,方便以后直接调用,就不用写代码了。但是在自定义过程的时候报错。我在有窗体的时候用同样的方法自定义过程没错呀,大侠请执教,我是不是少些什么,怎么可以实现,请说得详细些!

解决方案 »

  1.   

    出错的原因痕多,有的是你用到了一些DELPHI自带函数而没有再USES中引用它,还有一些是你传进来的参数和你定义的格式不同,或者你要调用的参数的那个窗体没有USES进来,还有就是你申明的函数或过程前后不一致。总之要仔细检查单步调试才能看出来。
      

  2.   

    给你一段代码,自己看看吧。。
    unit WrBaseValue;interface
    uses
    inifiles,Classes,SysUtils;type
       TLSInfo = record     //记录索的信息
          Sh : integer;
          DS : integer;
          SL : integer;
          GG : integer;
       end;
      TActionType = (atEncryption,atDecryption);
      TTomEncryption = class(TComponent)
      private
        { Private declarations }
        FInputString:string;
        FOutputString:string;
        FHexInputString:string;
        FHexOutputString:string;
        FKeyString:string;
        FAction:TActionType;
        procedure SetInputString(input:string);
        procedure SetOutputString(input:string);
        procedure SetKeyString(input:string);
        Function  EncryptionEngine (Src:String; Key : String; Encrypt : Boolean):String;
      protected
        { Protected declarations }
      public
        { Public declarations }
        constructor Create(AOwner: TComponent);override;
        Procedure Execute;
        function Encry(wAction : TActionType;InputStr: string): string;
      published
        { Published declarations }
        property Input: String read FInputString write SetInputString;
        property Output: String read FOutputString write SetOutputString;
        property Key: String read FKeyString write SetKeyString;
        property Action: TActionType read FAction write FAction default atEncryption;
      end;
       TWRBaseValue = class
           private
           FilePath : String;
           LSCount : integer;
           Encry : TTomEncryption;       inifile : Tinifile;
           public
           LsArray : array of TLSInfo;
           constructor Create;
           destructor Destroy;
           procedure InitLsArrayFromIniFile;   end;var
       BaseValue : TWRBaseValue;implementation
    constructor TWRBaseValue.Create;
    begin
        inherited;
        FilePath := ExtractFilePath(ParamStr(0)) + 'BaseConfig.YAC';
        inifile := TIniFile.Create(FilePath);
        LsCount := 34;
        Encry := TTomEncryption.Create(nil);
        setLength(LsArray,LsCount);
        InitLsArrayFromIniFile;end;destructor TWRBaseValue.Destroy;
    begin
        inherited;
        inifile.Free;
    end;procedure TWRBaseValue.InitLsArrayFromIniFile;
    var
    I : integer;
    begin
       LsCount := inifile.ReadInteger('BaseValue','Count',0);
       SetLength(LsArray,LsCount);
       Encry.Action := atDecryption;   for i := 1 to 34 do
       begin
           Encry.Input := inifile.ReadString('BaseValue','DS'+intTostr(i),'');
           Encry.Execute;
           LsArray[i-1].Sh := i;
           LsArray[i-1].DS := strToint(Encry.Output);
           Encry.Input := inifile.ReadString('BaseValue','SL'+intTostr(i),'');
           Encry.Execute;
           LsArray[i-1].SL := strtoint(Encry.Output);
           LsArray[i-1].GG := inifile.ReadInteger('BaseValue','GG'+intTostr(i),0);
              end;
    end;
      

  3.   

    没有仔细看你的代码
    但是为什么你把过程和函数统统放在private里面?一般来说我会把这些放在public里
      

  4.   

    呵呵,可不是,要想被别的单元引用好像应该是得写在public里吧