⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demounit.dfm

📁 PIC 单片机 PAS SOURCE CODE SAMPLES
💻 DFM
📖 第 1 页 / 共 5 页
字号:
          '          '#39'  Buffer: array[0..4095] of Char;'#39
          '          '#39'begin'#39
          '          '
          
            '            '#39'  SetString(Result, Buffer, GetEnvironmentVariable(' +
            'PChar(Name), '#39' +'
          '            '#39'Buffer, SizeOf(Buffer)));'#39
          '          '#39'end;'#39
          '          '#39#39
          '          '#39#39
          '          '#39#39
          '          '#39'constructor TidCGIRunner.Create(AOwner: TComponent);'#39
          '          '#39'begin'#39
          '          '#39'  inherited;'#39
          '          '
          
            '            '#39'  FErrorMsg := '#39'#39'#39'<html><body><h1><center>Interna' +
            'l Server Error</b'#39' +'
          '            '#39'ody></html>'#39'#39'#39'#13#10;'#39
          '          '
          
            '            '#39'  FTimeOutMsg := '#39'#39'#39'<html><body><h1><center>Proce' +
            'ss is terminated.'#39' +'
          '            '#39'</body></html>'#39'#39'#39'#13#10;'#39
          '          '#39'  FServerAdmin := '#39'#39'#39'admin@server'#39'#39'#39';'#39
          '          '#39'  FTimeOut := 5000;'#39
          '          '#39'end;'#39
          '          '#39#39
          '          '
          
            '            '#39'function TidCGIRunner.Execute(LocalDoc : string; AT' +
            'hread: TIdPee'#39' +'
          '            '#39'rThread;'#39
          
            '          '#39'                              RequestInfo: TIdHTTPReq' +
            'uestInfo;'#39
          
            '          '#39'                              ResponseInfo: TIdHTTPRe' +
            'sponseInfo;'#39
          
            '          '#39'                              Action : string = '#39'#39#' +
            '39'#39') : integer;'#39
          '          '#39'const'#39
          '          '#39'  FEnv = '#39'#39'#39'%s=%s'#39'#39'#39'#0;'#39
          '          '#39#39
          '          '#39'var'#39
          '          '#39'  ParsLine : string;'#39
          '          '#39'  ParsList : TStringList;'#39
          '          '#39'  I        : integer;'#39
          '          '#39'  hReadPipe,'#39
          '          '#39'  hNIReadPipe,'#39
          '          '#39'  hWritePipe: THandle;'#39
          '          '#39'  saPipe: TSecurityAttributes;'#39
          '          '#39'  StartInfo: TStartupInfo;'#39
          '          '#39'  ProcInfo: TProcessInformation;'#39
          '          '#39'  Params : PThreadParams;'#39
          '          '#39'  ReaderID : Dword;'#39
          '          '#39'  ReaderHandle : THandle;'#39
          '          '#39'  cEnv : String;'#39
          '          '#39#39
          '          '#39'begin'#39
          '          '#39'  cEnv := '#39'#39#39'#39';'#39
          '          '#39'  if Assigned(FServer) then'#39
          '          '
          
            '            '#39'   cEnv :=        Format(FEnv,['#39'#39'#39'SERVER_SOFTWARE' +
            #39'#39'#39', FServer.Server'#39' +'
          '            '#39'Software ]);'#39
          
            '          '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'SERVER_NAME'#39'#39'#39',R' +
            'equestInfo.Host]);;'#39
          '          '
          
            '            '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'SERVER_PROTOCOL'#39 +
            '#39'#39',RequestInfo.Vers'#39' +'
          '            '#39'ion]);'#39
          '          '
          
            '            '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'SERVER_PORT'#39'#39'#39 +
            ',IntToStr(AThread.Con'#39' +'
          '            '#39'nection.Binding.Port)]);'#39
          '          '#39#39
          
            '          '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'GATEWAY_INTERFACE'#39 +
            '#39'#39','#39'#39'#39'CGI/1.1'#39'#'
          '39'#39']);'#39
          '          '
          
            '            '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'REQUEST_METHOD'#39'#' +
            '39'#39',RequestInfo.Comma'#39' +'
          '            '#39'nd]);'#39
          '          '
          
            '            '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'SCRIPT_NAME'#39'#39'#39 +
            ',RequestInfo.Document'#39' +'
          '            '#39']);'#39
          '          '
          
            '            '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'QUERY_STRING'#39'#39' +
            #39',RequestInfo.Unparse'#39' +'
          '            '#39'dParams]);'#39
          '          '#39#39
          '          '
          
            '            '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'REMOTE_ADDR'#39'#39'#39 +
            ',RequestInfo.RemoteIP'#39' +'
          '            '#39']);'#39
          '          '#39#39
          '          '#39'  //Win32 fields'#39
          '          '
          
            '            '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'SystemRoot'#39'#39'#39',' +
            'getenv('#39'#39'#39'SystemRoot'#39'#'
          '39'#39')]'#39' +'
          '            '#39');'#39
          
            '          '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'COMSPEC'#39'#39'#39',geten' +
            'v('#39'#39'#39'COMSPEC'#39'#39'#39')]);'#39
          
            '          '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'WINDIR'#39'#39'#39',getenv' +
            '('#39'#39'#39'WINDIR'#39'#39'#39')]);'#39
          
            '          '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'PATH'#39'#39'#39',getenv('#39 +
            '#39'#39'PATH'#39'#39'#39')]);'#39
          
            '          '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'PATH_INFO'#39'#39'#39', Ac' +
            'tion]);'#39
          '          '
          
            '            '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'PATH_TRANSLATED'#39 +
            '#39'#39',ExpandFileName(D'#39' +'
          '            '#39'ocumentRoot + Action)]);'#39
          '          '#39#39
          '          '#39'  //Add HTTP_ fields'#39
          
            '          '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'HTTP_ACCEPT'#39'#39'#39','#39 +
            '#39'#39'*/*'#39'#39'#39']);'#39
          '          '#39#39
          '          '#39'  //Apache fields'#39
          '          '
          
            '            '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'SERVER_ADDR'#39'#39'#39 +
            ',AThread.Connection.B'#39' +'
          '            '#39'inding.IP]);'#39
          
            '          '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'DOCUMENT_ROOT'#39'#39'#39 +
            ',DocumentRoot]);'#39
          
            '          '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'SERVER_ADMIN'#39'#39'#39',' +
            'ServerAdmin]);'#39
          
            '          '#39'  cEnv := cEnv + Format(FEnv,['#39'#39'#39'SCRIPT_FILENAME'#39'#3' +
            '9'#39','#39'#39#39'#39']);'#39
          '          '#39#39
          '          '#39'  cEnv := cEnv + #0;'#39
          '          '#39#39
          '          '#39'  Params := nil;'#39
          '          '#39'  ReaderHandle := 0;'#39
          '          '#39'  saPipe.bInheritHandle := True;'#39
          '          '#39'  saPipe.lpSecurityDescriptor := nil;'#39
          '          '#39'  saPipe.nLength := SizeOf(saPipe);'#39
          '          '#39#39
          
            '          '#39'  if not CreatePipe(hReadPipe,hWritePipe,@saPipe,0) t' +
            'hen'#39
          '          '#39'    RaiseLastWin32Error;'#39
          '          '#39#39
          '          '#39'  FillChar(StartInfo,SizeOf(StartInfo),0);'#39
          '          '#39#39
          '          '#39'  StartInfo.dwFlags:= STARTF_USESTDHANDLES  or'#39
          '          '#39'                      STARTF_USESHOWWINDOW;'#39
          '          '#39'  StartInfo.wShowWindow:=SW_HIDE;'#39
          '          '#39'  StartInfo.hStdOutput := hWritePipe;'#39
          '          '#39'  StartInfo.hStdError  := hWritePipe;'#39
          '          '#39'  StartInfo.cb:=SizeOf(StartInfo);'#39
          '          '#39#39
          '          '#39#39
          '          '#39'try'#39
          '          '#39'  if not DuplicateHandle( GetCurrentProcess,'#39
          '          '#39'                          hReadPipe,'#39
          '          '#39'                          GetCurrentProcess,'#39
          '          '#39'                          @hNIReadPipe,'#39
          '          '#39'                          0,'#39
          '          '#39'                          False,'#39
          
            '          '#39'                          DUPLICATE_SAME_ACCESS) then' +
            #39
          '          '#39'       begin'#39
          '          '#39'        ResponseInfo.ContentText := FErrorMsg;'#39
          '          '
          
            '            '#39'        ResponseInfo.ContentLength := Length(Respon' +
            'seInfo.Conten'#39' +'
          '            '#39'tText);'#39
          '          '#39'        ResponseInfo.ResponseNo := 500;'#39
          '          '#39'        Result :=  ResponseInfo.ContentLength;'#39
          '          '#39'        Exit;'#39
          '          '#39'       end;'#39
          '          '#39#39
          '          '#39'  CloseHandle(hReadPipe);'#39
          '          '#39#39
          '          '#39'  New(Params);'#39
          '          '#39'  Params^.hReadPipe := hNIReadPipe;'#39
          '          '#39#39
          '          '#39#39
          '          '#39'  ReaderHandle := CreateThread( nil,'#39
          '          '#39'                                0,'#39
          '          '#39'                                @ThreadRead,'#39
          '          '#39'                                Params,'#39
          '          '#39'                                0,'#39
          '          '#39'                                ReaderId);'#39
          '          '#39'  if ReaderHandle = 0 then'#39
          '          '#39'   begin'#39
          '          '#39'     ResponseInfo.ContentText := FTimeOutMsg;'#39
          '          '
          
            '            '#39'     ResponseInfo.ContentLength := Length(ResponseI' +
            'nfo.ContentTe'#39' +'
          '            '#39'xt);'#39
          '          '#39'     ResponseInfo.ResponseNo := 500;'#39
          '          '#39'     Result :=  ResponseInfo.ContentLength;'#39
          '          '#39'     Exit;'#39
          '          '#39'   end;'#39
          '          '#39#39
          '          '#39#39
          '          '#39'  if CreateProcess(nil,'#39
          '          '#39'                   PChar(LocalDoc),'#39
          '          '#39'                   nil,'#39
          '          '#39'                   nil,'#39
          '          '#39'                   True,'#39
          '          '#39'                   0,'#39
          '          '#39'                   PChar(cEnv),'#39
          '          '#39'                   nil,'#39
          '          '#39'                   StartInfo,'#39
          '          '#39'                   ProcInfo)'#39
          '          '#39'  then'#39
          '          '#39'    begin'#39
          '          '#39'      CloseHandle(ProcInfo.hThread);'#39
          '          '#39'      CloseHandle(hWritePipe);'#39
          '          '#39'    end'#39
          '          '#39'  else'#39
          '          '#39'   begin'#39
          '          '#39'     ResponseInfo.ContentText := FTimeOutMsg;'#39
          '          '
          
            '            '#39'     ResponseInfo.ContentLength := Length(ResponseI' +
            'nfo.ContentTe'#39' +'
          '            '#39'xt);'#39
          '          '#39'     ResponseInfo.ResponseNo := 500;'#39
          '          '#39'     Result :=  ResponseInfo.ContentLength;'#39
          '          '#39'     Exit;'#39
          '          '#39'   end;'#39
          '          '#39#39
          '          '#39#39
          '          '
          
            '            '#39'  if WaitForSingleObject(ReaderHandle, FTimeOUT) = ' +
            'WAIT_TIMEOUT '#39' +'
          '            '#39'then'#39
          '          '#39#39
          '          '#39'     begin'#39
          '          '#39'        TerminateThread(ReaderHandle,0);'#39
          '          '#39'        TerminateProcess(ProcInfo.hProcess, 1);'#39
          '          '#39'        ResponseInfo.ContentText := FTimeOutMsg;'#39
          '          '
          
            '            '#39'        ResponseInfo.ContentLength := Length(Respon' +
            'seInfo.Conten'#39' +'
          '            '#39'tText);'#39
          '          '#39'        ResponseInfo.ResponseNo := 500;'#39
          '          '#39'        Result :=  ResponseInfo.ContentLength;'#39
          '          '#39'        Exit;'#39
          '          '#39'     end;'#39
          '          '#39#39
          '          '#39#39
          '          '#39'   ParsLine := Params^.s;'#39
          '          '#39'   I := Pos(#13#10#13#10,Params^.s);'#39
          '          '#39'   if i > 0 then'#39
          '          '#39'    begin'#39
          '          '#39'      ParsLine := Copy(ParsLine,1,I+3);'#39
          '          '
          
            '            '#39'      ParsLine := StringReplace(ParsLine,'#39'#39'#39': '#39'#3' +
            '9'#39','#39'#39'#39'='#39'#39'#39','
          '[rfReplaceAll]'#39' +'
          '            '#39');'#39
          '          '#39'      ParsList := TStringList.Create;'#39
          '          '#39'      ParsList.Text := ParsLine;'#39
          '          '
          
            '            '#39'      ResponseInfo.ContentType   := ParsList.Values' +
            '['#39'#39'#39'content-typ'#39' +'
          '            '#39'e'#39'#39'#39'];'#39
          '          '
          
            '            '#39'      ResponseInfo.ResponseNo    := StrToIntDef(Cop' +
            'y(ParsList.Va'#39' +'
          '            '#39'lues['#39'#39'#39'status'#39'#39'#39'],1,3),200);'#39
          '          '#39'      ResponseInfo.WriteHeader;'#39
          '          '
          
            '            '#39'      ResponseInfo.ContentText   := Copy(Params^.s,' +
            'I+4, Length(P'#39' +'
          '            '#39'arams^.s));'#39
          '          '#39'      ParsList.Free;'#39
          '          '#39'     end'#39
          '          '#39'       else'#39
          '          '#39'         begin'#39
          
            '          '#39'           ResponseInfo.ContentType := '#39'#39'#39'text/html' +
            #39'#39'#39';'#39
          '          '#39'         end;'#39
          '          '#39#39
          '          '#39'   Result :=  ResponseInfo.ContentLength;'#39
          '          '#39#39
          '          '#39'  finally'#39
          '          '#39'    if ReaderHandle > 0 then'#39
          '          '#39'       CloseHandle(ReaderHandle);'#39
          '          '#39'    if ProcInfo.hProcess > 0 then'#39
          '        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -