JAVA2OP更新

主要是修補缺少的二個檔案
bin\converters\java2op\bootclasses.jar
bin\converters\java2op\bootclasses.xml

下載之後將檔案copy到以下的路徑即可

bin\converters\java2op\bootclasses.jar
bin\converters\java2op\bootclasses.xml

下載路徑:
http://cc.embarcadero.com/Item/30326

Delphi 使用superobject分析JSON

ResizedImage600199-RADJson
http://superobject.googlecode.com

https://github.com/hgourvest/superobject

Delphi從2009才開始支援JSON格式,先前的版本需使用第三方函式庫才能解決。這邊提供不錯的SuperObject給大家。

使用方式很簡單,例如從台北市政府資料開放平台取得臺北市公廁點位資訊

[json]
[{“unit”:”台北市政府環境保護局”,”title”:”公廁坐落:士林官邸”,”dep_content”:”座數:8,特優級:2,優等級:6,普通級:0,加強級:0,無障礙設施”,”address”:”臺北市士林區福林路60號”,”lng”:”121.530152″,”lat”:”25.094898″,”modifydate”:”2013-03-25T17:58:20+08:00″},{“unit”:”台北市政府環境保護局”,”title”:”公廁坐落:天母公園”,”dep_content”:”座數
:1,特優級:0,優等級:1,普通級:0,加強級:0″,”address”:”臺北市士林區中山北路七段219號邊”,”lng”:”121.530071″,”lat”:”25.125855″,”modifydate”:”2015-08-06T00:00:00+08:00″}]
[/json]
[pascal]
uses superobject, supertypes, superxmlparser;

var vjson: Isuperobject;
vitem:Tsuperarray;
i,j:integer;
s:string;
begin
vjson:= so(‘[{"unit":"台北市政府環境保護局","address":"臺北市士林區福林路60號"},{"unit":"台北市政府環境保護局","address":"臺北市士林區中山北路七段219號邊"}]’);
vitem:=vjson.AsArray;
for i:=0 to vitem.Length-1 do begin
memo2.Lines.Add(vitem[i][‘unit’].AsString+’ ‘+vitem[i][‘address’].AsString);
end;
end;
[/pascal]

那如果格式如下
[json]
{“zoo”:”壽山動物園”,”animals”:[{“name”:”猴子”,”years”:”12″},{“name”:”猩猩”,”years”:”5″}]}
[/json]
[pascal]
var vjson: Isuperobject;
vitem:Tsuperarray;
i:integer;
begin
vjson:= so(‘{"zoo":"壽山動物園","animals":[{"name":"猴子","years":"12"},{"name":"猩猩","years":"5"}]}’);
memo2.lines.add(vjson[‘zoo’].asstring);
vitem:= vjson[‘animals’].AsArray;
for i:=0 to vitem.Length -1 do begin
memo1.Lines.Add(vitem[i][‘name’].AsString+’ ‘+vitem[i][‘years’].AsString );
end;
[/pascal]

Delphi XE8使用Microsoft Azure Translator微軟線上翻譯服務

在微軟的Microsoft Azure Marketplace有許多不錯的資料可以應用,今天就分享如果利用XE8搭配Microsoft Translator線上翻譯服務來做翻譯。
一、註冊Azure帳戶

點選 https://datamarket.azure.com/dataset/bing/microsofttranslator 上的登入,使用個人。然後依照步驗註冊就好。
tran002

二、訂閱服務
進入 https://datamarket.azure.com/dataset/bing/microsofttranslator ,點選2000000字元數/月的免費方案註冊。

tran001

tran004

 

tran005 tran006
三、註冊程式
程式中需要client_id跟client_secret ,所以到 https://datamarket.azure.com/developer/applications 註冊程式。

client_id就是用戶端識別碼

client_secret就是用戶端密碼

tran007
四、開始建立程式

新增一個Blank Application

001

接著在上面增加三個元件,TRESTClient、TRESTRequest跟TRESTResponse。重新命名為RESTClientAuthToken、RESTRequestAuthToken跟RESTResponseAuthToken.

002

 

RESTClientAuthToken的BaseURL設定 https://datamarket.accesscontrol.windows.net/v2

003

 

RESTRequestAuthToken的Method改為rmPOST、然後Resource設為OAuth2-13(參考 https://msdn.microsoft.com/en-us/library/hh454950.aspx)

 

004

 

然後在Params增加四個參數如下

 

005

 

在畫面上增加3個label、3個edit以及一個button

 

006

加上程式碼

[pascal]
var
token: string;
begin
RESTRequestAuthToken.Params.ParameterByName(‘client_secret’).Value := EditClient_Secret.Text;
RESTRequestAuthToken.Params.ParameterByName(‘client_id’).Value := EditClient_ID.Text;
RESTRequestAuthToken.Execute;
if RESTResponseAuthToken.GetSimpleValue(‘access_token’,token) then
begin
EditToken_value.Text := token;
end;
[/pascal]

取得Token值後我們可以開始進行翻譯,參考的文件為(https://msdn.microsoft.com/en-us/library/ff512387.aspx),一樣增加三個元件,TRESTClient、TRESTRequest跟TRESTResponse。重新命名為RESTClientTranslate、RESTRequestTranslate跟RESTResponseTranslate.。

RESTClientTranslate的BaseURL設為 http://api.microsofttranslator.com/v2/Http.svc

007

 

接著在RESTRequestTranslate的Resource設為Translate?text={text}&from={from}&to={to}

 

008

一樣在裡面增加四個Params,from跟to需要對應相關的語言代碼(參考https://msdn.microsoft.com/en-us/library/hh456380.aspx

009

在畫面上增加combobox二個,以及二個memo及button。

011

 

開啟view→LiveBindings Designer,將RESTRequestTranslate中的Params.text指到Memo1的Text(輸入),然後RESTResponseTranslate.的Content指向Memo2的Text(輸出)。

010

 

最後補上翻譯的程式碼如下。

[pascal]
RESTRequestTranslate.Params.ParameterByName(‘Authorization’).Value := ‘bearer ‘+EditToken_value.Text;
RESTRequestTranslate.Params.ParameterByName(‘from’).Value := cbFrom.Selected.Text;
RESTRequestTranslate.Params.ParameterByName(‘to’).Value := cbToo.Selected.Text;
RESTRequestTranslate.Execute;
[/pascal]

番外篇:
語音的部份(參考 https://msdn.microsoft.com/en-us/library/ff512420.aspx)
增加一個RESTRequestPlay,然後設定Resource為 speak?text={text}&language={language}&to={to}&format=audio/mp3&options=MinSize 。
三個Param為 Authorization、text、language
以及增加mediaplayer。
程式如下

[pascal]
var
MS: TMemoryStream;
TempFile: string;
begin
RESTRequestPlay.Params.ParameterByName(‘Authorization’).Value := ‘bearer ‘+EditToken_value.Text;
RESTRequestPlay.Params.ParameterByName(‘language’).Value := RESTRequestTranslate.Params.ParameterByName(‘to’).Value;
RESTRequestPlay.Params.ParameterByName(‘text’).Value := RESTResponseTranslate.Content;
RESTRequestPlay.Execute;
MS := TMemoryStream.Create;
try
MS.WriteData(RESTResponsePlay.RawBytes,Length(RESTResponsePlay.RawBytes));
TempFile := TPath.ChangeExtension(TPath.GetTempFileName,’.mp3′);
MS.SaveToFile(TempFile);
MediaPlayer1.FileName := TempFile;
MediaPlayer1.Play;
finally
MS.Free;
end;
end;
[/pascal]

API參考

https://msdn.microsoft.com/en-us/library/dd576287.aspx

程式碼下載

https://drive.google.com/file/d/0BxMN7KkA7p3NZlU5clItaGxiMzQ/view?usp=sharing

原文:
http://blogs.embarcadero.com/stephenball/2015/06/30/using-azure-translator-services-with-delphi/

 

Embarcadero RAD Studio XE8, Delphi XE8, and C++ Builder XE8 Update 1 正式發佈

這次更新分為二種版本,分為有買維護合約且有效期的以及沒有買維護合約的版本。差別如下~

 

General Update 1 Feature and Fix List

This update is provided to XE8 customers without an Update Subscription

Click here for the download.

  • Community toolbar
  • iOS 8 simulator fix
  • Several files missing from the initial XE8 delivery

Subscription Update 1 Features and Fix List

This update is provided to active Update Subscription customers

Click here for the download.

  • Community toolbar
  • Favorites in welcome page
  • Fast search of Bluetooth LE devices
  • iOS 8 simulator support
  • Improved robustness of IDE productivity features
  • Improvements in multi-device previews

延伸連結

Fix List for XE8 Update 1:
http://edn.embarcadero.com/article/44470

法國商使用Delphi結合UV感測器發表智慧型比基尼

法國公司Spinali Design發表了智慧型比基尼泳衣,使用Delphi結合UV 感測器開發app,如果穿載者紫外線過度 提醒穿戴者紫外線過度,並適時提醒補充防曬乳。

在影片中,32秒、40秒及55秒等多處都 可以看到Delphi IDE現身。

新聞網址:
http://www.telegraph.co.uk/news/worldnews/europe/france/11667659/Intelligent-French-bikini-warns-bathers-over-too-much-sun.html

HP機器上執行Rad Studio問題

HP的機器上面安裝Rad Studio後,執行時會出現下面的錯誤訊息。

[Error Error] Invalid PLATFORM variable “BPC”. PLATFORM must be one of the following: “Win32”, “Win64”, “Android”, “iOSSimulator”, “iOSDevice”, or “OSX32”. If PLATFORM is defined by your system’s environment, it must be overridden in the RAD Studio IDE or passed explicitly on the command line to MSBuild; e.g., /p:Platform=Win32.

原因是HP出廠時,在系統變數有一個變數名稱Platform造成Rad Studio出錯。只要將它刪除就行了!

hpradiostudio

Object Pascal Handbook by Marco Cantu 書籍推薦 (內容更新)。

訊息來源:廖啟甫 前輩
Object Pascal Handbook by Marco Cantu 書籍推薦 (內容更新)。
Win32, Win64, MacOSX, iOS and Android 跨平台和移動開發書籍,
合法註冊用戶免費下載。
ID: 30018, Object Pascal Handbook by Marco Cantu
http://cc.embarcadero.com/item/30018
書籍大綱:
Chapter 1: Coding in Pascal
Chapter 2: Variables and Data Types
Chapter 3: Language Statements
Chapter 4: Procedures and Functions
Chapter 5: Arrays and Records
Chapter 6: All About Strings
Chapter 7: Objects
Chapter 8: Inheritance
Chapter 9: Handling Exceptions
Chapter 10: Properties and Events (內容更新)
Chapter 11: Interfaces (內容更新)
Chapter 12: Manipulating Classes (內容更新)
Chapter 14: Generics
Chapter 15: Anonymous Methods
Chapter 16: Reflection and Attributes (內容更新)
Appendix A: The Evolution of Object Pascal
Appendix B: Glossary of Terms (內容更新)

Delphi Xe7開發iOS 8.1.3程式現階段解決方式

最近幾天的iOS版本已經升級到8.1.3了,如果您在開發時遇到

  1. 打開 XE7
  2. 進入 File->Open, 輸入 %AppData% 按Open開啟路徑
  3. 進入到  Embarcadero\BDS\15.0 然後選擇 Entitlement.TemplateiOS 打開
  4. 打開Mac的鑰匙圈管理選擇iPhone Developer certificate然後按右鍵,去看Organizational Unit identifier
  5. 回到Xe7中,在Entitlement.TemplateiOS.xml中加入
  6. [xml]
    <key>application-identifier</key>
    <string>OrganizationalUnit.$(ModuleName)</string>
    [/xml]