Delphi取得目前檔案位置名稱路徑

[pascal]
// 假如程式路徑在 c:\projects\bin\project1.exe
ShowMessage(‘Drive = ‘+ExtractFileDrive (Application.Exename)); //C:
ShowMessage(‘Dir = ‘+ExtractFileDir (Application.Exename)); //c:\projects\bin
ShowMessage(‘Path = ‘+ExtractFilePath (Application.Exename)); //c:\projects\bin\
ShowMessage(‘Name = ‘+ExtractFileName (Application.Exename)); //project1.exe
ShowMessage(‘OnlyName =’+ChangeFileExt(ExtractFileName(Application.Exename), ”)); //project1
ShowMessage(‘Ext = ‘+ExtractFileExt (Application.Exename)); //.exe
[/pascal]

Delphi&C++Builder的iOS 64-bit Release Plans線上研討會

由於XE7目前仍未支援iOS 64位元的程式編譯功能,但蘋果 App 於 2015年02月01日 上架必須支援 64位元,於是明天(27日)凌晨一點鐘,有一場同步的iOS 64-bit Release Plans線上研討會。如果有時間的朋友可以上網聽一下。

報名網址: http://forms.embarcadero.com/RADiOS64Webinar?cif=701G0000000wIGp

Delphi路徑規劃函數

把上次Delphi結合簡易PHP路徑規劃,搬到XE3來用。
主要運用在
1) 餐飲系統的外送服務
2) 物流系統的地圖服務
發現Delphi XE3不用像上次D7一樣用到urlencode XD
[pascal]
uses IdURI,Vcl.OleCtrls, SHDocVw;
procedure TForm1.RoutePlan(sFrom, sTo: String; wb: TWebBrowser);
var str:String;
begin
str := ‘http://superlevin.ifengyuan.tw/mapapi.php?FROM=’+TIdURI.ParamsEncode(sFrom)+’&TO=’+TIdURI.ParamsEncode(sTo);
wb.Navigate(str);
end;
[/pascal]

台灣健保系統程式開發資源

下午看到一則新聞「區所健保讀卡慢 替代役男解決」,一位替代役男「替區公所改善健保卡讀卡機控制軟體,讓系統自動傳輸資料,以往每年要1個月完成的工作,現在2周就能搞定。」,這位替代役男來頭不小,他正是出身Tagtoo塔圖廣告平台的小Q(Colin Su),部落格本身就藏有許多好文。幸好沒有埋沒他的專長~

回歸正題,整理一下開發跟健保卡相關的程式資料

1) 衛生福利部中央健保局 健保卡資料下載區 http://bit.ly/1A46VMx

2) 醫事憑證管理中心 程式開發專屬網站 http://bit.ly/1BsK8H8

Mac系統上VMware Fusion修改Disk Size出現there is not enough space on the file system for the selected operation

因為虛擬機器上要重新安裝Delphi XE7 update1時空間不足,接著要把Virtual Machine的Disk Size加大後出現了”there is not enough space on the file system for the selected operation”。搞了好久才知道Virtual Disck要加大的容量,系統的可用空間需要大於它,也就是說如果你要從60G加大到70G的話,你的系統可用空間也要有70G以上才行。

Delphi結合簡易PHP路徑規劃

延續上一篇的文章,如何透過Delphi傳遞起訖點就能幫助做路徑規劃呢?透過Delphi的WebBrowser元件搭配遠端的PHP,傳遞參數可以做得到!

PHP的部份,我們主要是要傳遞FROM以及TO二個參數(以下不做解釋XD)
[php]
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>路徑規劃</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var stepDisplay;
var markerArray = [];

function initialize() {
var rendererOptions = {
map: map,
suppressMarkers : true
}
directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
var fengyuan = new google.maps.LatLng(24.253706601916402, 120.72275021093753);
var mapOptions = {
zoom:17,
center: fengyuan
};
map = new google.maps.Map(document.getElementById(‘map-canvas’), mapOptions);
directionsDisplay.setMap(map);
stepDisplay = new google.maps.InfoWindow();
calcRoute();
}

