線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1810
推到 Plurk!
推到 Facebook!

Array 問題

答題得分者是:jow
apple12
一般會員


發表:28
回覆:23
積分:10
註冊:2003-05-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-11-15 17:11:24 IP:202.64.xxx.xxx 訂閱
在程式開始會執行不列

type logtype = record
class : String[6];
type : String[100];
end;
logrecord : array of logtype;
begin
logrecord[i].class := 'a';
logrecord[i].type := 'b';
end

關閉程式時,會有以下錯誤
Exception EAccessViolation in modele XXX.exe at 000A110B.
Access violation at address 004a111B in module XXX.exe. Read of address1448EDAC.
jow
尊榮會員


發表:66
回覆:751
積分:1253
註冊:2002-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-11-15 18:10:11 IP:123.193.xxx.xxx 訂閱
(1)
type, class是Delphi保留字
(2)
logrecord : array of logtype;
其中logrecord 必須配置記憶體
SetLength(logrecord, a_length);
(3)
i 的範圍 0~Length(logrecord)-1
(4)
釋放記憶體 logrecord := nil;



===================引 用 apple12 文 章===================
在程式開始會執行不列

type logtype = record
class : String[6];
type : String[100];
end;
logrecord : array of logtype;
begin
logrecord[i].class := 'a';
logrecord[i].type := 'b';
end

關閉程式時,會有以下錯誤
Exception EAccessViolation in modele XXX.exe at 000A110B.
Access violation at address 004a111B in module XXX.exe. Read of address1448EDAC.
編輯記錄
jow 重新編輯於 2007-11-15 18:10:43, 註解 無‧
apple12
一般會員


發表:28
回覆:23
積分:10
註冊:2003-05-10

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-11-16 09:24:34 IP:202.64.xxx.xxx 訂閱
我有做Setlength,但仍然有錯。
完全想不到錯在那裡?
jow
尊榮會員


發表:66
回覆:751
積分:1253
註冊:2002-03-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-11-17 09:02:20 IP:123.193.xxx.xxx 訂閱
你的問題應該不大, 能否將完整程式碼貼附上來?!

===================引 用 apple12 文 章===================
我有做Setlength,但仍然有錯。
完全想不到錯在那裡?
kevin2004
資深會員


發表:18
回覆:463
積分:416
註冊:2005-05-29

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-11-18 06:05:58 IP:61.231.xxx.xxx 訂閱
你寫的就好幾個錯,不用等退出,Compile就通不過

type logtype = record
class : String[6];
type : String[100];
end;

===>class與type是保留字,不可作欄位名稱

logrecord : array of logtype;
begin
logrecord[i].class := 'a';
logrecord[i].type := 'b';
end

==>i未在Var中定義
==>i 是未定義值,不可

------
Kevin
apple12
一般會員


發表:28
回覆:23
積分:10
註冊:2003-05-10

發送簡訊給我
#6 引用回覆 回覆 發表時間:2007-11-19 09:39:59 IP:202.64.xxx.xxx 訂閱



type logtype = record
subclass : String[6];
tablename : String[20];
end;
public
logrecord : array of logtype;
程式開始時會啟動以下:

procedure TfrmMain.Init;
var w_query : TSQLQuery;
i : Integer;
begin
w_query := TSQLQuery.Create(Nil);
w_query.SQLConnection := DM.SQLConnection1;
w_query.Close;
w_query.sql.Clear;
w_query.Sql.add('select * from abc ');
w_query.Open;
i := 0;
SetLength(logrecord, w_query.recordcount-1);
while not w_query.Eof do
begin
logrecord[i].subclass := w_query.fieldbyname('raditem').asstring;
logrecord[i].tablename := w_query.fieldbyname('value').asstring;
inc(i);
w_query.Next;
end;
w_query.Free;
end;

當結束程式時,便會有錯誤。
如果不執行上述,便不會有錯。
jow
尊榮會員


發表:66
回覆:751
積分:1253
註冊:2002-03-13

發送簡訊給我
#7 引用回覆 回覆 發表時間:2007-11-19 10:01:38 IP:210.66.xxx.xxx 訂閱
要做陣列邊界檢查.........

while ( i < Length(logrecord) ) and not w_query.Eof do


編輯記錄
jow 重新編輯於 2007-11-19 10:02:12, 註解 無‧
apple12
一般會員


發表:28
回覆:23
積分:10
註冊:2003-05-10

發送簡訊給我
#8 引用回覆 回覆 發表時間:2007-11-19 10:07:32 IP:202.64.xxx.xxx 訂閱
問題已解決,多謝jow的解答!
系統時間:2024-04-26 9:38:12
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!