全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1409
推到 Plurk!
推到 Facebook!

FileRead取出字串放入動態string

缺席
kensoong
初階會員


發表:31
回覆:70
積分:45
註冊:2003-05-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-24 12:38:18 IP:61.220.xxx.xxx 未訂閱
請教各位專家,謝謝...    Buffer : string 型態    
 fhandle := FileOpen(PATHNAME   '\'   filename, fmShareDenyNone);
 iLength := FileSeek(fhandle,0,2);
 FileSeek(fhandle,0,0);
 SetLength(Buffer, iLength 1);
 Buffer[iLength] := #0;     iBytesRead := FileRead(fhandle, Buffer, iLength );
 FileClose(fhandle);
iLength > 256,但是卻發現FileRead變成超大值,Buffer也有問題. ps:Buffer如何變成Long String ?這樣就可以了嗎? 謝謝各位...
allenchan
資深會員


發表:10
回覆:306
積分:283
註冊:2004-01-06

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-24 13:49:27 IP:203.70.xxx.xxx 未訂閱
引言: Buffer : string 型態 ps:Buffer如何變成Long String ?
A string represents a sequence of characters. Object Pascal supports the following predefined string types. Type Maximum length Memory required Used for ShortString 255 characters 2 to 256 bytes backward compatibility AnsiString ~2^31 characters 4 bytes to 2GB 8-bit (ANSI) characters WideString ~2^30 characters 4 bytes to 2GB Unicode characters; multi-user servers and multi-language applications AnsiString, sometimes called the long string, is the preferred type for most purposes. String types can be mixed in assignments and expressions; the compiler automatically performs required conversions. But strings passed by reference to a function or procedure (as var and out parameters) must be of the appropriate type. Strings can be explicitly cast to a different string type (see Typecasts). The reserved word string functions like a generic type identifier. For example, var S: string;
creates a variable S that holds a string. In the default {$H+} state, the compiler interprets string 
(when it appears without a bracketed number after it) as AnsiString. Use the {$H-} directive to 
turn string into ShortString.
發表人 - allenchan 於 2004/11/24 13:59:56
kensoong
初階會員


發表:31
回覆:70
積分:45
註冊:2003-05-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-11-24 14:11:47 IP:61.220.xxx.xxx 未訂閱
Sorry , 改PChar type與修改code才能解決... 感謝您的幫忙...自己也解決了...
allenchan
資深會員


發表:10
回覆:306
積分:283
註冊:2004-01-06

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-11-24 14:39:38 IP:203.70.xxx.xxx 未訂閱
引言: Sorry , 改PChar type與修改code才能解決... 感謝您的幫忙...自己也解決了...
不客氣,我只是把 Help 內容貼上來而已,沒能幫上忙 ~~ ^^
系統時間:2024-05-14 17:56:48
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!