CnPack Open Source Projects - 认识数组 array[m..n] of x
  Home Page News Downloads Nightly Build Documents Donation Forum Credits 简体中文
 Latest Releases

 
CnWizards 1.5.1.1219
[2024-11-03]

 
CnVCL 20241103
[2024-11-03]
  Nightly Build
  CnWizards Timeline
 Project Links
 

 
CnPack at GitHub
Use GitHub
 Visitors
Today Visitors: 367
Today Pages: 2799
Total Visitors: 5301987
Total Pages: 21370896
Since: 2003-09-01
 
认识数组 array[m..n] of x
 
CnPack Open Source Projects 2007-03-07 20:02:55

认识数组 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 类型的参数。


3、数组下标可以为负。



Page hits: 9702 times
From: CnPack Open Source Projects

Previous | UpNext

Links:

(C)Copyright 2001-2024 CnPack Develop Team  Site author: JingYu Zhou