echo.lpr 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. program echo;
  2. uses classes,sysutils,cgiapp;
  3. Type
  4. { TMyCgiApplication }
  5. TMyCgiApplication = Class(TCGIApplication)
  6. Public
  7. procedure DoRun; override;
  8. end;
  9. { TMyCgiApplication }
  10. procedure TMyCgiApplication.DoRun;
  11. procedure AddRow(const aName,avalue : string);
  12. begin
  13. AddResponseLn(Format('<tr><td><b>%s</b></td><td>%s</td></tr>',[aName,aValue]));
  14. end;
  15. Var
  16. L : TStrings;
  17. V,N : String;
  18. I : Integer;
  19. begin
  20. Terminate;
  21. EmitContentType;
  22. AddResponseLn('<html>');
  23. AddResponseLn('<body>');
  24. AddResponseLn('<h1>Simple CGI HTML echo demo</h1>');
  25. AddResponseLn('<h2>Request variables</h2>');
  26. AddResponseLn('<table border=1>');
  27. AddRow('Variable','Value');
  28. L:=TStringList.Create;
  29. Try
  30. GetRequestVarList(L);
  31. For I:=0 to L.Count-1 do
  32. begin
  33. L.GetNameValue(I,N,V);
  34. AddRow(N,V);
  35. end;
  36. AddResponseLn('</table>');
  37. AddResponseLn('<h2>CGI variables</h2>');
  38. AddResponseLn('<table border=1>');
  39. AddRow('Variable','Value');
  40. L.Clear;
  41. GetCGIVarList(L);
  42. For I:=0 to L.Count-1 do
  43. begin
  44. L.GetNameValue(I,N,V);
  45. AddRow(N,V);
  46. end;
  47. AddResponseLn('</table>');
  48. AddResponseLn('</body>');
  49. AddResponseLn('</html>');
  50. finally
  51. L.Free;
  52. end;
  53. end;
  54. begin
  55. With TMyCgiApplication.Create(Nil) do
  56. try
  57. Initialize;
  58. Run;
  59. finally
  60. Free
  61. end;
  62. end.