内存异常是因为你的字符串指针没有申请内存就直接使用。temp:pchar。
显示的字符串中有#0,系统认为是字符串结尾。调试一下,查看temp的情况,就能发现所有的硬盘盘符都已经读出来了。

解决方案 »

  1.   

    这个函数返回的盘符是以null分隔开的,如c:\<null>d:\<null><null>  
    应该怎么样才能将它们提取出来呢?
      

  2.   

    放到fromcreate 立会有问题的 label1还未创建
    onactive or onshowprocedure TForm1.Button1Click(Sender: TObject);
    var
      temp:array [0..255] of char;
      i:integer;
    begin
      FillChar(temp[0],256,0);
      getlogicaldrivestrings(255,temp);
      for i:= 0 to 254 do
      begin
        if temp[i]=#0 then
          if temp[i+1]=#0 then
            label1.Caption :=temp
          else temp[I]:=';';
      end;end;
      

  3.   

    但getlogicaldrivestrings函数只能用pchar型的字符串啊。用字符型数组不行的。而且当temp为字符型数组时,用pchar(temp)编译无法通过。还请大虾指点。thx.
      

  4.   

    改为:
    var
        temp:array of char;
        i:integer;
        iLen:integer;
    begin
        SetLength(temp,255);
        iLen:=getlogicaldrivestrings(255,pChar(test));
        for i:=0 to iLen-1 do
        begin
    {
    可以再进行逐字符的判断,是否为#0。
    }
        end;
    end;