function calcRoute() {
for (i = 0; i < markerArray.length; i++) {
markerArray[i].setMap(null);
}
markerArray = [];
var start = <?php echo ‘"’.($_GET["FROM"]).’"’; ?>;
var end = <?php echo ‘"’.($_GET["TO"]).’"’; ?>;
var request = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.WALKING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
showSteps(response);
}
});
}
function showSteps(directionResult) {
var myRoute = directionResult.routes[0].legs[0];
for (var i = 0; i < myRoute.steps.length; i++) {
var icon = "https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=" + i + "|FF0000|000000";
if (i == 0) {
icon = "https://chart.googleapis.com/chart?chst=d_map_xpin_icon&chld=pin|glyphish_walk|00FFFF|FF0000";
}
var marker = new google.maps.Marker({
position: myRoute.steps[i].start_point,
map: map,
icon: icon
});
attachInstructionText(marker,myRoute.steps[i].instructions);
markerArray.push(marker);
}

var marker = new google.maps.Marker({
position: myRoute.steps[i – 1].end_point,
map: map,
icon: "https://chart.googleapis.com/chart?chst=d_map_xpin_icon&chld=pin|glyphish_walk|ADDE63"
});
markerArray.push(marker);
}
function attachInstructionText(marker, text) {
google.maps.event.addListener(marker, ‘click’, function() {
stepDisplay.setContent(text);
stepDisplay.open(map, marker);
});
}
google.maps.event.addDomListener(window, ‘load’, initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
[/php]









DELPHI的部份,因為D7的URLENCODE有問題,所以我們另尋了一個解決的部份(見延伸閱讀)
[pas]
function HTTPEncode(const AStr: String): String;
const
NoConversion = [‘A’..’Z’,’a’..’z’,’*’,’@’,’.’,’_’,’-‘,’0′..’9′,’$’,’!’,””,'(‘,’)’];
var
Sp, Rp: PAnsiChar;
begin
SetLength(Result, Length(AStr) * 3);
Sp:= PAnsiChar(AStr);
Rp:= PAnsiChar(Result);
while Sp^ <> #0 do
begin
if Sp^ in NoConversion then
Rp^ := Sp^
else
if Sp^ = ‘ ‘ then
Rp^ := ‘+’
else
begin
FormatBuf(Rp^, 3, ‘%%%.2x’, 6, [Ord(Sp^)]);
Inc(Rp,2);
end;
Inc(Rp);
Inc(Sp);
end;
SetLength(Result, Rp – PAnsiChar(Result));
end;
function URLEncode(const Url: String): String;
begin
Result:= HttpEncode(UTF8Encode(Url));
end;
[/pas]
最後在畫面上佈置出二個Edit以及一個Button,以及WebBrowser。程式很簡單
[pas]
procedure TForm1.Button1Click(Sender: TObject);
var
str:WideString;
begin
str := ‘http://你的php位置?FROM=’+URLEncode(edit1.text)+’&TO=’+URLEncode(edit2.text);
self.WebBrowser1.Navigate(str);
end;
[/pas]

延伸閱讀:
Delphi URLEncode問題解決
http://alexey-m.ru/articles/urlencode-utf-8-windows1251

Delphi 7 從健保局下載zip檔案順便解壓縮

由於學校還使用Delphi 7,為了要教同學從網路上下載檔案加上解壓縮費了不少力氣。順便就記錄一下如何從健保局抓下檔案後,然後一道解壓縮。

1.Delphi7沒有壓縮元件,所以要尋求免費的資源。幸好有Opensource的Delphi 7zip元件
網址:https://code.google.com/p/d7zip/
下載之後解壓縮會有三個檔案
7z.dll
readme.html
sevenzip.pas

2.把7z.dll跟sevenzip.pas放到程式目錄下(散佈程式時記得.exe檔跟7z.dll要一起copy)。
3.回到Delphi7的Project→add to project把sevenzip.pas加進專案
4.File→Use Unit選Sevenzip.pas後就可以開始寫code了
5.畫面上佈置如下圖
(text設為http://www.nhi.gov.tw/Resource/webdata/2976_1_hospbsc.zip)
delphi7zip02
6.ButtonClick程式如下
[pascal]
procedure TForm1.Button1Click(Sender: TObject);
var
ms:TMemoryStream;
i:integer;
tempfile,extname,filename1:String;
begin
ms := Tmemorystream.Create;
ms.Clear;
ms.Position :=0;
try
idhttp1.Get(edit1.text,ms);
ms.SaveToFile(ExtractFilePath(Application.ExeName)+’\test.zip’);
except
end;
if fileexists(ExtractFilePath(Application.ExeName)+’\test.zip’) then
begin
with CreateInArchive(CLSID_CFormatZip) do
begin
OpenFile(ExtractFilePath(Application.ExeName)+’\test.zip’);
for i := 0 to NumberOfItems – 1 do
if not ItemIsFolder[i] then begin
tempfile := ItemPath[i];
extname:=ExtractFileExt(tempfile);
if extname =’.txt’ then
filename1:=tempfile;
end;
ExtractTo(ExtractFilePath(Application.ExeName));
end;
Memo1.Lines.LoadFromFile(Filename1);
end;
end;
[/pascal]
藥品健保藥價資料集
P.S idhttp1.HandleRedirects := True;