字符串的长度如何超过255?(50分)

E

erx

Unregistered / Unconfirmed
GUEST, unregistred user!
字符串的长度如何超过255并且可以以数组的方式保存在文件当中,
例如

child=Record
data:WIDESTRING *****
end;

afile=Record
every:ARRAY [1..1000] of child;
end;

*****这样变异是不能通过的,而改成data:STRING[255]就可以了
我想超过255,该怎么办?谢谢!
 
type
child=Record
data:WIDESTRING;// *****
end;

type afile=Record
every:ARRAY [1..1000] of child;
end;
可以通过呀!若你想定长的话,用string[255]是表示用shortString,它有255字节的限制.你
可用array[0..1023] of char来设定也行.
如下:
type
child=Record
data:array[0..1023] of char;// *****
end;

type afile=Record
every:ARRAY [1..1000] of child;
end;
 
var
S:String;
begin
S:=' ....';//这样不能超过 255;但像下面这样可以
S:=' ..'+'....'+'...'+...;
end;
 
编译可以通过的,你得修改一下编译选项,把Huge strings打勾。
 
program Project1;
{$H+}
{$APPTYPE CONSOLE}
uses
SysUtils;
type
dataStructure=Record
mapAddress:ANSISTRING;
end;

fileStructure=Record
data:ARRAY [1..2000] of dataStructure;
end;

var
F:File of fileStructure;
begin
assign(F,'d:/a.dat');
rewrite(F);
reset(F);
close(F);
readln;
end.

变异结果
[Error] Project1.dpr(18): Type 'fileStructure' needs finalization - not allowed in file type
 
File of fileStructure这种方式下的string不能是自管理类型的长字符串
只能是ShortString
 
对呀对呀,该怎么解决?
 
数组吖或者用PChar都可以。。
 
具体怎么做?
 
srtlength(var,size);
然后就可以拉
 
不是啦,写入文件的纪录,必须长度固定,你用
array [0..1000] of char来代替就可以了。:)
 
用PChar怎么向带有结构的文件中存储?
 
用Pchar比较麻烦,Pchar实际上是一个指针,因此长度固定是4Byte,
如果你要保存那个Pchar字符串的话,必须保存Pchar所指的字符串!类似下面的:

write(f,child.Pchar^,PchrLength);
 
那么数据结构怎么定义?
除了这个,还有其他的一些比如 no : BYET等等
它们同时在一个文件中
 
關注!!!!
 
array[0..1023] of widechar;
 
定长的字符串当然不能超过255了,因为定长字符串是段字符串
描述结构如下
type
TSString=record
StrLength:Word;///注意这里表示的是字符的长度,是Word型,最大长度255。
StrData:array[strLength-1] of char;
end;
在这里要想突破255就不要用定长字符创,可用静态的字符数组
如下:
child=Record
data:array[0..1000] of char;///这里就不会受到255的限制,但要记住对这段内存要初始化,不然的话会出现乱码。
end;

afile=Record
every:ARRAY [1..1000] of child;
end;
 
在单元加入编译指令{$H+}
 

Similar threads

S
回复
0
查看
956
SUNSTONE的Delphi笔记
S
S
回复
0
查看
779
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
顶部