2019-04-04

WinAPI SetDllDirectory / GetDllDirectory

procedure TForm1.Button1Click(Sender: TObject);
var
  BL: DWORD;
  BF: PWideChar;
begin
  GetMem(BF, sizeof(255));
  SetDllDirectory(PWideChar('C:\\xxx'));
  GetDllDirectory(BL,BF);
  ShowMessage(WideString(BF));
  FreeMem(BF);
end;

2016-02-21

Delphi UTF-8 Conversion Routines

http://docwiki.embarcadero.com/RADStudio/Seattle/en/UTF-8_Conversion_Routines

2016-02-14

dbExpress / dbGO 以TADOConnection / TADODataSet 連結 MS Access 資料庫

ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=資料庫檔案路徑;Mode=Read;Jet OLEDB:Database Password=密碼;';

2016-02-11

以 TPerlRegEx.Replace 替代掉符合樣式的字串

環境:Win7+XE4

uses System.RegularExpressionsCore;
:
procedure TForm1.Button1Click(Sender: TObject);
var
  RE: TPerlRegEx;
  slFile,slTmp: TStringList;
begin
  RE:=TPerlRegEx.Create;
  slFile:=TStringList.Create;
  slTmp:=TStringList.Create;

  slFile.LoadFromFile(FOD1.FileName);
  RE.Subject:=slFile.Text;
  RE.Options:=[preCaseLess];   //忽略大小寫
  slTmp.Delimiter:='|';
  slTmp.Text:=Memo1.Lines.Text;
  RE.RegEx:='([\s|\.|\=|\[])('+slTmp.DelimitedText+')([\s|\.|\]])';

  while RE.MatchAgain do begin
    RE.Replacement:='$1GA00_$2$3';  //也可以 " \ " 替代  " $ " 結果相同
    RE.Replace;
  end;

  FreeAndNil(RE);
  FreeAndNil(slFile);
  FreeAndNil(slTmp);
end;

備註:
TPerlRegEx.ComputeReplacement;   //經樣式運算後的替代字串
TPerlRegEx.MatchedText;                 //符合樣式的字串等同 TPerlRegEx.Groups[0]
TPerlRegEx.Replacement:='';            //經運算後似乎無法讓Replace再利用,所以看使用狀況必須重覆執行

2016-01-25

清除record的方法

TRecord = record
  a: String;
  b: String;
end;

sRecord:=Default(TRecord)

2015-04-06

Google App Engine memcache 測試

環境:

  • Google App Engine - 1.9.18
  • Python-2.7

# -*- coding: utf-8 -*-
#!/usr/bin/env python2.7
import webapp2
import urllib2
import json

from google.appengine.api import memcache
from google.appengine.ext.webapp.util import run_wsgi_app
   
class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
       
        r = urllib2.urlopen('http://mis.twse.com.tw/stock/api/getIndustry.jsp')
        j = json.loads(r.read())
        for n in range(0,len(j['tse'])):
            memcache.add(key=j['tse'][n]['code'], value=j['tse'][n]['name'], namespace='tse')
           
        for n in range(0,len(j['otc'])):
            memcache.add(key=j['otc'][n]['code'], value=j['otc'][n]['name'], namespace='otc')
       
        self.response.out.write(memcache.get(key='01', namespace='tse'))
        self.response.out.write(memcache.get(key='01', namespace='otc'))

2015-02-21

Delphi 讀取證券交易所股票資訊JSON格式

環境:

  • Win7
  • Delphi XE4

uses IdHTTP, Data.DBXJSON;
...
...


procedure TForm1.Button1Click(Sender: TObject);
var
  H: TIdHTTP;
  JSON: String;
  JO: TJSONObject;
  JV: TJSONValue;
  JP: TJSONPair;
begin
  H:=TIdHTTP.Create(nil);
  H.Request.UserAgent:='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)';
  JSON:=H.Get('http://mis.twse.com.tw/stock/api/getStockInfo.jsp?ex_ch=tse_3673.tw');
  JO := TJSONObject.ParseJSONValue(JSON) as TJSONObject;
  JP := JO.Get(0);
  ShowMessage(JP.ToString);
  ShowMessage(JP.JsonString.Value);
  JV:=(JP.JsonValue as TJSONArray).Get(0);
  ShowMessage((JV as TJSONObject).Get('n').JsonValue.Value);
  FreeAndNil(JO);
  FreeAndNil(H);
end;