如题

解决方案 »

  1.   

    S:string;   
      bs:   array   of   byte;   
      begin   
            S:='1234567';   
            for   i:=   0   to   6   do   
            begin   
                    Bs[i]:=ord(s[i+1]);   
            end;   
      end; 
      

  2.   

    找了好多函数copystr,copymemory什么的,都不行...
    可以了,谢谢哈
      

  3.   

    var
     Buf:array [0..7] of Byte;
     S: String;
    begin
    ...
    ...
     copymemory(@Buf, @S, Length(S));
    end;
    copymemory不行啊,
      

  4.   

    var
      buf: array of Byte;
      str: String;//可能是AnsiString也可能是UnicodeString
      iLen: Integer;  
      iBytes: Integer;
    begin
      ...
      iLen := Length(str);
      if iLen <= 0 then begin
        //0字节,或者超大(可能异常)
        buf := Nil;
        Exit;
      end;  iBytes := iLen * sizeof(str[1]);  SetLength(buf, iBytes);
     
      Move(str[1],buf[0], iBytes);
      ...
    end;
      

  5.   

    不能直接使用@s,要使用PChar(S),或者@S[1]