請問一個TMemorystream的Bug問題 |
尚未結案
|
willchen
初階會員 發表:64 回覆:81 積分:29 註冊:2003-05-23 發送簡訊給我 |
void __fastcall TForm1::DS_Launcher() { TSearchRec sr; int FileFound=FindFirst(OKpath "\\*.agn",faAnyFile,sr); while(FileFound==0) { //處理資料 TMemoryStream *filestream=new TMemoryStream(); filestream->LoadFromFile(OKpath sr.Name); DS_launcher_client->Socket->SendStream(filestream); DeleteFile((OKpath sr.Name).c_str()); //找下一個檔案 //delete filestream; FileFound=FindNext(sr); } }我之前在抓Bug的時候,都找半天找不到Bug在哪,結果找最後才找到delete filestream這行,我是覺得很奇怪,為何我自己new的東西,卻不能delete,一但delete就會出現Access violation...請問各位高手,如果調用TMemoryStream時 需要注意那些問題?? |
dllee
站務副站長 發表:321 回覆:2519 積分:1711 註冊:2002-04-15 發送簡訊給我 |
TMemoryStream 並沒有 BUG,在使用 SendStream 前請先看看使用說明。
以下是取自 BCB5 的 Online Help
引言: TCustomWinSocket::SendStream TCustomWinSocket See also Writes all the information that can be read from the AStream parameter to the socket connection. bool __fastcall SendStream(Classes::TStream* AStream); Description Use SendStream to write to the socket connection. The writing may occur in the OnSocketEvent event handler of a Windows socket object or in the OnWrite or OnClientWrite event handler of a socket component. Alternately, SendStream may write from a socket that is expected to write to the connection without a notification to signal the connections readiness to read. SendStream reads information from the stream indicated by AStream and writes it to the socket connection. The value returned by SendStream indicates whether any information was successfully written to the connection. Note: The Stream passed as a parameter to SendStream becomes ? owned?by the windows socket object. The Windows socket object frees the stream when it is finished with it. Do not attempt to free the stream after it has been passed as a parameter.其中已說明了,傳入的 Stream 參數不能再 delete 了,因為 SendStream() 已會自行處理。 沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com |
willchen
初階會員 發表:64 回覆:81 積分:29 註冊:2003-05-23 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |