各位高手如何将C++的声明转成delphi的 ( 积分: 100 )

  • 主题发起人 主题发起人 wcnmdznsq
  • 开始时间 开始时间
W

wcnmdznsq

Unregistered / Unconfirmed
GUEST, unregistred user!
、void&nbsp;*&nbsp;OpenComm_N(unsigned&nbsp;long&nbsp;CommPort,unsigned&nbsp;long&nbsp;baudrate)<br><br>int&nbsp;extSys&nbsp;_Query_UserCard&nbsp;(void&nbsp;*&nbsp;icdev,&nbsp;<br>unsigned&nbsp;long&nbsp;ulPurseNo,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulFactoryFixID,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulSerNo,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulGrade,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulGroup,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulType,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulSubType,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulTimesLimit,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulDayLimit,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulForegift,<br>char&nbsp;*&nbsp;szNumber,<br>char&nbsp;*&nbsp;szStartDate,<br>char&nbsp;*&nbsp;szName,<br>char&nbsp;*&nbsp;szEndDate,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulLockFlag,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulBalance,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulTraceNo,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulDayAmount,<br>char&nbsp;*&nbsp;szOccurTime,<br>long&nbsp;*&nbsp;lAmount,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulLastBalance,<br>unsigned&nbsp;long&nbsp;*&nbsp;ulTerminalNo,<br>int&nbsp;nWaitTime)
 
function&nbsp;OpenComm_N(CommPort,&nbsp;baudrate:&nbsp;LongWord):Pointer;<br><br>function&nbsp;{extSys}&nbsp;_Query_UserCard&nbsp;(icdev:&nbsp;Pointer;&nbsp;<br>&nbsp;&nbsp;ulPurseNo:&nbsp;LongWord;<br>&nbsp;&nbsp;var&nbsp;ulFactoryFixID,&nbsp;ulSerNo,&nbsp;ulGrade,&nbsp;ulGroup,&nbsp;ulType,&nbsp;ulSubType,<br>&nbsp;&nbsp;ulTimesLimit,&nbsp;ulDayLimit,&nbsp;ulForegift:&nbsp;LongWord;<br>&nbsp;&nbsp;szNumber,&nbsp;szStartDate,&nbsp;szName,&nbsp;szEndDate:&nbsp;PChar;<br>&nbsp;&nbsp;var&nbsp;ulLockFlag,&nbsp;ulBalance,&nbsp;ulTraceNo,&nbsp;ulDayAmount:&nbsp;LongWord;<br>&nbsp;&nbsp;szOccurTime:&nbsp;PChar;<br>&nbsp;&nbsp;var&nbsp;lAmount:&nbsp;Integer;<br>&nbsp;&nbsp;var&nbsp;ulLastBalance,&nbsp;ulTerminalNo:&nbsp;LongWord;<br>&nbsp;&nbsp;nWaitTime:&nbsp;Integer):Integer;
 
恩!他现在提示我&nbsp;应用程序初始化错误&nbsp;(0xc0000142)&nbsp;失败
 
extSys&nbsp;??是什么??
 
