CnPackTip#3:認識靜態數組 array[m,n] of x

來源:互聯網
上載者:User
認識靜態數組 array[m,n] of x

Written by SkyJacker
http://www.cnpack.org
CnPack IV  QQ Group: 130970
2007-3-7

年前 passion 和 Bahamut討論過。
這裡總結一下,有誤之處請指出。

var
  A: array[0..0] of Char;   // 表示一個字元。即 array[0..0] 表示一個此類型的元素
  B: array[0..10] of Char;  // 下標從0開始的Char數組可以把數組名當作PChar來使用;也可以用字串直接賦值
  C: array[1..10] of Char;  // 普通數組
  D: array[-1..10] of Byte; // 普通數組
  I: Integer;
begin
  A[0] := 'A';
  B := 'BC';
  C[1] := 'D';
  D[-1] := 2;
  D[0] := Ord('F');
  D[1] := Ord('A');
  for I := - 1 to 3 do
  begin
    ShowMessage(IntToStr(D[I]));
  end;
  ShowMessage(A + '-' + B + '-' + C);
end;

1、關於"Zero-based character arrays" 的 Delhpi Help:
//An array type of the form array[0..x] of Char is called a zero-based character array.
//Zero-based character arrays are used to store null-terminated strings and are compatible with PChar values

2、array[0..0] 的意義是什嗎?
是為了方便傳遞 array 類型的參數。
可以參考 CnPackTip#4 <<New() 的學習>>

3、數組下標可以為負。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.