setlength(var s;newlength:integer);
   曾在一书中看到 setlength(s,256)这个函数怎么理解?
分配空间,这个空间是什么?
对于newlengh这个参数,控件大全一书明明讲了是在0-255,如果超过将怎样?

解决方案 »

  1.   

    string在dephi中长度为255,所以用setlength设置可变长度字符串时,其长度当然不能超过255了。如果超过了地址将会报错了。
      

  2.   

    为动态数组指定维数
    如:
    var
       s: array of String;
       i: integer;
    begin
      setLength(s,12);
      for i:=low(s) to High(s) do
        s[i] := IntToStr(i);
    end;
      

  3.   

    setlength(var s;newlength:integer);
    帮助原文:Sets the length of a string or dynamic-array variable.
    译文:  设置一个字符串或一个动态数组的长度。
    如果是字符串:newlength必须是0~255之间。
    如果超过就会出错。
      

  4.   

    to 楼主:
    谁说string只能255个char的?
    填个10000char进去都没事,尽管setlength好了;此外
    1. turbo pascal中的string,或者delphi里的shortstring,是有255限制的;
    2. 在IDE里写string还是有限制的,长于255的string要自己连接字符串;
    3. to linzhengqun, shehyde:你们说的是shortstring;

    For a short-string variable, SetLength simply sets the length-indicator character (the character at S[0]) to the given value. In this case, NewLength must be a value between 0 and 255.
    4. 现在瞎说的书很多的。