我把唯一正确的方法写成函数怎么又不对了呢?
tmp.Add(Copy(PChar(mychar), 1, Length(mychar)));
………………》》》》
function chartostr(Buf:array of char):string;
begin
result:=Copy(PChar(Buf),1,Length(Buf)); //出错 Invalid typecast
end;
function chartostring(Bufchar):string;
var
s:string;
len:integer;
begin
len:= length(StrPas(Buf));
setlength(s,len);
move(Buf[0],s[1],len); //不能用strcopy
result:=s;
end;
function chartostring(Bufchar;length:integer):string;//char转变成string
var
s:string;
begin
setlength(s,length);
move(Buf[0],s[1],length); //不能用strcopy
result:=s;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
mychar:array of char;
begin
setlength(mychar,1);
mychar[0]:='t';
ShowMessage(chartostring(@mychar[0], Length(mychar)));
end;