想請問指標的問題 |
答題得分者是:chris_shieh
|
SamSam1230
中階會員 發表:128 回覆:178 積分:65 註冊:2004-12-23 發送簡訊給我 |
我現在有一個定義是 TableStruct : Array of String;
TableStruct_SIZE : Array of integer; 一般的指標用法是 var TableStruct_Count :^integer;
var X : integer; TableStruct_Count := @XXXTableStruct_Count;
X := TableStruct_Count^; 但我想我的指標是指著 Array of String , Array of integer我要怎樣定義跟使用呢? 謝謝
|
wameng
版主 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
|
chris_shieh
高階會員 發表:46 回覆:308 積分:240 註冊:2004-04-26 發送簡訊給我 |
array變數 本身就是Pointer
From Delphi Help:
Dynamic-array variables are implicitly pointers and are managed by the same reference-counting technique used for long strings. To deallocate a dynamic array, assign nil to a variable that references the array or pass the variable to Finalize; either of these methods disposes of the array, provided there are no other references to it. Dynamic arrays are automatically released when their reference-count drops to zero. Dynamic arrays of length 0 have the value nil. Do not apply the dereference operator (^) to a dynamic-array variable or pass it to the New or Dispose procedure. if X and Y are variables of the same dynamic-array type, X := Y points X to the same array as Y. (There is no need to allocate memory for X before performing this operation.) Unlike strings and static arrays, COPY-ON-WRITE is not employed for dynamic arrays, so they are not automatically copied before they are written to. ex: type TDynamicArrayType = Array of String; //要直接傳array 要先定義type ... procedure ClearArray(var aryOld:TDynamicArrayType); var aryNew:TDynamicArrayType; begin aryNew:=aryOld; Showmessage('aryNew:' IntToStr(Length(aryNew))); SetLength(aryOld,0); end; procedure TForm1.Button1Click(Sender: TObject); var aryOld:TDynamicArrayType; begin SetLength(aryOld, 3); aryOld[0]:='test0'; aryOld[1]:='test1'; aryOld[2]:='test2'; Showmessage('aryOld:' IntToStr(Length(aryOld))); ClearArray(aryOld); Showmessage('aryOld:' IntToStr(Length(aryOld))); end;@瞭解越多.懂得越少@ |
SamSam1230
中階會員 發表:128 回覆:178 積分:65 註冊:2004-12-23 發送簡訊給我 |
|
wameng
版主 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
|
chris_shieh
高階會員 發表:46 回覆:308 積分:240 註冊:2004-04-26 發送簡訊給我 |
|
SamSam1230
中階會員 發表:128 回覆:178 積分:65 註冊:2004-12-23 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |