2015年12月10日 星期四

Delphi XE8 TFDMemTable的複製

Delphi XE8 內鍵了FireDAC,裡面有一個組件是 TFDMemTable
用起來和TClientDataSet中不多

如果要複製資料到另一個FDMemTable可以用
 
function TForm1.CopyFD(mt: TFDMemTable): TFDMemTable;
begin
  Result := TFDMemTable.Create(nil);
  Result.Data := mt.Data;
end;
相當的簡單

2015年12月9日 星期三

ASP.NET 5/MVC 6 自訂使用Claim驗証

在ASP.NET 5 如果不想用落落長又複雜的 Identity 有另一個簡單的方式

ASP.NET 5 小地雷:新增 Scaffold 項目不見

在VS2015使用ASP.NET 5 RC1發現沒有 新增Controller對話框了



2012年3月3日 星期六

MyDac 5.x 修正ftMemo為空時,變成Null

最近準備升級Mysql 4.x -> 5.5
不小發現元件的一個bug,在Memo型態空值時,變會成null
造成5.5 update會跳出 can not be null
簡單的修正方式如下

DBAccess.pas
3375 行
function TDAParam.GetIsNull: boolean;
begin
  if IsBlobDataType then begin
  if DataType in [ftMemo, ftWideMemo] then Result := false
  else Result := TBlob(FParamObject).Size = 0;//原code是只要size為0就是null
  end else
   Result := inherited IsNull;
end;

2012年2月9日 星期四

Delphi 元件設計注意事項

原本是要繼承TPopupMenu的元件,
功能是會產生Grid常用的一些功能
(如:匯出)
第一步當然是在Create時產生需要的TMenuItem

constructor TSmfCxGridPopupMenu.Create(AOwner: TComponent);
begin
inherited;
_CreateMenuItem(); //產生menuitem
end;

結果執行時間竟然會發現menuitem會重覆出現兩次,
百思不得其解。

經過無數Debug發現,原在設計時期,拉元件到Form時會呼叫一次Create
然後Delphi就很熱心的把Create之後的狀態存在DFM

結果就造成執行時,元件Create後,又會載入DFM的狀態
形成MenuItem重覆

解決方法就是設計時期不呼叫CreateMenuItem();

constructor TSmfCxGridPopupMenu.Create(AOwner: TComponent);
begin
inherited;
// 確定在 Run Time 時才有作用,不然會重覆
if not (csDesigning in ComponentState) then _CreateMenuItem();
end;

DevExpress 6.x 新版 Drag a column header here to group by that column 中文化

稍為追了一下code
新版修改變簡單了
打開 cxGridStrs.pas
裡面就是串字對應的文字
修改

scxGridGroupByBoxCaption = '《托曳欄位至此可群組化》';//'Drag a column header here to group by that column';

即可。

其它中文化方式都差不多

2011年12月12日 星期一

Delphi 泛型轉字串

最近在用泛型寫一些東西,痴心妄想需要以下功能

TTest
<T>.ToString; //不能編譯哦!
begin
Result := f.ToString;
end;

看了半天沒有很好的解決方案
唯一的方式只有這樣
TToString<T> = reference to function(const AValue: T): string;

procedure TForm2.Button1Click(Sender: TObject);
var
gen
: TGenContainer<Integer>;
begin
gen
:= TGenContainer<Integer>.Create(
function(const AValue: Integer): string
begin
Result := IntToStr(AValue);
end);
end;

也就是說必需在傳入一個函式。
這樣有點麻煩就是