把edit1.text里的内容如AAAA转为65656565这种型式,使用以下方法不行,而且死机!应怎么写?(50分)

W

wlyft

Unregistered / Unconfirmed
GUEST, unregistred user!
把edit1.text里的内容如AAAA转为65656565这种型式,使用以下方法不行,而且死机!
应怎么写?
var
s1,s2:string;
wlya:array[1..9] of pchar;
i1,i2:integer;
begin
s1:=edit1.text;
i1:=length(s1);
for i2:=1 to i1 do
begin
strcopy(wlya[i2],pchar(copy(s1,i2,1)));
s2:=s2+inttostr(integer(wlya[i2])))

end;
end;
 
My God!

Delphi Help:

Use StrCopy to copy a null-terminated string. StrCopy does not perform any length checking.
The destination buffer must have room for at least StrLen(Source)+1 characters.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
不错,你已经给指针数组wlya分配了空间,但是,你并没有为其中的指针分配空间(指针所指向的空间)。

改正非常简单:
wlya:array[1..9] of char;
strcopy(@wlya[i2],pchar(copy(s1,i2,1)));
Done.

不过,这样似乎更加简单:
for i2:=1 to i1 do
s2:=s2+inttostr(Byte(S1[i2]));
为什么一定要用中间数组呢?
 
也可以写为
for i2:=1 to i1 do
s2:=s2+inttostr(щкв(S1[i2]));
 
也可以写为
for i2:=1 to i1 do
s2:=s2+inttostr(ord(S1[i2]));
 
多人接受答案了。
 
顶部