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';

即可。

其它中文化方式都差不多