簡介
· ExtPascal是ExtJS的包裝/綁定。 ExtPascal讓您通過服務器使用ExtJS,使用面向對象Pascal語法命令。這為Web瀏覽器編程語言帶來了結構性以及嚴格的Pascal語法。
· 其主要優點是:
· 使用您喜歡的語言(Object Pascal)的,您有較高的生產力,而不是使用JavaScript和PHP,HTML和/或CSS。
· 使用一個強類型語言的本土和編譯的代碼。也就是說,許多錯誤是由編譯器直接任命,不用浪費時間在瀏覽器中測試。
· 使用代碼完成(智能感知),現在很多IDE都有這個功能(Delphi/lazarus)用來提供更多的生產力。
· 在服務器上集中編程,JavaScript和HTML是動態語言編程,使開發更輕松,更分散。
· 業務規則可以使用Object Pascal封裝在服務器中,而不是在JavaScript中可見。
· 易于在Delphi /lazarus/MSEide / FPIDE調試。
先決條件
· 可選Windows,Linux,MacOS X或FreeBSD的機器。采用英特爾/ AMD的32位和PowerPC已經測試通過,這些處理器同樣也支持FreePascal。
· 可選的網頁瀏覽器:IE 6 +,Firefox 1.5+,Chrome 2 +,Safari 3 +,Opera9 +或其他兼容的瀏覽器。 JavaScript和Cookies應該設置為啟用。
· 下載并安裝Apache 2.2或更高版本,但是Apache 1.3和IIS在ExtPascal工程中使用CGIGateway,見下文。
· 對于本機的FastCGI運行下載和安裝的Apache 2.2的FastCGI。見下面詳細說明。對于通過CGIGateway設置在Apache或IIS FastCGI的見下面詳細說明了。
· 下載ExtJS的3.2.0。
· 在安裝Apache的文檔根目錄下面安裝ExtJS(通常在htdocs中)在文件夾ext,如果您的Apache在D盤,應該是如下設置:
· D:\Apache Software Foundation\Apache2.2\htdocs\ext
·

· 在Windows下安裝Delphi(7..2010)或FreePascal與lazarus0.9.28 +或者MSEide 2.0 + 2.4.0。我曾用過Turbo Delphi,FreePascal 2.2.4和MSEide 2.0。
· 對于POSIX系統(Linux,MacOS下,BSD系統,Solaris等)安裝lazarus0.9.28 +或MSEide 2.0 + FreePascal 2.4.0。我使用FreePascal 2.2.4和MSEide 2.0。
· 使用SVN下載ExtPascal(見說明)工作目錄,例如:C:\ ExtPascal。
· 在ExtPascal包中,復制codepress文件夾,到/htdocs/ext文件夾中。
第一步
01. 使用您喜愛的ObjectPascal IDE打開ExtPascalSamples目錄里面的ExtPascalSamples工程文件。
02. 在 Delphi 設置 Syntax 選項 (菜單 \Project\Options\Compiler):
OFF Strict var-strings
OFF Complete boolean eval
ON Extended syntax
OFF Typed @ operator
ON Open parameters
ON Huge strings/Long strings by default
ON Assignable typed constants
03. 在 Lazarus 設置Parsing options (菜單 \Project\Compiler Options\Parsing):
Syntax mode: 'Delphi'
ON C++ Styled INLINE
ON C Style macros
OFF Constructor name must be init
OFF Static Keyword in Objects
ON Use Ansi Strings
04. 在 FreePascal 或者 MSEide 里面,使用 -Smdghie50 -venwhi -l 作為 compiler 選項.加入這些選項 -O2pPENTIUM4 -CXpPENTIUM4 -XXsi -CfSSE 到 release/final 版本。
05. 編譯ExtPascalSamples
通過CGI gateway設置FastCGI (任何 Apache 版本以及IIS相似過程)
01. 打開CGIGateway.dpr.
02. 如果有必要修改Port constant, 默認 2014.
03. 編譯.
04. 拷貝 CGIGateway.exe 到 cgi-bin 目錄.
05. 打開您的 FastCGI 應用程序 (在這里是 CGIGateway.dpr).
06.有必要可以修改端口, 默認 2014. 在代碼底部:
Application := TFCGIApplication.Create('ExtPascal Samples ' + ExtPascalVersion, TSamples, 2014, 5);
07. 編譯.
08. 拷貝您的 FastCGI 應用程序到 cgi-bin 目錄. 如果是 Posix (non-Windows) 平臺用 .fcgi 擴展名.
09. 把CGIGateway.exe改成 ExtPascalSamples.cgi 或者其他Web Server擴展名作為CGI應用程序。
10. 跑這個例子, 舉例, 在cgi-bin(Apache/cgi-bin)目錄有下面文件:
ExtPascalSamples.exe
// The real FastCGI application. The extension is `.fcgi` for Posix platforms.
ExtPascalSamples.cgi // The CGI Gateway.
11. 可以不在 Apache or IIS配置第11步, 但是我推薦您使用HTTP壓縮來提高性能 (on IIS 也一樣).
12.在瀏覽器中輸入如下地址:
http://localhost/cgi-bin/ExtPascalSamples.cgi
//執行這一步,請先在Apache下設置FastCGI,并啟動Apache
13. ExtPascalSamples.cgi (the gateway) 自動找到 ExtPascalSamples.exe (the real FastCGI application).
在Apache 2.2+設置FastCGI
01. 下載CGI模塊: http://www./dist/mod_fastcgi-2.4.6-AP22.dll
02. 重命名為 mod_fastcgi.so
03. 拷入到Apache目錄 (by example c:\apache\modules)
04. 在 httpd.conf 文件 (Apache's conf folder) in LoadModule session insert the line below:
LoadModule fastcgi_module modules/mod_fastcgi.so
05. 聲明 FastCGI application 作為內部服務, 在 httpd.conf加入如下:
fastcgiexternalserver cgi-bin/ExtPascalSamples –host localhost:2014 –idle-timeout 3
CAUTION: 不要在Google Wiki下粘貼上面的代碼(Google wiki uses the char 150 and the true hifen char is 45).
06. cgi-bin/ExtPascalSamples 是URL,您通過瀏覽器調用 ExtPascal 程序. 拷貝可執行文件到cgi-bin目錄下面并不重要。URL是大小寫敏感的。
07. –host 參數定義了FastCGI application主機 (by example localhost).
08.默認 TCP/IP 端口是 2014, 你可以在源碼中修改,已改變端口.
09. 手工啟動 FastCGI 程序,配置好參數后啟動Apache.
10. 在你的瀏覽器下輸入如下地址:
http://localhost/cgi-bin/ExtPascalSamples
11. 查看FastCGI docs獲取更多信息。
12. 我推薦你使用HTTP 壓縮來提高性能,查看如下文檔 Advanced configuration. --Smartsoft Modify in Guangzhou, 2010-04-13
XAMPP Apache 不兼容mod_fastcgi/ExtPascal?.如果您在第10步遇到 404 error ,請參照 "在Apache 2.2+設置FastCGI", try WampServer? 2 or raw Apache installation.