星期三, 5月 26, 2010

cxgrid要能取消選擇的作法

cxgrid 的optionSelection屬性MultiSelect設為True

cxGDBTV1MouseDown事件設定

procedure TfrmDataSwSelect.cxGDBTV1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i : integer;
begin

i := cxGDBTV1.DataController.FocusedRowIndex;
cxGDBTV1.DataController.ClearSelection; //清除
cxGDBTV1.DataController.SelectRows(i,i);
end;

cxGDBTV1KeyDown事件設定

procedure TfrmDataSwSelect.cxGDBTV1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssShift in Shift) then //shift要失效
Key :=0;
end;

清楚選取用

cxGDBTV1.DataController.ClearSelection;

初始時將cxgrid移到特定的選擇可用

ADOQuery1.First;
if ADOQuery1.Locate('swid', swid, []) then
iIndex := ADOQuery1.RecNo-1
else
iIndex:=-1;
if iIndex>=0 then
cxGDBTV1.DataController.SelectRows(iIndex,iIndex);

星期三, 5月 19, 2010

檢查MDAC2.8是否有安裝

dpr下寫

if not CheckMDACVersionOK( _MDAC_V26 ) then
begin
OneBtnMsgBox(LoginLangInfo.g_saMsg[160], MB_ICONINFORMATION);// 資料庫存取發生錯誤!//請先安裝 MDAC 2.8 或以上版本。
exit;
end;


呼叫到的funcion

uses registry;

const
_MDAC_V26 = '2.6'; //MDAC 2.6 SQL Server 所需

//----------------------------------------------------------------------------//
// CheckMDACVersionOK 檢查MDAC版本是否夠新 //
// 支援postgreSql後改為外部傳參數決定版本 by FBI 2005-1108 //
// 參數: //
// (1) sVer : 檢查版號 //
//----------------------------------------------------------------------------//
function CheckMDACVersionOK(sVer : String):boolean;
var
Reg :TRegistry;
sVersion:string;

begin
Result:=false;
Reg:=TRegistry.Create;
try
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if not Reg.OpenKeyReadOnly('\SOFTWARE\Microsoft\DataAccess') then exit;
sVersion:=Reg.ReadString('FullInstallVer');
if sVersion='' then exit; //讀不到 Key,代表沒安裝MDAC
finally
Reg.Free;
end;
//檢查版本: MS 官方文件限制在 MDAC 2.6 以上。
try
//sVersion:=Copy(sVersion,1,3);
if sVersion < sVer then exit;
except
exit;
end;
Result:=true;
end;

星期二, 5月 18, 2010

cxgrid的header加入右鍵選單

把元件TcxGridPopupMenu拉進來,grid屬性設定好要的cxgrid,onpopup事件加入下面程式碼

uses cxGridStdPopupMenu;

type
TMenuStringForCxGrid = class(TObject)
class procedure HeaderMenuProc(Sender:TObject);
end;

class procedure TMenuStringForCxGrid.HeaderMenuProc(Sender: TObject);
var
HM:TcxGridStdHeaderMenu;
begin
HM:=TcxGridStdHeaderMenu(Sender);
if HM.Items.Count<>17 then exit;
HM.Items[0].Caption:='&遞增排序';//遞增排序
HM.Items[1].Caption:='&遞減排序';//遞減排序
HM.Items[2].Caption:='&取消排序';//取消排序

HM.Items[4].Caption:='&以此欄位分組';//以此欄位分組
HM.Items[5].Caption:='&分組視窗';//分組視窗
HM.Items[6].Visible:=false;
HM.Items[7].Visible:=false;
HM.Items[8].Visible:=false;

HM.Items[10].Caption:='&隱藏此欄位';//隱藏此欄位
HM.Items[11].Caption:='&欄位選擇視窗';//欄位選擇視窗

HM.Items[13].Visible:=false;
HM.Items[14].Caption:='&最適欄寬';//最適欄寬
HM.Items[15].Visible:=false;
HM.Items[16].Caption:='&最適欄寬(所有欄位)';//最適欄寬(所有欄位)

end;

PopCxGridMenuProc(ASenderMenu); //右鍵選單中文化

//這個是呼叫到的funcion
function PopCxGridMenuProc(ASenderMenu: TComponent):boolean;
begin
if ASenderMenu is TcxGridStdHeaderMenu then
TcxGridStdHeaderMenu(ASenderMenu).OnPopup := TMenuStringForCxGrid.HeaderMenuProc;
result:=true;
end;

星期五, 5月 07, 2010

使用stuff將多筆記錄合併成一筆並用逗號分隔


select stuff((select ','+user_name From im_chat_log where id in (1, 2) FOR XML PATH('')),1,1,'' ) as xylist