请问我这样把一些信息写进一个文本文件

解决方案 »

  1.   

    unit U_function;interface
      uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;  //private {the no function or procedure}  //public{the function have not override object}
        Function GetLocalHostName:string;
        Function CodeChangeToName(Tablename,Code:string):string;
        Function NameChangeToCode(Cname:string):string;
        procedure DownloadCodeTable(Tablename,param: string);
        type TuserInfo=Class(Tobject)
           private
           public
             Procedure CreateUserFile(servername:string; username:string; password:string;F:boolean);
             procedure CloseUserFile;
             Function Getusername:string;
             Function Getuserpass:string;
             Function GetServername:string;
             function GetF:boolean;
        end;
        type TuserRec=packed record
          LinkServer:string[40];
          userpassword:string[20];
          username:string[20];
          F:boolean;
        end;    var
        userinfo:Tuserinfo;
        userRec:TUserRec;
        userinfofile:file of TuserRec;
        oldvalue:string;
        DMValue,MCValue:string;
        TNValue,FieldName:string;
        LABEL_MC:string;
    implementation
        uses U_DM,U_Link;
      //获取本机的名称
      Function GetLocalHostName:string;
      var
      ComputerName:pchar;
      Size: Cardinal;
      Re:Boolean;
      begin
         Size := MAX_COMPUTERNAME_LENGTH+1;
         Getmem(ComputerName,Size);
         {retrieve computer name}
         Re:=GetComputerName(ComputerName, Size);
         if re then
            result := StrPas(Computername)
         else Showmessage('Computer Name Not Found');
         Freemem(ComputerName);
      end;  Function CodeChangeToName(Tablename,Code:string):string;
      var
        SQLSTR:string;
      begin
        SQLSTR:='select MC From '+tablename+' where Rtrim(Ltrim(DM))='''+trim(CODE)+'''';
        DM.DM_query.Data:=DM.DM_query.DataRequest(SQLSTR);
        DM.DM_query.open;
        if DM.DM_query.RecordCount=0 then
        result:=''
        else begin
               DM.DM_query.first;
               if not DM.DM_query.Fields[0].IsNull then
               result:=DM.DM_query.Fields[0].AsString
               else result:='';
             end;
      end;  Function NameChangeToCode(Cname:string):string;
      begin
      end;
      procedure DownloadCodeTable(Tablename,param: string);
      var
        SQLSTR:string;
      begin
        SQLSTR:='select DM,MC From '+tablename+' where Rtrim(Ltrim(DM)) like'+'''%'+trim(Param)+'%'' or rTrim(Ltrim(MC)) like'+'''%'+trim(param)+'%''';
        DM.DM_query.Data:=DM.DM_query.DataRequest(SQLSTR);
        DM.DM_query.open;
      end;
    { TuserInfo }procedure TuserInfo.CloseUserFile;
    begin
        closefile(userinfofile);
    end;procedure TuserInfo.CreateUserFile(servername:string; username:string; password:string; F:boolean);
    var
      path:string;
    begin
       path:=extractfilepath(application.ExeName)+'\userinfo\';
       if NOT directoryExists(path) then
       CreateDir(path);
       AssignFile(userinfofile,path+'userinfo.dat');
       rewrite(userinfofile);
       userRec.LinkServer:=servername;
       userRec.username:=username;
       userRec.F:=F;
       if F then
       userrec.userpassword:=password
       else  userrec.userpassword:='';
       write(userinfofile,userRec);
       closefile(userinfofile);
    end;function TuserInfo.GetF: boolean;
    var
      path:string;
    begin
      path:=extractfilepath(application.ExeName)+'\userinfo\';
      AssignFile(userinfofile,path+'userinfo.dat');
      reset(userinfofile);
      seek(userinfofile,0);
      read(userinfofile,userRec);
      result:=userRec.F;
      closefile(userinfofile);
    end;function TuserInfo.GetServername: string;
    var
      path:string;
    begin
      path:=extractfilepath(application.ExeName)+'\userinfo\';
      AssignFile(userinfofile,path+'userinfo.dat');
      reset(userinfofile);
      seek(userinfofile,0);
      read(userinfofile,userRec);
      result:=trim(userRec.LinkServer);
      closefile(userinfofile);
    end;function TuserInfo.Getusername: string;
    var
      path:string;
    begin
      path:=extractfilepath(application.ExeName)+'\userinfo\';
      AssignFile(userinfofile,path+'userinfo.dat');
      reset(userinfofile);
      seek(userinfofile,0);
      read(userinfofile,userRec);
      result:=trim(userRec.username);
      closefile(userinfofile);
    end;function TuserInfo.Getuserpass: string;
    var
      path:string;
    begin
      path:=extractfilepath(application.ExeName)+'\userinfo\';
      AssignFile(userinfofile,path+'userinfo.dat');
      reset(userinfofile);
      seek(userinfofile,0);
      read(userinfofile,userRec);
      result:=trim(userRec.userpassword);
      closefile(userinfofile); 
    end;end.