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;

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

2011年3月23日 星期三

Delphi TNotifyEvent用參數的問題

本來以為用若名函數可以搞定:
//以下方法不能編譯過
Button1.OnClick := procedure( sender : tobject ) begin
//...code
end;

結果不能通過。
後來找了好久才發現另外一個妙招,Delphi舊版的也可以用

procedure Click(Self : TObject; Sender: TObject);
var lv : TLvItem;
begin
lv := TLvItem(Self);
//.....code..
end;

function _CreateMenuItem(lv : TLvItem):TMenuItem;
var Meth: TMethod;
begin
Meth.Data := lv;
Meth.Code := @Click;
Result.OnClick := TNotifyEvent(Meth);
end;

2010年12月2日 星期四

敗家 WP7 Phone

HTC 7 Mozart

要開始寫程式啦...

2010年3月23日 星期二

Delphi TDictionary 用法


var
aDic : TDictionary;
aEnum : TDictionary.TPairEnumerator;
begin
aEnum := aDic.GetEnumerator;
while (aEnum.MoveNext) do
begin
Memo1.Items.Add(aEnum.Current.Key + ' : ' + IntToStr(aEnum.Current.Value));
end;

方法二

var kvp : TPait<integer,string>
begin
for kvp in FList do begin
//kvp.....
end;
end;