var str:String[4];
begin
str:='3456';
edit1.Text:=str[0];
end;
为什么在edit1中返回的是个空格,我知道str[0]中存放的内容是str的长度4,str[0]在内存中到底是
以什么形式存放的?????请大家指点一下
begin
str:='3456';
edit1.Text:=str[0];
end;
为什么在edit1中返回的是个空格,我知道str[0]中存放的内容是str的长度4,str[0]在内存中到底是
以什么形式存放的?????请大家指点一下
procedure TForm1.Button1Click(Sender: TObject);
var str:String[4];
begin
str:='3456';
edit1.Text:=InttoStr(Byte(str[0]));
end;执行后显示“4”
而直接读取时编译器将str[0]当做字符处理,显示出来就像一个空格。
var str:String[4];
begin
str:='3456';
edit1.Text:=inttostr(ord(str[0]));end;
注意:String[4]作为短串,它的string[0]是可访问的,如果是长串,它的[0]就不可访问了
尽量不要用string[0]
请再指点下
[长度]数据
所以它的长度不能超过255个字符
A ShortString is 0 to 255 characters long. While the length of a ShortString can change dynamically, its memory is a statically allocated 256 bytes; the first byte stores the length of the string, and the remaining 255 bytes are available for characters. If S is a ShortString variable, Ord(S[0]), like Length(S), returns the length of S; assigning a value to S[0], like calling SetLength, changes the length of S. ShortString uses 8-bit ANSI characters and is maintained for backward compatibility only.
str:='3456';
内存中为
$04 $33 $34 $35 $36
第一个$04就是长度(HELP写得很清楚了),后面就是3456的ascii码