![DELPHI8操作符重載的例子_第1頁(yè)](http://file4.renrendoc.com/view10/M03/25/10/wKhkGWWVDROAGCfNAAFlA6Jd0Hs676.jpg)
![DELPHI8操作符重載的例子_第2頁(yè)](http://file4.renrendoc.com/view10/M03/25/10/wKhkGWWVDROAGCfNAAFlA6Jd0Hs6762.jpg)
![DELPHI8操作符重載的例子_第3頁(yè)](http://file4.renrendoc.com/view10/M03/25/10/wKhkGWWVDROAGCfNAAFlA6Jd0Hs6763.jpg)
![DELPHI8操作符重載的例子_第4頁(yè)](http://file4.renrendoc.com/view10/M03/25/10/wKhkGWWVDROAGCfNAAFlA6Jd0Hs6764.jpg)
![DELPHI8操作符重載的例子_第5頁(yè)](http://file4.renrendoc.com/view10/M03/25/10/wKhkGWWVDROAGCfNAAFlA6Jd0Hs6765.jpg)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
DELPHI8操作符重載的例子
unitWinForm;
interface
uses
System.Drawing,System.Collections,System.ComponentModel,
System.Windows.Forms,System.Data;
type
TWinForm=class(System.Windows.Forms.Form)
{$REGIONVDesignerManagedCode\'}
strictprivate
///
IIIRequireddesignervariable.
Ill
Components:System.ComponentModel.Container;
Buttonl:System.Windows.Forms.Button;
III
IIIRequiredmethodforDesignersupport-donotmodify
///thecontentsofthismethodwiththecodeeditor.
///
procedureInitializeComponent;
procedureButtonl_Click(sender:System.Object;e:System.EventArgs);
{$ENDREGION}
strictprotected
III
IIICleanupanyresourcesbeingused.
Ill
procedureDispose(Disposing:Boolean);override;
private
{PrivateDeclarations}
public
constructorCreate;
end;
〃寫成類也可以,這里我用了記錄。由于記錄是值類型省去了創(chuàng)建實(shí)例的麻煩
TCIassTest=record
public
FA:Integer;
〃重載了操作符
classoperatoradd(A,B:TCIassIest):TCIassTest;
end;
[assembly:RuntimeRequiredAttribute(TypeOf(TWinForm))]
implementation
{$REGIONVWindowsFormDesignergeneratedcode\'}
///
IIIRequiredmethodforDesignersupport-donotmodify
///thecontentsofthismethodwiththecodeeditor.
///
procedureTWinForm.InitializeComponent;
begin
Self.Buttonl:=System.Windows.Forms.Button.Create;
Self.SuspendLayout;
//
//Buttonl
//
Self.Buttonl.Location:=System.Drawing.Point.Create(96,88);
Self.Buttonl.Name:=\'Buttonl\';
Self.Buttonl.Size:=System.Drawing.Size.Create(392,112);
Self.Buttonl.Tablndex:=0;
Self.Buttonl.Text:=\'Buttonl\';
lnclude(Self.Buttonl.Click,Self.Buttonl_Click);
//
//TWinForm
//
Self.AutoScaleBaseSize:=System.Drawing.Size.Create(6,14);
Self.ClientSize:=System.Drawing.Size.Create(560,357);
Self.Controls.Add(Self.Buttonl);
Self.Name:=\'TWinForm\';
Self.Text:=\'WinForm\';
Self.ResumeLayout(False);
end;
{$ENDREGION}
procedureTWinForm.Dispose(Disposing:Boolean);
begin
ifDisposingthen
begin
ifComponents<>nilthen
Components.Dispose();
end;
inheritedDispose(Disposing);
end;
constructorTWinForm.Create;
begin
inheritedCreate;
//
//RequiredforWindowsFormDesignersupport
//
InitializeComponent;
//
//TODO:AddanyconstructorcodeafterInitializeComponentcall
//
end;
procedureTWinForm.Buttonl_Click(sender:System.Object;e:System.EventArgs);
var
A,B,C.TCIassIest;
begin
A.FA:=1;
B.FA:=2;
C:=A+B;〃兩個(gè)結(jié)構(gòu)(或者類)用+操作,在DELHI8以前是不可想象的
system.Windows.Forms.MessageBox.Show(System.Convert.TDString(C.FA));
end;
{TCIassTest}
〃重載“+”操作符的實(shí)現(xiàn)
classoperatorTCIassTest.add(A,B:TCIassTest):TCIassTest;
begin
Result.FA:=A.FA+B.FA;
end;
end.
delphitree從一個(gè)表復(fù)制到另一個(gè)表
由于TREE從源表復(fù)制到目標(biāo)表的ID號(hào)與PARENT會(huì)變化,故不能單純的復(fù)制數(shù)據(jù),還要將
ID與PARENT的結(jié)構(gòu)關(guān)系復(fù)制到目標(biāo)表。
因此我們用遞歸操作。
由于myquery的數(shù)據(jù)會(huì)變動(dòng),全國(guó)計(jì)算機(jī)等級(jí)考試網(wǎng),加入收藏我們要實(shí)時(shí)創(chuàng)建
myquery。
下面是delphitree從一個(gè)表復(fù)制到另一個(gè)表的遞歸源碼:
ProcedureTfrm_SysDepasManager.CopyTree(socParent,desParent:integer);〃樹遞歸復(fù)制
過程
Var
myquery:TADOQuery;
mysoc,mydes:integer;
Begin
myquery:=Tadoquery.Create(Nil);
Try
myquery.Connection:=frmdata.ADOConnectionl;
myquery.Active:=false;
myquery.SQL.CIear;
myquery.SQL.Add('select*fromLCConstDepawhereparent='+inttostr(socParent));
myquery.Active:=true;
〃插記錄
WhileNotmyquery.EofDo
Begin
mysoc:=myquery.FieldByName('ID').Aslnteger;
ReDataSet2.Append;
ReDataSetZ.FieldByNameCshlid'J.AsInteger:=Syspublic.LoginSchoollD;
ReDataSetZ.FieldByNameCnameyAsString:=myquery.FieldByName(*name').AsString;
ReDataSet2.FieldByName('pinyin)AsString:=myquery.FieldByName('pinyin').AsString;
ReDataSet2.FieldByName('parent').Aslnteger:=desParent;
ReDataSet2.Post;
mydes:=ReDataSet2.FieldByName('ID').Aslnteger;
CopyTree(mysoc,mydes);
myquery.Next;
End;
Finally
myquery.Free;
End;
End;
Delphi實(shí)現(xiàn)對(duì)注冊(cè)表的監(jiān)視和掃描
Delphi自帶的TRegistry類只能實(shí)現(xiàn)注冊(cè)表的基本操作,如果我們要實(shí)時(shí)監(jiān)視注冊(cè)表的變化
或者掃描注冊(cè)表特定項(xiàng)下的所有子項(xiàng),TRegistry類就無(wú)能為力了。我啃了半天SDK,終于實(shí)
現(xiàn)了Delphi對(duì)注冊(cè)表的監(jiān)視與掃描,不敢獨(dú)享,拿來(lái)獻(xiàn)給廣大的Delphi愛好者。
監(jiān)視注冊(cè)表相關(guān)項(xiàng)的改變要用到一個(gè)API:RegNotifyChangeKeyValue,
LONGRegNotifyChangeKeyValue(
HKEYhKey,//要監(jiān)視的一個(gè)項(xiàng)的句柄
BOOLbWatchSubtree,//是否監(jiān)視此項(xiàng)的子鍵
DWORDdwNotifyFilter;//監(jiān)視哪些變化
HANDLEhEvent,//接受注冊(cè)表變化事件的事件對(duì)象句柄
BOOLfAsynchronous//注冊(cè)表變化前報(bào)告還是注冊(cè)表變化后才報(bào)告
);
注意上面的hEvent是接受注冊(cè)表變化事件的事件對(duì)象句柄,我們要用API:CreateEvent
來(lái)創(chuàng)建一個(gè)系統(tǒng)事件對(duì)象。
HANDLECreateEvent(
LPSECURITY_ATTR1BUTESIpEventAttributes,//SECURITY_ATTRIBUTES結(jié)構(gòu)
BOOLbManualReset,//是否自動(dòng)重置
BOOLblnitialState,//是否設(shè)置初始狀態(tài)
LPCTSTRIpName//事件對(duì)象的名稱
);
新建一個(gè)工程,添加一個(gè)ListBox,兩個(gè)Buttono
〃先寫個(gè)監(jiān)視注冊(cè)表的例子
〃監(jiān)視HKEY_CURRENT_USER\\Software項(xiàng)下所有子鍵
procedureTForml.ButtonlClick(Sender:TObject);
var
hNotify:THandle;
hKeyx:HKEY;
dwRes:DWORD;
begin
hNotify:=CreateEvent(nil,〃不使用SECURITY_ATTRIBUTES結(jié)構(gòu)
FALSE,〃不自動(dòng)重置
TRUE,〃設(shè)置初始狀態(tài)
\'RegistryNotify\,〃事件對(duì)象的名稱
);
ifhNotify=0then
begin
Showmessage(\,CreateEventfailed.、');
exit;
end;
ifRegOpenKeyEx(HKEY_CURRENT_USER,〃跟鍵
\'Software、',〃子鍵
0,//reserved
KEY_NOTIFY〃監(jiān)視用
hKeyx〃保存句柄
)<>ERROR_SUCCESSthen
begin
CloseHandle(hNotify);
Showmessage(\,RegOpenKeyExfailed.、');
exit;
end;
ifRegNotifyChangeKeyValue(hKeyx,//監(jiān)視子鍵句柄
TRUE,〃監(jiān)視此項(xiàng)的子鍵
REG_NOTIFY_CHANGE_NAMEorREG_NOTIFY_CHANGE_LAST_SE7;
hNotify,〃接受注冊(cè)表變化事件的事件對(duì)象句柄
TRUE〃注冊(cè)表變化前報(bào)告
)<>ERROR_SUCCESSthen
begin
CloseHandle(hNotify);
RegCloseKey(hKeyx);
Showmessage(\,RegNotifyChangeKeyValuefailed\,);
exit;
end;
dwRes:=WaitForSingleObject(hNotify,60*1000);〃監(jiān)視一分鐘
ifdwRes=0then
Showmessage(\'Registrywillbechanged.\,);
CloseHandle(hNotify);
RegCloseKey(hKeyx);
end;
要注意的是,API:WaitForSingleObject要等到注冊(cè)表變化事件發(fā)生或者超時(shí)才會(huì)返回,
在此期間我們的程序?qū)⑹ロ憫?yīng)。解決的辦法是新建一個(gè)線程,在新線程中監(jiān)視注冊(cè)表。
對(duì)注冊(cè)表進(jìn)行掃描要用到另外兩個(gè)API:RegEnumKey和RegEnumValue。
LONGRegEnumKey(
HKEYhKey,//要掃描的注冊(cè)表項(xiàng)目句柄
DWORDdwlndex,//要掃描的subkey序號(hào)
LPTSTRIpName,//要掃描的subkey名稱
LPDWORDIpcbName,//要掃描的subkey名稱占用空間
);
此函數(shù)的使用方法是:首先給dwlndex賦值0,調(diào)用RegEnumKey;然后Inc(dwlndex),再
調(diào)用RegEnumKey,直到返回值為ERROR_NO_MORE」TEMS,表示沒有更多的子項(xiàng)了。
〃掃描注冊(cè)表的例子
〃只演示了如何枚舉HKEY_CURRENT_USER\\Software下的一層子項(xiàng)
procedureTForml.Button2Click(Sender:TObject);
var
buf:array[0..255]ofchar;
iRes:integer;
hKeyx:HKEY;
dwlndex,dwSize:DWORD;
begin
ifRegOpenKeyExfHKEY_CURRENT_USER,\'Software\,,0,KEY_READor
KEY_ENUMERATE_SUB_KEYS,hKeyx)<>ERROR_SUCCESSthen
begin
ShowmessagefX,RegOpenKeyExfailed.、');
exit;
end;
dwlndex:=0;
repeat
dwSize:=255;
iRes:=RegEnumKey(hKeyx,dwlndex,buf,dwSize);
ifiRes=ERROR_NO_MORE_ITEMSthen
break
elseifiRes=ERROR_SUCCESSthen
begin
Listboxl.ltems.Add(buf);
lnc(dwlndex);
end;
untiliRes<>ERROR__SUCCESS;
RegCloseKey(hKeyx);
end;
try
ifNTNetGetDCName(nil,nil,pDomain)=0then
Result:=WideCharToString(pDomain);
finally
NTNetApiBufferFree(pDomain);
end;
finally
FreeLibrary(Libhandle);
end;
end;
functionGetDomainName:AnsiString;
type
WKSTAJNFO_100=record
wkilOO_platform_id:Integer;
wkilOO_computername:PWideChar;
wkilOOJangroup:PWideChar;
wkilOO_ver_major:Integer;
wkilOO_ver_minor:Integer;
end;
WKSTA_USER_INFO_1=record
wkuil__username:PChar;
wkuiljogon_domain:PChar;
wkuil_logon_server:PChar;
wkuil_oth_domains:PChar;
end;
type
//Win9XANSIprototypesfromRADMIN32.DLLandRLOCAL32.DLL
TWin95_NetUserGetlnfo=function(ServerName,UserName:PChar;Level:DWORD;var
BfrPtr:Pointer):Integer;
stdcall;
TWin95_NetApiBufferFree=function(BufPtr:Pointer):Integer;
stdcall;
TWin95_NetWkstaUserGetlnfo=function(Reserved:PChar;Level:Integer;var
BufPtr:Pointer):Integer;
stdcall;
//WinNTUNICODEequivalentsfromNETAPI32.DLL
TWinNT_NetWkstaGetlnfo=function(ServerName:PWideChar;level:Integer;var
BufPtr:Pointer):Integer;
stdcall;
TWinNT_NetApiBufferFree=function(BufPtr:Pointer):Integer;
stdcall;
var
Win95_NetUserGetlnfo:TWin95_NetUserGetlnfo;
Win95_NetWkstallserGetlnfo:TWin95_NetWkstallserGetlnfo;
Win95_NetApiBufferFree:TWin95_NetApiBufferFree;
WinNT_NetWkstaGetlnfo:TWinNT_NetWkstaGetlnfo;
WinNT_NetApiBufferFree:TWinNT_NetApiBufferFree;
WSNT:AWKSTA_INFO_100;
WS95:AWKSTA_USER_INFO_1;
EC:DWORD;
hNETAPI:THandle;
begin
try
Result:=\';
ifIsWinNTthen
begin
hNETAPI:=LoadLibrary(\,NETAPI32.DLL、');
ifhNEIAPIoOthen
begin@WinNT_NetWkstaGetlnfo:=GetProcAddress(hNETAPI,\?NetWkstaGetlnfo\J);
@WinNT_NetApiBufferFree:=GetProcAddress(hNETAPI,\?NetApiBufferFree\T);
EC:=WinNT_NetWkstaGetlnfo(nilz100,Pointer(WSNT));
ifEC=0then
begin
Result:=WideCharToString(WSNTA.wkilOOJangroup);
WinNT_NetApiBufferFree(Pointer(WSNT));
end;
end;
end
else
begin
hNETAPI:=LoadLibrary(\,RADMIN32.DLL、');
ifhNETAPI<>Othen
begin@Win95_NetApiBufferFree:=GetProcAddress(hNETAPI,\?NetApiBufferFree\J);
@Win95_NetUserGetlnfo:=GetProcAddressfhNETAPI,NetUserGetlnfoA\,);
EC:=Win95_NetWkstaUserGetlnfo(nil,1,Pointer(WS95));
ifEC=0then
begin
Result:=WS95A.wkuil_logon_domain;
Win95__NetApiBufferFree(Pointer(WS95));
end;
end;
end;
finally
ifhNETAPI<>0then
FreeLibrary(hNETAPI);
end;
end;
functionAppendShareResource(ServerName/FilePathzNetName/Remark:string):Integer;
var
Shlnfo:TSHARE_INFO_502;
parm_err:PDWORD;
_FilePath/_NetName/_Remark:PWideChar;
_ServerName:Pchar;
LibHandle:THandle;
begin
LibHandle:=LoadLibrary(NTIib);
ifLibHandle=0then
raiseException.Create(\,Unabletomaplibrary:\'+NTlib);
try
,
@NTNetShareAdd:=GetProcAddress(Libhandle/NetShareAdd\);
分配內(nèi)存
GetMem(__ServerNamez255);//
GetMem(_FilePath,255);
GetMem(_NetName,255);
GetMem(_Remarkz255);
StringToWideChar(FilePath,_FilePath,255);〃字符串轉(zhuǎn)換,一定要轉(zhuǎn)換正確
StringToWideChar(NetName,_NetName,255);
StringToWideChar(Remark,_Remark,255);
strpcopy(_ServerName,ServerName);
〃開始創(chuàng)建結(jié)構(gòu)
withShlnfodo
begin
shi502_netname:=_NetName;
shi502_type:=STYPE_DISKTREE;
shi502__remark:=_Remark;
shi502_max_uses:=$FFFFFFFF;
shi502_current_uses:=10;
shi502_path:=_FilePath;
shi502_passwd:=nil;
shi502_reserved:=0;
shi502_security_descriptor:=nil;
shi502_permissions:=ACCESS_ALL;
end;
try
Result:=NTNetShareAdd(_ServerName,502,@Shlnfo,parm_err);
finally//別忘了釋放內(nèi)存
FreeMem(_ServerName,255);
FreeMem(_FilePath,255);
FreeMem(__NetName,255);
FreeMem(_Remark,255);
end;
finally
FreeLibrary(Libhandle);
end;
end;
functionDeleteShareResource(ServerName:string;NetName:string):Integer;
var
__ServerName:Pchar;
LibHandle:THandle;
begin
LibHandle:=LoadLibrary(NTIib);
ifLibHandle=0then
raiseException.Create(\,Unabletomaplibrary:\'+NTlib);
try
@NTNetShareDel:=GetProcAddress(Libhandle,NetShareDel\");
分酉己內(nèi)存
GetMem(__ServerNamez255);//
strpcopy(__ServerName,ServerName);
try
Result:=NTNetShareDel(_ServerName,NetName,。);
finally
FreeMem<_ServerName,255);
end;
finally
FreeLibrary(Libhandle);
end;
end;
functionAddShareResource(ServerName:PChar;FilePath:PChar;
NetName:PChar;Remark:PChar):Integer;
var
MyShare:Share_lnfo50;
PMyShare:AShare_lnfo50;
LibHandle:THandle;
begin
LibHandle:=LoadLibrary(NTIib);
ifLibHandle=0then
raiseException.Create(\TUnabletomaplibrary:\'+MElib);
try
@MENetShareAdd:=GetProcAddress(Libhandle,\TNetShareDel\,);
strLcopy(MyShare.shi50_netname,NetName,13);
MyShare.shi50_type:=0;
MyShare.shi50_flags:=0;
MyShare.shi50__remark:=Remark;
MyShare.shi50_path:=FilePath;
{MyShare.shi50_rw_password:=nil;
MyShare.shiSO_ro_password:=nil;}
PMyShare:=@MyShare;
Result:=MENetShareAdd(ServerName,50,PMySharezSizeOf(MyShare));
finally
FreeLibrary(Libhandle);
end;
end;
functionDelShareResource(ServerName:string;NetName:string):Integer;
var
_ServerName:Pchar;
LibHandle:THandle;
begin
LibHandle:=LoadLibrary(NTIib);
ifLibHandle=0then
raiseException.Create(\,Unabletomaplibrary:\'+MElib);
try
@NTNetShareDel:=GetProcAddress(Libhandle,\TNetShareDel\?);
GetMem(_ServerName,255);//分配內(nèi)存
strpcopy(_ServerName,ServerName);
try
Result:=NTNetShareDel(_ServerName,NetName,0);
finally
FreeMem(__ServerName,255);
end;
finally
FreeLibrary(Libhandle);
end;
end;
delphi數(shù)據(jù)庫(kù)引擎管理器
當(dāng)用戶在硬盤的某個(gè)邏輯盤上建立一個(gè)目錄,用于存放用戶數(shù)據(jù)庫(kù)文件時(shí),Delphi將如何訪
問該目錄中所存放的數(shù)據(jù)庫(kù)文件。例如,在E盤上建立E:\xsdagl\data目錄,用于存放
學(xué)生檔案管理系統(tǒng)數(shù)據(jù)庫(kù)文件,Delphi應(yīng)如何訪問E:\xsdagl\data目錄中的數(shù)據(jù)庫(kù)文件?
常用方法是使用Delphi數(shù)據(jù)庫(kù)引擎管理器建立一個(gè)與E:\xsdagl\data目錄對(duì)應(yīng)的別名(如
xsda),然后用該別名實(shí)現(xiàn)對(duì)數(shù)據(jù)庫(kù)文件進(jìn)行訪問。因此,在講述Delphi訪問數(shù)據(jù)庫(kù)文件方
法前,先介紹數(shù)據(jù)庫(kù)引擎管理器BDEAdministrator。
數(shù)據(jù)庫(kù)引擎管理器(BDEAdministrator)是對(duì)數(shù)據(jù)庫(kù)引擎(BDE)進(jìn)行管理和配置的工具軟
件。在訪問本地或遠(yuǎn)程數(shù)據(jù)庫(kù)前,編程人員首先需要使用這個(gè)軟件在本地計(jì)算機(jī)中創(chuàng)建需使
用數(shù)據(jù)庫(kù)的別名,同時(shí)指定數(shù)據(jù)庫(kù)引擎使用什么樣的驅(qū)動(dòng)程序?qū)?shù)據(jù)庫(kù)進(jìn)行訪問。所以數(shù)據(jù)
庫(kù)引擎管理器具有以下幾個(gè)方面的功能:
①為用戶訪問數(shù)據(jù)庫(kù)文件創(chuàng)建數(shù)據(jù)庫(kù)別名,也可修改與刪除數(shù)據(jù)庫(kù)別名。
②對(duì)用戶所使用的各類數(shù)據(jù)庫(kù)引擎進(jìn)行配置。
③安裝和刪除用戶所使用的各種數(shù)據(jù)庫(kù)驅(qū)動(dòng)程序。
Delphi中遍歷XML文檔的實(shí)現(xiàn)方法及源代碼
XML文檔的節(jié)點(diǎn)是標(biāo)準(zhǔn)的樹形結(jié)構(gòu),可以通過遞歸或者回溯算法來(lái)遍歷所有的節(jié)點(diǎn)八
本例使用遞歸算法為例,制作了2個(gè)遍歷XML文檔的例子。
第一個(gè)例子,給出一個(gè)XML節(jié)點(diǎn),遍歷所有子節(jié)點(diǎn)?不包括起始節(jié)點(diǎn)。
第二個(gè)例子,給出一個(gè)XML節(jié)點(diǎn),遍歷所給的節(jié)點(diǎn)及其下屬的所有子節(jié)點(diǎn)。
以上2個(gè)示例均列舉出了XML文檔的標(biāo)簽屬性和文本值,是比較完整的示例代碼。
<?xmlversion=\"1.0\"encoding=\Hgb2312\"?>
<rootwebsite=\Hhttp://www.whylOOOOO.com\">
<channelid=\"1\"tagname=\"channel\">
<topicid=tagname二、"topic\">Windows頻道</topic>
<Urlid=\"l-2\"tagname=\"Url\">www.whylOOOOO.com/_windows</Url>
</channel>
<channelid=\H2\"tagname=\"channel\M>
<topicid=tagname=\"topic\">代碼實(shí)驗(yàn)室</topic>
<subWebid=\"2-2\"tagname=\"subWeb\H>http://lab.whylOOOOO.com</subWeb>
</channel>
<BBSid=\"03\"tagname=\"BBS\">
<topicid=\"03?l\"tagname=\"topic\">電腦學(xué)習(xí)社區(qū)</topic>
<subWebid=\"03-2\"tagname=\"subWeb\n>http://bbs.whylOOOOO.com</subWeb>
<subBBSid=\"03-3\">
<subBBStopicid=\''0331\">菜鳥學(xué)院</subBBStopic>
<subBBStopicid=\"03-3-2\">問吧</subBBStopic>
<subBBStopicid=\"0333\">學(xué)吧</subBBStopic>
<subBBStopicid=\"0334\">回吧</subBBStopic>
<subBBStopicid=\"03-3-5\nx/subBBStopic>
<subBBStopic></subBBStopic>
</subBBS>
</BBS>
<AnatherTagnote=\HtestTag-l\"/>
<AnatherTag/>
</root>
{}
functionTForml.GetXmlTreel(nNode:IXMLNode):string;
var
i,j:integer;
begin
fori:=0tonNode.ChildNodes.Count-1do
begin
s:=s+'<'+nNode.ChildNodes.Nodes[i].NodeName;
forj:=0tonNode.ChildNodes[i].AttributeNodes.Count-ldo
begin
s:=s+''+nNode.ChildNodes[i].AttributeNodes[j].NodeName;
s:=s+'=\H,+nNode.ChildNodes[i].AttributeNodes[j].NodeValue+)\"';
end;
s:=s+'>';
ifnNode.ChildNodes.Nodes[i].lsTextElementthen
s:=s+nNode.ChildNodes.Nodes[i].Text;
ifnNode.HasChildNodesandnotnNode.ChildNodes.Nodes[i].lsTextElementthen
begin
s:=s+#13+#10;
GetXmlTreel(nNode.ChildNodes.Nodes[i]);
end;
s:=s+'</'+nNode.ChildNodes.Nodes[i].NodeName+>>'+#13+#10;
end;
result:=s;
end;
}
functionTForml.GetXmlTree2(nNode:IXMLNode):string;
var
i,j:integer;
begin
s:=s+'<'+nNode.NodeName;
forj:=0tonNode.AttributeNodes.Count-1do
begin
s:=s+'+nNode.AttributeNodes[j].NodeName;
s:=s+'=\H,+nNode.AttributeNodes[j].NodeValue\H,;
end;
s:=s+'>f;
ifnNode.lsIextElementthen
s:=s+nNode.Text
else
begin
s:=s+#13+#10;
ifnNode.HasChildNodesthen
fori:=0tonNode.ChildNodes.Count-1do
begin
GetXmlTree2(nNode.ChildNodes.Nodes[i]);
end;
end;
s:=s+'<r+nNode.NodeName+'>'+#13+#10;
result:=s;
end;
{}
調(diào)用:
procedureTForml.Button4Click(Sender:TObject);
var
oXml:TXMLDocument;
begin
oXml:=TXMLDocument.Create(self);
oXml.FileName:='_Treeview.xmlJ;
oXml.Active:=true;
s:=";
s:=GetXmlTreel(oXml.ChildNodes.FindNode(,root'));
Memol.Lines.Add(s);
oXml.Free;
end;
procedureTForml.Button5Click(Sender:TObject);
var
oXml:TXMLDocument;
begin
oXml:=TXMLDocument.Create(self);
oXml.FileName:='_Treeview.xmr;
oXml.Active:=true;
,,
s:=;
s:=GetXmlTree2(oXml.ChildNodes.FindNode(Jroot'));
Memol.Lines.Add(s);
oXml.Free;
end;
firebird嵌入式數(shù)據(jù)庫(kù)
firebird是一個(gè)跨平臺(tái)的開源數(shù)據(jù)庫(kù),適用interbase授權(quán)協(xié)議(IPL),從borland的interbase
脫胎而來(lái)。以前用interbase/firebird的時(shí)候,發(fā)布程序的時(shí)候哪怕只有一個(gè)用戶至少也得安
裝一個(gè)localserver,一些單機(jī)版的程序只好使用access來(lái)保存數(shù)據(jù)。但是微軟那個(gè)mdac偏
偏常出現(xiàn)一些莫名其妙的問題,access2000的數(shù)據(jù)庫(kù)文件在win98上就經(jīng)常出現(xiàn)“插入時(shí)無(wú)
法定位遇到BOF/EOF...^^一類不知所云的錯(cuò)誤提示,安裝新版mdac并打上oledb補(bǔ)丁
就能解決問題,不過一個(gè)幾百k的小程序要帶上七八兆的補(bǔ)丁感覺實(shí)在不好。我就一直希望
能夠把interbase/firebird應(yīng)用于桌面數(shù)據(jù)的存儲(chǔ),就是因?yàn)槟莻€(gè)安裝服務(wù)器的問題一直沒有
好辦法。
現(xiàn)在終于發(fā)布了嵌入式的firdbird,我們可以用firebirdembbed作為桌面數(shù)據(jù)庫(kù)了,跟
C/S版的firebird數(shù)據(jù)奎一樣,對(duì)許多現(xiàn)代數(shù)據(jù)庫(kù)特性提供充分的支持,可以使用觸發(fā)器、
存儲(chǔ)過程,可以自定義類型,可以自定義外部函數(shù)。而且他與firebirdC/S使用相同的文件
格式,也支持將一個(gè)數(shù)據(jù)庫(kù)文件存儲(chǔ)到多個(gè)文件,把它的數(shù)據(jù)文件放到firebirdC/S上立刻
就可以使用,你隨時(shí)可以把單機(jī)應(yīng)用改造成C/S或者放到web上。應(yīng)用程序開發(fā)與firebirdC/S
沒什么不同,可以使用它的CAPI,也可以使用Delphi/BCB的interbase和dbx組件,當(dāng)然,
安裝了0dbe驅(qū)動(dòng)以后,用ado也是可以的。發(fā)布程序時(shí)只需要提供一個(gè)dll,我(門的firebird
應(yīng)用程序就可以工作了(用ad。不行,用dbx還需要midas.dll和dbexpint.dll),可以很容易地
制作出安裝程序,所有的配置工作都可以由程序員自己控制,也不用擔(dān)心數(shù)據(jù)庫(kù)會(huì)被用戶直
接打開進(jìn)行改動(dòng)了。而且據(jù)我所知,嵌入式數(shù)據(jù)庫(kù)好像還沒有支持存儲(chǔ)過程和觸發(fā)器的吧,
access,sqlite都不行,更不用說(shuō)dbf和paradox了。
Int64與Currency
procedureTForml.ButtonlClick(Sender:TObject);
var
c:Currency;
i:Int64absolutec;
begin
c:=1234.5678;
ShowMessage(lntlbStr(i));//12345678
end;
procedureTForml.Button2Click(Sender:TObject);
var
i:Int64;
c:Currencyabsolutei;
begin
i:=12345678;
ShowMessage(CurrTbStr(c));//1234.5678
end;
procedureTForml.Button3Click(Sender:TObject);
var
i:Int64;
c:Currency;
begin
i:=12345;
ShowMessage(Curr7bStr(PCurrency(@i)A));//l.2345
c:=3.14;
ShowMessage(lntTDStr(Plnt64(@c)A));//31400
end;
獲取斐波那契數(shù)列的函數(shù)
(斐波那契數(shù)列:1、2、3、5、8、13、21、34、55、89、144...等于前兩數(shù)之和}
{昂納多?斐波那契(LeonardoFibonacci,1170-1240,意大利數(shù)學(xué)家)}
usesTypes;
{參數(shù)2是要獲取的總數(shù)}
procedurefbnc(varA:Tlnt64DynArray;Count:Integer);
var
i:Integer;
begin
SetLengthfA,Count);
A[0]:=1;
A[l]:=2;
fori:=2toCountdoA[i]:=A[i-2]+A[i-1];
end;
{測(cè)試}
procedureTForml.ButtonlClick(Sender:TObject);
var
ns:Tlnt64DynArray;
n:Int64;
begin
fbnc(ns,90);
Memol.Clear;
forninnsdoMemol.Lines.Add(lntToStr(n));
end;
{查看其黃金分割比}
procedureTForml.Button2Click(Sender:TObject);
var
ns:Tlnt64DynArray;
i:Integer;
begin
fbnc(ns,90);
Memol.Clear;
fori:=0toLength(ns)-1do
begin
ifi=0thenContinue;
Memol.Lines.Add(FloatToStr(ns[i]/ns[i-l]));
end;
end;
動(dòng)態(tài)指定存儲(chǔ)過程的參數(shù)來(lái)可視化建立報(bào)表工程
由于項(xiàng)目需求變動(dòng),需要使用到了Rave進(jìn)行報(bào)表設(shè)計(jì),在使用中也查閱了很多資料,但是,
網(wǎng)上的資料很多都是很淺顯的入門文章,本文中主要介紹,如何使用帶參存儲(chǔ)過程作為數(shù)據(jù)
源,實(shí)現(xiàn)可視化報(bào)表的設(shè)計(jì)。
下面是界面設(shè)計(jì),很簡(jiǎn)單,通過選擇的日期和時(shí)間范圍,以要打印數(shù)據(jù)的類別來(lái)生成打
印報(bào)表。在界面中添加一個(gè)RvProject,幾個(gè)RvDataSetConnection,幾個(gè)ADOStoredProc,一
個(gè)ADOConnection,當(dāng)然,這只是為設(shè)計(jì)時(shí)為了方便應(yīng)用,在完成可視化設(shè)計(jì)報(bào)表格式后,
可以只使用一個(gè)存儲(chǔ)過程的組件就可以了。
\'800\')this.width=\'800\';if(this.height>\'600\")this.height=\'600\';\"border=0>
思想就是:當(dāng)可視化建立報(bào)表時(shí),需要提供數(shù)據(jù)源,使用帶參數(shù)的存儲(chǔ)過程在設(shè)計(jì)時(shí),
需要提供參數(shù)值,才能得到由存儲(chǔ)過程返回的數(shù)據(jù)源;而存儲(chǔ)過程的參數(shù)值是由界面提供
并由用戶選擇動(dòng)態(tài)產(chǎn)生的,這就需要在設(shè)計(jì)時(shí),屏蔽參數(shù)值的部分,可以采用兩種方法:一
是指定固定的參數(shù)值,另外就是修改存儲(chǔ)過程,先去掉存儲(chǔ)過程的參數(shù)部分,當(dāng)然,要保證,
去掉參數(shù)前后,存儲(chǔ)過程返回的數(shù)據(jù)集是結(jié)構(gòu)等同的。
下面提供部分代碼,以供參考:
存儲(chǔ)過程部分:(如何使用表名做參數(shù),我以前寫過一個(gè)總結(jié))
CREATEProcedureGetSteel@tableNamenvarchar(20),@strDate
nvarchar(20),@strBeginTimenvarchar(30),@strEndTimenvarchar(30)
AS
declare@sSqlnvarchar(4000)
set@sSql=\'selectAVG(CASEWHENP24=999THENNULLELSEP24END)asA1L,AVG(CASE
WHENP23=999THENNULLELSEP23END)asA1R,AVG(CASEWHENP18=999THENNULLELSE
P18END)asA2L,AVG(CASEWHENP17=999THENNULLELSEP17END)asA2R,\'
set@sSql=@sSql+\'AVG(CASEWHENP138=999THENNULLELSEP138END)as
B15L,AVG(CASEWHENP137=999THENNULLELSEP137END)asB15R,AVG(CASEWHENP144=
999THENNULLELSEP144END)asB16L,AVG(CASEWHENP143=999THENNULLELSEP143END)
asB16Rfrom\'
set@sSql=@sSql+@tableName
set@sSql=@sSql+\'WhereTempDate=\'+@strDate+\'ANDTempTimeBETWEEN\'
+@strBeginTime+\'AND\'+@strEndTime
EXECUTEsp_executesql@sSql
GO
在設(shè)計(jì)時(shí),將參數(shù)部分注釋掉,同時(shí),將存儲(chǔ)過程的名稱指定為GetSteel,將Active屬
性設(shè)為True。然后在Rave工程中建立一個(gè)DataView,就可以看到相應(yīng)的數(shù)據(jù)字段列表,可
以進(jìn)行報(bào)表的設(shè)計(jì)了。
在設(shè)計(jì)完報(bào)表后,可以按F9預(yù)覽,數(shù)據(jù)源的Active屬性為True,可以看到已經(jīng)有數(shù)據(jù)
顯示在報(bào)表中。
下一步就是修改存儲(chǔ)過程的屬性,將active設(shè)為False,去掉ProcedureName屬性,然
后在程序中指定存儲(chǔ)過程的參數(shù)值。
下面是部分代碼,已經(jīng)整理過界面元素,并將連接數(shù)據(jù)庫(kù)的控件整理到一個(gè)DataMConn
單元中。
WithDataMConn.ADOSPPrintSteeldo
begin
Close;
ProcedureName:=\'GetSteel\';
Parameters.Clear;
Parameters.CreateParameter(\'@tableName\',ftString,pdinput,20,0);
Parameters.CreateParameter(\'@strDate\',ftString,pdinput,20,0);
Parameters.CreateParameter(\'@strBeginTime\',ftString,pdinput,20,0);
Parameters.CreateParameter(\'@strEndTime\',ftString,pdinput,20,0);
Parameters.ParamByName(\'@tableName\,).Value:=tableName;
Parameters.ParamByName(\'@strDate\').Value:=strDate;
Parameters.ParamByName(\'@strBeginTime\').Value:=strBeginTime;
Parameters.ParamByName(\'@strEndTime\').\/alue:=strEndTime;
try
Open;
rvDataSetConnectionl.DataSet:=DataMConn.ADOSPPrintSteel;
except
begin
ShowMessageN打開存儲(chǔ)過程出現(xiàn)錯(cuò)誤!請(qǐng)聯(lián)系開發(fā)人員\');
Exit;
end;
end;
end;
RvProject.ProjectFile:二GetCurrentDir()+\'\\Project.rav\';//得至lJ工程路徑
RvProject.Open;〃打開報(bào)表工程
ifcmbKind.Itemindex=0then〃全部數(shù)據(jù)
begin
WithRvProject.ProjMando〃找到要打印的報(bào)表頁(yè)的日期時(shí)間等控件,并賦值
begin
MyPage:=FindRaveComponent(\'Report4.Pagel\',nil)asTRavePage;
MyText^FindRaveComponent^'txtDateWMyPage)asTRaveText;
MyText.Text:=printDate;
MyText^FindRaveComponent^'txtBeginTimeWMyPage)asTRaveText;
MyText.Text:=printBeginTime;
MyText:=FindRaveComponent(\'txtEndTime\',MyPage)asTRavelext;
MyText.Iext:=printEndTime;
end;
RvProject.ExecuteReport(\,report4\);〃執(zhí)行打印
RvProject.Close;
end;
注意:在存儲(chǔ)過程寫好后,不要輕易變更各個(gè)字段名稱,因?yàn)檫@樣將導(dǎo)致Rave中的
DataView不可用;在設(shè)計(jì)時(shí)也要十分小心,否則很可能要推倒重來(lái),重新將存儲(chǔ)過程設(shè)為
無(wú)參,注釋掉賦參的代碼,重新添加DataView等等。我就如此經(jīng)歷了幾次,才摸清楚到底
如何使用帶參數(shù)的存儲(chǔ)過程做數(shù)據(jù)源實(shí)現(xiàn)報(bào)表的可視化設(shè)計(jì),希望對(duì)有需要者有些幫助!
計(jì)算機(jī)二級(jí):delphi播放mp3背景音樂代碼
〃以下的代碼為delphi中實(shí)現(xiàn)播放背景音樂
var
mciOpenParms:TMCI_Open_Parms;
m_MCIDevicelD:MCIDEVIC曰D;
procedureTForml.FormCreate(Sender:TObject);
var
mciPlayParms:MCI_PLAY__PARMS;
ret:integer;
begin
try
begin
mciOpenParms.lpstrDeviceType:=y;
mciOpenParms.lpstrElementName:='做你的愛人.mp3';
mciSendCommand(0/MCI_OPENzMCI_OPEN_ELEMENI;DWORD(@mciOpenParms));
m_MCIDevicelD:=mciOpenParms.wDevicelD;
mciPlayParms.dwCallback:=Forml.Handle;
mciPlayParms.dwFrom:=0;
ret:=mciSendCommand(m_MCIDevicelD/MCI_PLAXMCI__FROMor
MCI_NOTIFYinteger(@mciPlayParms));
end;
except
end;
end;
計(jì)算機(jī)二級(jí):DELPHI如何在菜單中顯示圖片
用過Office97嗎?是不是覺得在菜單中顯示圖標(biāo)很新鮮?如果想讓你的程序也能如此錦上
添花,那就請(qǐng)你趕快準(zhǔn)備bmp吧!
假設(shè)你打算為“文件”菜單欄(name為nl)下的第9項(xiàng)(序號(hào)改為8)“打印”添加
一個(gè)打印機(jī)圖標(biāo)(文件名為c:inter.bmp),那只要在form的OnCreate事件中這樣編寫:
var
Bmp:TPicture;
begin
Bmp:=TPicture.Create;
Bmp.LoadFromFile(zc:printer.bmp');
SetMenultemBitmaps(nl.Handle,8,MF_BYPOSITION,Bmp.Bitmap.Handle,
Bmp.Bitmap.Handle);
end;
其中,第一個(gè)bitmap.handle用于未選定菜單項(xiàng)(unchecked),第二個(gè)則指定了選定
(checked)時(shí)所顯示的bitmap,同異皆可。另外,由于菜單項(xiàng)的高度有限,所以,若bitmap
過大,只有左上角被顯示。
計(jì)算機(jī)二級(jí)DELPHI技巧:窗體中底圖位置的設(shè)置
<Pclass=contentstyle="“MARGIN:"Opx\?2px4px>首先需要調(diào)用底圖,增加1個(gè)image控件,
在屬性中選擇Picture屬性,Load選中的圖片。
然后,屬性中選擇Align屬性,該屬性中有7
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024-2025學(xué)年第12課從明朝建立到清軍人關(guān)-勤徑學(xué)升高中歷史必修上同步練測(cè)(統(tǒng)編版2019)
- 園林養(yǎng)護(hù)人員雇傭合同范文2025年
- 2025年伙伴合同終止協(xié)議
- 2025年企業(yè)辦公用品綜合供需合同
- 2025年官方物流配送協(xié)議書高清
- 2025年企業(yè)設(shè)備抵押擔(dān)保貸款合同
- 2025年動(dòng)物收養(yǎng)協(xié)議版式
- 2025年糧食供需雙方合同策劃大綱
- 2025年智能交通項(xiàng)目提案報(bào)告模式
- 2025年企業(yè)維修保養(yǎng)年合作協(xié)議
- 2025中國(guó)鐵塔集團(tuán)安徽分公司招聘29人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025年河北省農(nóng)村信用社招聘歷年高頻重點(diǎn)提升(共500題)附帶答案詳解
- 人教版五年級(jí)下冊(cè)信息技術(shù)全冊(cè)教案
- 手術(shù)室植入物的管理
- 電力供電系統(tǒng)試驗(yàn)調(diào)試和聯(lián)調(diào)方法
- 天津市紅橋區(qū)2023-2024學(xué)年高二上學(xué)期期末考試化學(xué)試題(含答案)
- 食品經(jīng)營(yíng)許可證主要設(shè)備設(shè)施布局圖及操作流程
- Unit6AtthesnackbarStorytimeDiningwithdragons(課件)譯林版英語(yǔ)四年級(jí)上冊(cè)
- 高二年級(jí)家長(zhǎng)會(huì)課件
- 滬教版 九年級(jí)(上)數(shù)學(xué) 秋季課程 第12講 統(tǒng)計(jì)初步(解析版)
- 《國(guó)際中文教材評(píng)價(jià)標(biāo)準(zhǔn)》
評(píng)論
0/150
提交評(píng)論