如何将C++程序转为Pascal语法<br>原文出处:&nbsp;by&nbsp;Paul&nbsp;Fulford&nbsp;of&nbsp;Komodo&nbsp;Software<br>翻译:http://delphi.ktop.com.tw<br><br>将C++&nbsp;转为&nbsp;Pascal/Delphi<br>==============================<br>目录<br>概论<br>数据型态<br>关键词<br>叙述结尾<br>变量宣告<br>字符串<br>数组<br>数值的指定与比较<br>常数宣告<br>函数与程序<br>with&nbsp;...&nbsp;do叙述<br>批注<br>流程控制<br>对象导向结构<br>Containers<br>例外处理<br>资料流(Streaming)<br>项目档的设计<br>如何转换<br>结论<br>=================================<br>概论:<br>这篇文章的目的是让您了解C++与Object&nbsp;Pascal的不同<br>也让您能够有能力将C++转为Object&nbsp;Pascal(以下称为OP)<br>=================================<br>数据型态<br>这一章可学到如何将&nbsp;C++&nbsp;的数据型态&nbsp;转成&nbsp;OP&nbsp;的数据型态.<br>变量宣告时可参考下列对照表<br>C++&nbsp;OP&nbsp;大小&nbsp;(bytes)&nbsp;值范围<br>==================================================================<br>char&nbsp;----&nbsp;1&nbsp;-128&nbsp;to&nbsp;127<br>----&nbsp;char&nbsp;1&nbsp;1&nbsp;ASCII&nbsp;character<br>int&nbsp;integer&nbsp;2&nbsp;-32,768&nbsp;to&nbsp;32,767<br>short&nbsp;----&nbsp;2&nbsp;-32,768&nbsp;to&nbsp;32,767<br>----&nbsp;shortint&nbsp;1&nbsp;-128&nbsp;to&nbsp;127<br>long&nbsp;longint&nbsp;4&nbsp;-2,147,483,647&nbsp;to&nbsp;2,147,483,647<br>unsigned&nbsp;char&nbsp;byte&nbsp;1&nbsp;0&nbsp;to&nbsp;255<br>unsigned&nbsp;int&nbsp;word&nbsp;2&nbsp;0&nbsp;to&nbsp;65,535<br>unsigned&nbsp;short&nbsp;word&nbsp;2&nbsp;0&nbsp;to&nbsp;65,535<br>unsigned&nbsp;long&nbsp;----&nbsp;4&nbsp;0&nbsp;to&nbsp;4,294,967,295<br><br>float&nbsp;single&nbsp;4&nbsp;3.4E-38&nbsp;TO&nbsp;3.4E+38<br>double&nbsp;double&nbsp;8&nbsp;1.7E-308&nbsp;TO&nbsp;1.7E+308<br>long&nbsp;double&nbsp;extended&nbsp;10&nbsp;3.4E-4932&nbsp;TO&nbsp;3.4E+4932<br>----&nbsp;comp&nbsp;8&nbsp;1.7E-308&nbsp;TO&nbsp;1.7E+308<br>----&nbsp;real&nbsp;(for&nbsp;backwards&nbsp;compatibility&nbsp;only&nbsp;--&nbsp;use&nbsp;double)<br><br>void&nbsp;pointer&nbsp;8&nbsp;n/a&nbsp;--&nbsp;an&nbsp;untyped&nbsp;pointer<br>----&nbsp;boolean&nbsp;1&nbsp;True&nbsp;or&nbsp;False<br>(C++&nbsp;may&nbsp;soon&nbsp;have&nbsp;a&nbsp;boolean&nbsp;type)<br>String&nbsp;----&nbsp;a&nbsp;C++&nbsp;standard&nbsp;object<br>----&nbsp;string&nbsp;an&nbsp;array&nbsp;of&nbsp;up&nbsp;to&nbsp;255&nbsp;ASCII&nbsp;characters<br>----&nbsp;PChar&nbsp;pointer&nbsp;to&nbsp;a&nbsp;null-terminated&nbsp;string<br>=================================================================<br><br>=================================<br>关键词<br>C++&nbsp;有&nbsp;59&nbsp;个关键词,&nbsp;OP&nbsp;有&nbsp;60&nbsp;个关键词.&nbsp;This&nbsp;does&nbsp;not&nbsp;include&nbsp;the&nbsp;many&nbsp;vendor<br>C++&nbsp;大小写有分&nbsp;OP&nbsp;大小写不分<br><br>C++的关键词<br>asm&nbsp;auto&nbsp;break&nbsp;case&nbsp;catch&nbsp;cdecl&nbsp;char&nbsp;class&nbsp;const&nbsp;const_cast&nbsp;continue<br>default&nbsp;delete&nbsp;do&nbsp;double&nbsp;dynamic_cast&nbsp;else&nbsp;enum&nbsp;extern&nbsp;far&nbsp;float&nbsp;for<br>friend&nbsp;goto&nbsp;huge&nbsp;if&nbsp;inline&nbsp;interrupt&nbsp;int&nbsp;near&nbsp;new&nbsp;operator&nbsp;pascal&nbsp;private<br>protected&nbsp;public&nbsp;register&nbsp;reinterpret_cast&nbsp;return&nbsp;short&nbsp;signed&nbsp;sizeof<br>static&nbsp;static_cast&nbsp;struct&nbsp;switch&nbsp;template&nbsp;this&nbsp;throw&nbsp;try&nbsp;typedef&nbsp;typeid<br>union&nbsp;unsigned&nbsp;virtual&nbsp;void&nbsp;volatile&nbsp;wchar_t&nbsp;while<br>OP的关键词<br>and&nbsp;as&nbsp;asm&nbsp;array&nbsp;begin&nbsp;case&nbsp;class&nbsp;const&nbsp;constructor&nbsp;destructor&nbsp;div&nbsp;do&nbsp;<br>downto&nbsp;else&nbsp;end&nbsp;except&nbsp;exports&nbsp;file&nbsp;finally&nbsp;for&nbsp;function&nbsp;goto&nbsp;if&nbsp;implementation&nbsp;<br>in&nbsp;inherited&nbsp;inline&nbsp;initialization&nbsp;interface&nbsp;is&nbsp;label&nbsp;library&nbsp;mod&nbsp;nil&nbsp;not&nbsp;<br>object&nbsp;of&nbsp;or&nbsp;packed&nbsp;procedure&nbsp;program&nbsp;property&nbsp;raise&nbsp;record&nbsp;repeat&nbsp;set&nbsp;shl<br>shr&nbsp;string&nbsp;then&nbsp;to&nbsp;try&nbsp;type&nbsp;unit&nbsp;until&nbsp;uses&nbsp;var&nbsp;while&nbsp;with&nbsp;xor<br>=================================<br>叙述结尾<br>C++叙述结尾<br>大部份的叙述都用&nbsp;;&nbsp;号结尾<br>有一些例外如:<br>#include&nbsp;<br>#define&nbsp;MAXNAMELENGTH&nbsp;35<br><br>OP叙述结尾<br>所有的叙述都用&nbsp;;&nbsp;号结尾<br>=================================<br>变量宣告<br>C++变量宣告<br>变量名称只有前32个字有效<br>变量名称宣告可在程序的任何地方宣告(当然,宣告后才可用)<br>//&nbsp;...&nbsp;如在程序中宣告<br>{<br>char&nbsp;i;<br>for&nbsp;(i=0;i&lt;10;i++)<br>{<br>char&nbsp;sName[10];&nbsp;//&nbsp;在区块中也可宣告变量<br>int&nbsp;iCount,&nbsp;iLoop,&nbsp;iValToReach;<br>double&nbsp;dMaxLoan,&nbsp;dTotal;<br>float&nbsp;fMaxRate&nbsp;=&nbsp;123.875;<br>}<br>}<br>OP变量宣告<br>变量名称只有前63个字有效<br>变量名称要宣告在var之后,且要在function或procedure开始时宣告<br>不可在区块内宣告变量<br>如:<br>function&nbsp;PayBack_d(var&nbsp;dAmount:&nbsp;double):&nbsp;double;<br>var<br>iCount,&nbsp;iLoop,&nbsp;iValToReach:&nbsp;integer;<br>dMaxLoan,&nbsp;dTotal,&nbsp;dMaxRate:&nbsp;double;<br>begin<br>dMaxRate&nbsp;:=&nbsp;123.875;<br>{...}<br><br>=================================<br>字符串<br>C++字符串<br>在C++现在也有了字符串对象,但并不和以&quot;/0&quot;结束的char相容.<br>大部份的字符串就是char数组,可以无限长度.<br>下面是一些char数组宣告的例子:<br>char&nbsp;sName[26];&nbsp;//&nbsp;25&nbsp;个chars长<br>char&nbsp;psDemo[]&nbsp;=&nbsp;&quot;Hello,&nbsp;there!&quot;;&nbsp;<br>char&nbsp;*&nbsp;psDemo&nbsp;=&nbsp;new&nbsp;char[26];<br>对字符串变量最常做的事就是strcpy与strcat<br>您要确定strcat或strcpy后的长度够不够存放.<br>以下是strcpy/strcat的例子.<br>class&nbsp;Ticker<br>{<br>...<br>public:<br>char&nbsp;sBuf[10],<br>sLatestTrade[TRADELENGTHBUF],<br>saTradeRecords[50]&nbsp;[TRADELENGTHBUF];<br>...<br>void&nbsp;OptnFormat2_v(unsigned&nbsp;long&nbsp;&amp;&nbsp;ulQuantity,<br>CompanyC&nbsp;*&nbsp;poC,<br>int&nbsp;&amp;&nbsp;iSeries);<br>...<br>};<br>...<br>void&nbsp;TickerC::OptnFormat2_v(unsigned&nbsp;long&nbsp;&amp;&nbsp;ulQuantity,<br>CompanyC&nbsp;*&nbsp;poC,<br>int&nbsp;&amp;&nbsp;iSeries)<br>{<br>ultoa(ulQuantity,&nbsp;sBuf,&nbsp;10);<br>strcpy(sLatestTrade,&nbsp;sBuf);<br>AddMosToString_v(sLatestTrade,<br>poC-&gt;oSOS.oSeries[iSeries].oExpDate.enMonth);<br>itoa(poC-&gt;oSOS.oSeries[iSeries].oExpDate.iDay,&nbsp;sBuf,&nbsp;10);<br>strcat(sLatestTrade,&nbsp;sBuf);<br>strcat(sLatestTrade,&nbsp;poC-&gt;oS.sTicker);<br>double&nbsp;dStrike&nbsp;=&nbsp;poC-&gt;oSOS.oSeries[iSeries].dStrike;<br>gcvt(dStrike,&nbsp;3,&nbsp;sBuf);<br>strcat(sLatestTrade,&nbsp;sBuf);<br>if(poC-&gt;oSOS.oSeries[iSeries].enCallPut&nbsp;==&nbsp;Call)<br>strcat(sLatestTrade,&nbsp;&quot;Calls&quot;);<br>else&nbsp;strcat(sLatestTrade,&nbsp;&quot;Puts&quot;);<br>}<br><br>OP字符串<br>Delphi&nbsp;1.0字符串最多255bytes,Delphi&nbsp;2.0以后无此限.<br>在OP内的String所占的记忆空间会比您宣告的大小大.<br>因为字符串为数组,在数组[0]放长度.<br>例:<br>var<br>sMyName:&nbsp;string[25];&nbsp;{最大25字符}<br>sYourName:&nbsp;string;<br>begin<br>sMyName&nbsp;:=&nbsp;'Paul&nbsp;Fulford';&nbsp;{单引号表字符串}<br>在OP中,您可用:=和+处理字符串运算,例:<br>TickerC&nbsp;=&nbsp;class<br>...<br>public<br>sLatestTrade:&nbsp;string[TRADELENGTHBUF];<br>saTradeRecords:&nbsp;TStringList;<br>...<br>procedure&nbsp;TickerC.OptnFormat2(var&nbsp;lQuantity:&nbsp;longint;<br>poC:&nbsp;CompanyC;<br>var&nbsp;iSeries:&nbsp;integer);<br>...<br>end;<br>...<br>procedure&nbsp;TickerC.OptnFormat2(var&nbsp;lQuantity:&nbsp;longint;<br>poC:&nbsp;CompanyC;<br>var&nbsp;iSeries:&nbsp;integer);<br>begin<br>sLatestTrade&nbsp;:=&nbsp;IntToStr(lQuantity);<br>AddMosToString(sLatestTrade,<br>poC.oSOS.oSeries[iSeries].oExpDate.enMonth);<br>sLatestTrade&nbsp;:=&nbsp;sLatestTrade&nbsp;+<br>IntToStr(poC.oSOS.oSeries[iSeries].oExpDate.iDay)&nbsp;+<br>poC.oS.sTicker&nbsp;+<br>FloatToStr(poC.oSOS.oSeries[iSeries].dStrike);<br>if&nbsp;poC.oSOS.oSeries[iSeries].enCallPut&nbsp;=&nbsp;Call&nbsp;then<br>sLatestTrade&nbsp;:=&nbsp;sLatestTrade&nbsp;+&nbsp;'Calls'<br>else&nbsp;sLatestTrade&nbsp;:=&nbsp;sLatestTrade&nbsp;+&nbsp;'Puts';<br>end;&nbsp;{OptnFormat2}<br><br>您会发现OP处理字符串容易得多.<br>C++中字符串以&quot;/0&quot;结尾,OP中数组[0]放字符串长度.<br>=================================<br>数组<br>数组是数据的一序列排列.<br>C++与OP的数组宣告很不同.<br>但取用方式很像.<br><br>C++数组<br>数组从0开始,第一个元素为&nbsp;[0],&nbsp;第二个为[1]...类推,初学者要小心<br>//&nbsp;宣告&nbsp;数组...<br>DateC&nbsp;aoCANHolidays[SIZE_HOLIDAYARRAY];<br>double&nbsp;dAverageLast31Days[31];<br>//&nbsp;取用数组<br>for(int&nbsp;i&nbsp;=&nbsp;30,&nbsp;j&nbsp;=&nbsp;29;&nbsp;i&nbsp;&gt;&nbsp;0;&nbsp;i--,j--)<br>dAverageLast31Days&nbsp;=&nbsp;dAverageLast31Days[j];<br><br>OP数组<br>数组通常从[1]开始,但也不全然.<br>在Delphi中您也可以发现某些对象也是从[0]开始的.<br>像TList就是从TList[0]开始,我们要小心看对象的说明文件.<br>例子:<br>var<br>aoCANHolidays:&nbsp;array[1..SIZE_HOLIDAYARRAY]&nbsp;of&nbsp;DateC;<br>dAverageLast31Days:&nbsp;array[1..31]&nbsp;of&nbsp;double;<br>i,j:&nbsp;integer;<br>begin<br>j&nbsp;:=&nbsp;30;<br>for&nbsp;i&nbsp;:=&nbsp;31&nbsp;downto&nbsp;2&nbsp;do<br>begin<br>dAverageLast31Days&nbsp;=&nbsp;dAverageLast31Days[j];<br>Dec(j);&nbsp;{&nbsp;or&nbsp;j&nbsp;:=&nbsp;j-1;&nbsp;}<br>end;<br><br><br>两个语言都可用多维数组,见下例:<br><br>C++<br>double&nbsp;dMatrix[50]&nbsp;[20];<br><br>OP<br>var<br>dMatrix:&nbsp;array[1..50,&nbsp;1..20]&nbsp;of&nbsp;double;<br><br><br>=================================<br>数值的指定与比较<br>C++数值的指定与比较<br>比较相等时用&nbsp;==&nbsp;号<br>给定值时用&nbsp;=&nbsp;号<br>如:<br>if&nbsp;(dMaxRate&nbsp;==&nbsp;15.75)<br>{&nbsp;...<br>dMaxRate&nbsp;=&nbsp;12.5;<br>...<br>}<br><br>OP数值的指定与比较<br>比较相等时用&nbsp;=&nbsp;号<br>给定值时用&nbsp;:=&nbsp;号<br>如:<br>if&nbsp;dMaxRate&nbsp;=&nbsp;15.75&nbsp;then<br>begin<br>...<br>dMaxRate&nbsp;:=&nbsp;12.5;<br>...<br>end;<br>有一个例外就是OP在Const的值的给定是用=号,如:<br>const&nbsp;max=100;<br>=================================<br>常数宣告<br>常数是无法改变值的,所以一定要在宣告时给值.<br>C++常数宣告<br>const&nbsp;int&nbsp;iMax&nbsp;=&nbsp;2000;<br>const&nbsp;double&nbsp;dMaxValue&nbsp;=&nbsp;1234.75;<br>也可用宏定义常数<br>#define&nbsp;nMAXAMOUNT&nbsp;1000<br><br>OP常数宣告<br>function&nbsp;PayBack_d(var&nbsp;dAmount:&nbsp;double):&nbsp;double;<br>const<br>iMAX&nbsp;=&nbsp;2000;&nbsp;{notice&nbsp;value&nbsp;assigned&nbsp;with&nbsp;single&nbsp;equal&nbsp;sign&nbsp;this&nbsp;time}<br>dMAXVALUE&nbsp;=&nbsp;1234.75;<br>var<br>iCount,&nbsp;iLoop,&nbsp;iValToReach:&nbsp;integer;<br>dMaxLoan,&nbsp;dTotal,&nbsp;dMaxRate:&nbsp;double;<br>begin<br>dMaxRate&nbsp;:=&nbsp;dMAXVALUE;<br>{...}<br>=================================<br>函数与程序<br>在C++中所有的Function一定会传回值.<br>在OP中function要传回值,procedure不用<br>在C++中所有的function一定要()号,就算无参数<br>在OP中function无参数不用()号<br>C++函数与程序<br>例:<br>double&nbsp;IntSinceLastAddDate_d(double&nbsp;&amp;dAvailCash);&nbsp;//&nbsp;prototype<br>void&nbsp;SetNewIntRate();&nbsp;//&nbsp;no&nbsp;parameters&nbsp;or&nbsp;return&nbsp;value<br>...<br>double&nbsp;LoanC::IntSinceLastAddDate_d(double&nbsp;&amp;dAvailCash)<br>{<br>double&nbsp;dSomething;<br>...<br>return&nbsp;dSomething;<br>}<br><br>void&nbsp;LoanC::SetNewIntRate()<br>{&nbsp;...&nbsp;}<br><br><br>OP函数与程序<br>例:<br>function&nbsp;IntSinceLastAddDate_d(var&nbsp;dAvailCash:&nbsp;double):&nbsp;double;<br>procedure&nbsp;SetNewIntRate;&nbsp;{无参数也无传回值}<br>...<br>function&nbsp;LoanC.IntSinceLastAddDate_d(var&nbsp;dAvailCash:&nbsp;double):&nbsp;double;<br>var<br>dSomething:&nbsp;double;<br>begin<br>...<br>result&nbsp;:=&nbsp;dSomething;&nbsp;<br>{the&nbsp;global&nbsp;variable&nbsp;&quot;result&quot;&nbsp;is&nbsp;assigned&nbsp;the&nbsp;return&nbsp;value!}<br>end;<br><br>procedure&nbsp;LoanC.SetNewIntRate;<br>begin<br>...<br>end;<br><br>两个语言可以在参数传递时采用&nbsp;pass&nbsp;by&nbsp;valye&nbsp;或&nbsp;pass&nbsp;by&nbsp;reference:<br><br>C++&nbsp;pass&nbsp;by&nbsp;value&nbsp;...&nbsp;double&nbsp;IntSinceLastAddDate_d(double&nbsp;dAvailCash);<br>OP&nbsp;pass&nbsp;by&nbsp;value&nbsp;...&nbsp;function&nbsp;IntSinceLastAddDate_d(dAvailCash:&nbsp;double):&nbsp;double;<br>C++&nbsp;pass&nbsp;by&nbsp;reference&nbsp;...&nbsp;double&nbsp;IntSinceLastAddDate_d(double&nbsp;&amp;dAvailCash);<br>OP&nbsp;pass&nbsp;by&nbsp;reference&nbsp;...&nbsp;function&nbsp;IntSinceLastAddDate_d(var&nbsp;dAvailCash:&nbsp;double):&nbsp;double;<br>C++&nbsp;pass&nbsp;constant&nbsp;...&nbsp;double&nbsp;IntSinceLastAddDate_d(const&nbsp;double&nbsp;dAvailCash);<br>OP&nbsp;pass&nbsp;constant&nbsp;...&nbsp;function&nbsp;IntSinceLastAddDate_d(const&nbsp;dAvailCash:&nbsp;double):&nbsp;double;<br><br>=================================<br>with&nbsp;...&nbsp;do叙述<br>C++无&nbsp;with&nbsp;..&nbsp;DO叙述<br>在C++中当您要取用资料时:<br>poC.oStock.aoTradesLast130Days[0].lVol&nbsp;=&nbsp;0;<br>poC.oStock.aoTradesLast130Days[0].dHigh&nbsp;=&nbsp;0;<br>poC.oStock.aoTradesLast130Days[0].dLow&nbsp;=&nbsp;0;<br>poC.oStock.aoTradesLast130Days[0].dClose&nbsp;=&nbsp;0;<br>但在OP中可以简化成:<br>with&nbsp;poC.oStock.aoTradesLast130Days[0]&nbsp;do<br>begin<br>lVol&nbsp;:=&nbsp;0;<br>dHigh&nbsp;:=&nbsp;0;<br>dLow&nbsp;:=&nbsp;0;<br>dClose&nbsp;:=&nbsp;0;<br>end;<br><br>=================================<br>批注<br>C++<br>有两种<br>//&nbsp;双斜线后为批注<br>/*&nbsp;批注&nbsp;*/<br><br>OP<br>有三种<br>//&nbsp;双斜线后为批注<br>{&nbsp;批注&nbsp;}<br>(*&nbsp;批注&nbsp;*)<br>=================================<br>流程控制<br>有五种流程控制指令,C++与OP都有,用法满像的.<br>~~~~~~~~~~~~~~~~~~~~~~~~~<br>1)&nbsp;if&nbsp;...&nbsp;else&nbsp;指令<br><br>C++<br><br>if(&lt;逻辑表达式&gt;)&nbsp;//&nbsp;一定要有()号<br>{&nbsp;...<br>}<br>else&nbsp;if(&lt;逻辑表达式&gt;)<br>{...<br>}<br>else<br>{...<br>}<br><br>OP<br><br>if&nbsp;&lt;逻辑表达式&gt;&nbsp;then&nbsp;//&nbsp;不一定要有()号,因有then<br>begin<br>...<br>end<br>else&nbsp;if&nbsp;&lt;逻辑表达式&gt;&nbsp;then<br>begin<br>....<br>end<br>else<br>begin<br>...<br>end;&nbsp;{最后一个end才要加;分号}<br><br>~~~~~~~~~~~~~~~~~~~~~~~~~<br>2)&nbsp;switch/case&nbsp;...&nbsp;指令<br>C++<br><br>switch()<br>{<br>case&nbsp;iX:&nbsp;...&nbsp;break;<br>case&nbsp;iY:&nbsp;...&nbsp;break;<br>default:&nbsp;...<br>}<br><br>OP<br><br>case&nbsp;of<br>{no&nbsp;&quot;begin&quot;&nbsp;here}<br>iX:&nbsp;<br>begin<br>...<br>end;&nbsp;{每个end都要;分号}<br>iY:<br>begin<br>...<br>end;<br>else&nbsp;{此处不用;号}<br>begin<br>...<br>end;<br>end;&nbsp;{这个end要;分号}<br><br><br>~~~~~~~~~~~~~~~~~~~~~~~~~<br>3)&nbsp;for&nbsp;...&nbsp;loop&nbsp;指令<br>C++<br><br>for(iCount&nbsp;=&nbsp;0;&nbsp;iCount&nbsp;&lt;=&nbsp;10;&nbsp;iCount++)<br>{&nbsp;<br>//&nbsp;iCount++,&nbsp;每次循环值加一<br>...<br>break;&nbsp;//&nbsp;中断循环<br>continue;&nbsp;//&nbsp;跳到下一个循环<br>...<br>}<br><br><br>OP<br><br>for&nbsp;iCount&nbsp;:=&nbsp;1&nbsp;to&nbsp;10&nbsp;do<br>begin<br>...&nbsp;{iCount每次自动加&nbsp;1}<br>break;&nbsp;{&nbsp;中断循环&nbsp;}<br>continue;&nbsp;{&nbsp;跳至下一个循环&nbsp;}<br>...<br>end;<br><br>~~~~~~~~~~~~~~~~~~~~~~~~~<br>4)&nbsp;while&nbsp;...&nbsp;loop&nbsp;指令<br>C++<br><br>while(&lt;逻辑表达式&gt;)<br>{<br>...<br>break;&nbsp;//&nbsp;中断循环<br>continue;&nbsp;//&nbsp;跳到下一个循环<br>...<br>}<br><br><br>OP<br><br>while&nbsp;&lt;逻辑表达式&gt;&nbsp;do<br>begin<br>...<br>break;&nbsp;{&nbsp;中断循环&nbsp;}<br>continue;&nbsp;{&nbsp;跳至下一个循环&nbsp;}<br>...<br>end;<br>~~~~~~~~~~~~~~~~~~~~~~~~~<br>5)&nbsp;do/repeat&nbsp;...&nbsp;指令<br>C++<br><br>do<br>{<br>//&nbsp;逻辑表达式&nbsp;False循环终止<br>...<br>break;&nbsp;//&nbsp;中断循环<br>continue;&nbsp;//&nbsp;跳到下一个循环<br>...<br>}while(&lt;逻辑表达式&gt;);<br><br><br>OP<br><br>repeat<br>//&nbsp;逻辑表达式&nbsp;True循环终止<br>...<br>break;&nbsp;{&nbsp;中断循环&nbsp;}<br>continue;&nbsp;{&nbsp;跳至下一个循环&nbsp;}<br>...<br>until&nbsp;&lt;逻辑表达式&gt;;<br>=================================&nbsp;<br>对象导向结构<br>C++与OP都可称为是对象导向式的语言.<br>C++可以用多重继承(multiple&nbsp;inheritance),OP只能单一继承(single&nbsp;inheritance)<br>让我们来看看建立对象的基本语法:<br><br>C++<br>Classes必须定义在header檔中...<br>class&nbsp;LoanC&nbsp;//&nbsp;未有继承时<br>{<br>private:&nbsp;//&nbsp;内定为private<br>...<br>protected:&nbsp;//&nbsp;要有冒号<br>...<br>public:<br>...<br>};&nbsp;//分号结尾<br><br>在C++中单一继承的语法如下:<br>class&nbsp;B:&nbsp;A<br>{...};<br><br>在C++中多重继承的语法如下:<br>class&nbsp;D:&nbsp;A,&nbsp;B,&nbsp;C<br>{...};<br><br>classes继承对象时可标明public,&nbsp;protected,&nbsp;或&nbsp;private.<br>内定是为&nbsp;private<br>class&nbsp;D:&nbsp;public&nbsp;A,&nbsp;public&nbsp;B,&nbsp;private&nbsp;C<br>{...};<br><br>OP<br>Classes是在unit/file中的&nbsp;&quot;type&quot;&nbsp;结构中宣告...<br>type<br>LoanC&nbsp;=&nbsp;class(TObject)&nbsp;<br>{这表是从TObject继承下来.&nbsp;}<br>{此处不用&nbsp;&quot;begin&quot;&nbsp;指令}<br>private<br>...<br>protected&nbsp;{此处不用冒号}<br>...<br>public<br>...<br>published<br>...<br>end;<br>关键词&nbsp;private,&nbsp;protected,&nbsp;public,&nbsp;及&nbsp;published&nbsp;(只有OP有)&nbsp;指明了<br>每一个数据元素的数据范围宽广.<br>private:只能给在Class内部使用<br>protected:只能给这个Class或演生的Class使用<br>public:可以在程序所有的地方使用<br>Published:Delphi专用,用来建立接口<br>每一个Class需要一个建立者(constructor)<br>在C++理,建立者与class同名.<br>建立者可加参数:<br>ie:<br>LoanC();&nbsp;//&nbsp;无参数<br>LoanC(double&nbsp;&amp;dCurrentBal);&nbsp;//&nbsp;一个参数<br>LoanC(double&nbsp;&amp;dBalOne,&nbsp;double&nbsp;&amp;dBalTwo);&nbsp;//&nbsp;两个参数<br><br>在OP理,建立者与class不同名.<br>ie:<br>constructor&nbsp;MyLoanOne;&nbsp;{no&nbsp;parameters}<br>constructor&nbsp;MyLoanTwo(var&nbsp;dCurrentBal:&nbsp;double);<br>constructor&nbsp;MyLoanThree(var&nbsp;dBalOne,&nbsp;dBalTwo:&nbsp;double);<br>C++与OP都提供解构者(destructors),也可称为释放内存(free&nbsp;memory)<br>在C++理,&nbsp;解构者与建构者一样,与class同名.<br>如:<br>~LoanC();&nbsp;//&nbsp;C++&nbsp;destructor<br><br>在OP理,&nbsp;解构者与class不同名.<br>如:<br>destructor&nbsp;LoanC.Destroy;<br>begin<br>oLoanDate.Free;<br>...<br>inherited&nbsp;Destroy;&nbsp;{&quot;inherited&quot;&nbsp;is&nbsp;a&nbsp;keyword}<br>end;<br>建立一个新对象,宣告一个变量:<br>double&nbsp;dAmount&nbsp;=&nbsp;1515.75;<br>LoanC&nbsp;oMyLoan(dAmount);<br>如此做会配置一块内存,<br>如果用只标方式可以如下宣告:<br>double&nbsp;dAmount&nbsp;=&nbsp;1515.75;<br>LoanC&nbsp;*&nbsp;poMyLoan&nbsp;=&nbsp;new&nbsp;LoanC(dAmount);<br>在OP理则不同,每一个都是指标.<br>var<br>dAmount:&nbsp;double;<br>oMyLoan:&nbsp;LoanC;<br>begin<br>{oMyLoan&nbsp;does&nbsp;not&nbsp;yet&nbsp;exist!}<br>dAmount&nbsp;:=&nbsp;1515.75;<br>oMyLoan&nbsp;:=&nbsp;LoanC.MyLoanTwo(dAmount);&nbsp;{now&nbsp;it&nbsp;does}<br>在OP理也可也&nbsp;Override.<br>type<br>LoanC&nbsp;=&nbsp;class<br>...<br>constructor&nbsp;Create;&nbsp;{overrides&nbsp;TObject's&nbsp;Create}<br>...<br>end;<br>...&nbsp;and&nbsp;call&nbsp;the&nbsp;inherited&nbsp;Create&nbsp;constructor&nbsp;in&nbsp;the&nbsp;LoanC&nbsp;definition...<br>constructor&nbsp;LoanC.Create;<br>begin<br>inherited&nbsp;Create;&nbsp;{calls&nbsp;TObject's&nbsp;Create}<br>...<br>end;<br><br>C++与OP理引用内部元素采用如下语法:<br>oMyLoan.dPrincipal;<br>在C++中,使用指针引用内部元素采用如下语法:<br>poMyLoan-&gt;dPrincipal;<br>在C++中有三个运操作数:<br>1.&nbsp;&amp;&nbsp;取地址<br>2.&nbsp;*&nbsp;取指标<br>3.&nbsp;-&gt;&nbsp;印用元素<br>在OP中都用.(逗点号)<br>=================================<br>Containers<br>C++:Containers<br>typedef&nbsp;TISetAsVector&nbsp;tdCompanySet;<br>typedef&nbsp;TISetAsVectorIterator&nbsp;tdCSetIter;<br>...<br>int&nbsp;OwlMain(int,&nbsp;char*[])<br>{...<br>tdCompanySet&nbsp;oCompColl;<br>...<br>}<br>...<br>void&nbsp;MainForm::AddNewCompany()<br>{<br>CompanyC&nbsp;*&nbsp;poC&nbsp;=&nbsp;new&nbsp;CompanyC;<br>oCompColl.Add(new&nbsp;CompanyC(poC));<br>...<br>//&nbsp;now&nbsp;iterate<br>tdCSetIter&nbsp;oCIter(oCompColl);<br>while(oCIter)<br>{<br>poC&nbsp;=&nbsp;oCIter++;<br>//&nbsp;now&nbsp;use&nbsp;poC<br>...<br>}<br>}<br>OP:Containers<br>TMainForm&nbsp;=&nbsp;class(TForm)<br>...<br>public<br>oCompColl:&nbsp;TList;<br>...<br>end;<br>...<br>procedure&nbsp;TMainForm.AddNewCompany;<br>var<br>poC:&nbsp;CompanyC;<br>iCount:&nbsp;integer;<br>begin<br>poC&nbsp;:=&nbsp;CompanyC.Create;<br>...<br>oCompColl.Add(poC);<br>...<br>{now&nbsp;iterate}<br>for&nbsp;iCount&nbsp;:=&nbsp;0&nbsp;to&nbsp;oCompColl.Count&nbsp;-&nbsp;1&nbsp;do<br>begin<br>poC&nbsp;:=&nbsp;oCompColl.Items[iCount];<br>{now&nbsp;use&nbsp;poC}<br>...<br>end;<br><br>=================================<br>例外处理<br>C++:例外处理<br>try<br>{<br>...<br>}<br>catch()<br>{<br>...<br>}<br>catch(...)<br>{<br>...<br>}<br><br><br>OP:例外处理<br>try<br>{不用&nbsp;begin&nbsp;...&nbsp;end;&nbsp;指令}<br>...<br>finally<br>{例外处理}<br>...<br>end;<br><br>取得Run&nbsp;Time&nbsp;错误讯息时:<br>try<br>...<br>except<br>on&nbsp;do&nbsp;...&nbsp;;<br>end;<br><br>=================================<br>资料流(Streaming)<br><br>C++:资料流<br>class&nbsp;CompanyC<br>{<br>...<br>friend&nbsp;ofstream&nbsp;&amp;&nbsp;operator&nbsp;&lt;&lt;(ofstream&nbsp;&amp;oS,&nbsp;CompanyC&nbsp;*&nbsp;poC);<br>...<br>};<br>...<br>friend&nbsp;ofstream&nbsp;&amp;&nbsp;operator&nbsp;&lt;&lt;(ofstream&nbsp;&amp;oS,&nbsp;CompanyC&nbsp;*&nbsp;poC)<br>{<br>oS&nbsp;&lt;&lt;&nbsp;poC-&gt;dVersion<br>&lt;&lt;&nbsp;poC-&gt;dLastDivPerShare<br>&lt;&lt;&nbsp;poC-&gt;enIndustry<br>...<br>&lt;&lt;&nbsp;poC-&gt;sName;<br>return&nbsp;oS;<br>}<br><br>friend&nbsp;ofstream&nbsp;&amp;&nbsp;operator&nbsp;&lt;&lt;(ofstream&nbsp;&amp;oS,&nbsp;CompanyC&nbsp;*&nbsp;poC)<br>{<br>oS.write(&nbsp;(char*)&nbsp;&amp;&nbsp;(*poC),&nbsp;sizeof(*poC));<br>return&nbsp;oS;<br>}<br>//&nbsp;打开&nbsp;a&nbsp;stream<br>ofstream&nbsp;ofS(&quot;gamedata.gam&quot;);<br>if(!ofS)&nbsp;<br>return;<br>...<br>//&nbsp;存档<br>tdCSetIter&nbsp;oCIter(oCompColl);&nbsp;//&nbsp;see&nbsp;container&nbsp;section<br>while(oCIter)<br>{<br>poC&nbsp;=&nbsp;oCIter;<br>ofS&nbsp;&lt;&lt;&nbsp;poC;<br>}<br>ofS.close();<br><br><br>OP:资料流<br>type<br>CompanyC&nbsp;=&nbsp;class<br>public<br>procedure&nbsp;Read(var&nbsp;f:file);<br>procedure&nbsp;Write(var&nbsp;f:file);<br>...<br>end;<br>...<br>procedure&nbsp;CompanyC.Write(var&nbsp;f:file);<br>begin<br>BlockWrite(f,&nbsp;dVersion,&nbsp;sizeof(dVersion));<br>BlockWrite(f,&nbsp;dLastDivPerShare,&nbsp;sizeof(dLastDivPerShare));<br>BlockWrite(f,&nbsp;enIndustry,&nbsp;sizeof(enIndustry));<br>...<br>BlockWrite(f,&nbsp;sName,&nbsp;sizeof(sName));<br>end;<br><br>开档:<br>procedure&nbsp;TMainForm.FileSaveItemClick(Sender:&nbsp;TObject);<br>var<br>oGameFile:&nbsp;file;<br>iCount:&nbsp;integer;<br>poC:&nbsp;CompanyC;<br>sNameFile:&nbsp;string[13];<br>begin<br>...<br>sNameFile&nbsp;:=&nbsp;'gamedata.gam';<br>AssignFile(oGameFile,&nbsp;sFileName);<br>Rewrite(oGameFile,&nbsp;1);&nbsp;{the&nbsp;1&nbsp;means&nbsp;1&nbsp;byte&nbsp;at&nbsp;a&nbsp;time}<br>...<br>for&nbsp;iCount&nbsp;:=&nbsp;0&nbsp;to&nbsp;oCompColl.Count&nbsp;-&nbsp;1&nbsp;do<br>begin<br>poC&nbsp;:=&nbsp;oCompColl.Items[iCount];<br>poC.Write(oGameFile);<br>end;<br>CloseFile(oGameFile);<br>end;<br><br>=================================<br>项目档的设计<br>在&nbsp;C++中,常数定义放在.h文件中,程序放在.cpp中(会用#include&nbsp;.h檔)<br>在&nbsp;Delphi中,常数定义与程序都在一个文件.pas中<br>不同的.pas可用uses指令引用别的.pas宣告个变量<br>=================================<br>如何转换<br>如果要转有画面的C++程序要比转无画面的C++程序困难的多.<br>如果要转有画面的C++程序,要先在Dlephi开一Form,再将c++的程序代码转入.<br>要将程序copy&nbsp;至delphi中再来改.<br>1)&nbsp;先整体性的转换&nbsp;,将&nbsp;C++&nbsp;的{...}&nbsp;改为&nbsp;begin...end;<br>double&nbsp;CompanyC::NewAnnualReport_v(Economy&nbsp;&amp;&nbsp;oE)<br>{&nbsp;...&nbsp;//&nbsp;delimiter&nbsp;starts&nbsp;on&nbsp;a&nbsp;new&nbsp;line<br>}<br><br>...versus&nbsp;this...<br>double&nbsp;CompanyC::NewAnnualReport_v(Economy&nbsp;&amp;&nbsp;oE){&nbsp;//&nbsp;delimiter&nbsp;at&nbsp;end&nbsp;of&nbsp;line<br>...&nbsp;<br>}<br><br>2)&nbsp;a)&nbsp;将&nbsp;C++&nbsp;的&nbsp;||&nbsp;转为&nbsp;&quot;or&quot;<br>b)&nbsp;将&nbsp;C++&nbsp;的&nbsp;&amp;&amp;&nbsp;转为&nbsp;&quot;and&quot;<br>c)&nbsp;(1)将&nbsp;C++&nbsp;的&nbsp;==&nbsp;转为&nbsp;=<br>(2)将&nbsp;C++&nbsp;的&nbsp;=&nbsp;转为&nbsp;:=<br>d)&nbsp;将&nbsp;C++&nbsp;的&nbsp;/*&nbsp;*/&nbsp;转为&nbsp;{&nbsp;}<br>e)&nbsp;C++的&nbsp;//&nbsp;不用转<br>f)&nbsp;将&nbsp;双引号转为单引号&nbsp;&quot;&nbsp;-&gt;&nbsp;'<br><br>3)&nbsp;C++的每个if要加&nbsp;then<br>如:<br>C++<br>if(oE.enDirection&nbsp;==&nbsp;Up&nbsp;&amp;&amp;<br>oE.uNumMosUpYr&nbsp;&gt;=&nbsp;oE.uNumMosDownYr)<br>{<br>...<br>}<br><br>OP<br>if&nbsp;(oE.enDirection&nbsp;=&nbsp;Up)&nbsp;and<br>(oE.iNumMosUpYr&nbsp;&gt;=&nbsp;oE.iNumMosDownYr)&nbsp;then<br>begin<br>...<br>end;<br><br>4)&nbsp;将控制指令修改<br><br>5)&nbsp;C++的&nbsp;overloaded&nbsp;运算可&nbsp;re-written,那就看您在OP中要如何处理.<br>6)&nbsp;将&nbsp;C++&nbsp;的&nbsp;::&nbsp;转为&nbsp;.<br>procedure&nbsp;TForm1.Memo1Change(Sender:&nbsp;TObject);&nbsp;{要加上分号}<br>begin<br>...<br>end;<br>7)&nbsp;将&nbsp;C++&nbsp;的&nbsp;++&nbsp;和&nbsp;decrement&nbsp;--&nbsp;改为inc(x)&nbsp;与dec(<br>8)&nbsp;将C++在区块&nbsp;中宣告的变量全部移到var区中.<br>9)&nbsp;将C++的函数名称前加上&nbsp;&quot;function&quot;&nbsp;或&nbsp;&quot;procedure&quot;<br>10)&nbsp;将&nbsp;C++&nbsp;的&nbsp;-&gt;&nbsp;转为&nbsp;.&nbsp;(句点)<br>DateC&nbsp;oBirthDate;<br>var<br>oBirthDate:&nbsp;DateC;<br>begin<br>oBirthDate&nbsp;:=&nbsp;DateC.Create;<br>11)&nbsp;将&nbsp;C++&nbsp;的strcpy(...)&nbsp;与&nbsp;strcat(...)&nbsp;转为&nbsp;:=&nbsp;与&nbsp;+<br><br>12)&nbsp;那多重继承呢?(&nbsp;multiple&nbsp;inheritance).<br>用Class&nbsp;B继承Class&nbsp;A,再用class&nbsp;C继承&nbsp;B的方式&nbsp;.<br>=================================<br>结论<br>C++&nbsp;是简短的语言,&nbsp;而&nbsp;OP&nbsp;比较像英文.<br>然而C++较紧密,但不易阅读.<br><br>============完结=============
 
问题已解决!谢谢各位
 
后退
顶部