不同Unit之間,如何共用record |
答題得分者是:eaglewolf
|
shihyi
一般會員 發表:8 回覆:12 積分:4 註冊:2009-01-03 發送簡訊給我 |
各位先進
有個資料共用的問題 想請教大家 我在Unit1跟Unit2要共用Unit3中所訂義的record 我的record還滿簡單的,大概長這樣 [code delphi] info_t = record name: String; height: double; weight : double; end; [/code] 因為Unit1跟Unit2要共用這樣子的資料 於似乎我就傻傻的在Unit3這樣子的宣告 [code delphi] student_info : array[1..20] of info_t ; [/code] 不過這樣子宣告好像行不通 所以想請各位先進幫幫忙 麻煩大家了,謝謝~ |
eaglewolf
資深會員 發表:4 回覆:268 積分:429 註冊:2006-07-06 發送簡訊給我 |
|
chenyk
高階會員 發表:14 回覆:95 積分:171 註冊:2002-07-08 發送簡訊給我 |
範例: //======================================= {unit1} interface uses SysUtils; type info_t = record
a: double; b: double; end; ... //======================================= {unit3} interface uses unit1; ... 只要 record 是宣告在 interface ,unit3 有引用unit1 應該是能正常運作的 |
shihyi
一般會員 發表:8 回覆:12 積分:4 註冊:2009-01-03 發送簡訊給我 |
謝謝先進們的回覆
可能我說的不是很清楚 我盡可能再說明的詳細一點 我Unit1與Unit2想要共用Unit3的變數 然後我Unit3長成這樣 [code delphi] unit Unit3; interface uses StrUtils; var a : integer; //student_info : array[1..20] of info_t ; type info_t = record name : String; height : double; widght : double; end; implementation end. [/code] 意思就是說我在Unit1改變了a的值,Unit2也知道a的值改變了 這樣子的做法用Integer之類的型態是OK的 但是如果把上面的「student_info : array[1..20] of info_t ;」這行註解拿掉 Delphi會告訴我「Undeclared identifier: 'info_t'」,就是他看不懂什麼叫info_t 所以,要怎麼樣共用record 再麻煩各位先進了~ |
eaglewolf
資深會員 發表:4 回覆:268 積分:429 註冊:2006-07-06 發送簡訊給我 |
把type 宣告放在var前面
你要先宣告type info_t compiler才會知道有info_t [code delphi] type info_t = record name: String; height: double; weight : double; end; var student_info : array[1..20] of info_t ; [/code] ===================引 用 shihyi 文 章=================== 謝謝先進們的回覆 可能我說的不是很清楚 我盡可能再說明的詳細一點 我Unit1與Unit2想要共用Unit3的變數 然後我Unit3長成這樣 [code delphi] unit Unit3; interface uses StrUtils; var a : integer; //student_info : array[1..20] of info_t ; type info_t = record name : String; height : double; widght : double; end; implementation end. [/code] 意思就是說我在Unit1改變了a的值,Unit2也知道a的值改變了 這樣子的做法用Integer之類的型態是OK的 但是如果把上面的「student_info : array[1..20] of info_t ;」這行註解拿掉 Delphi會告訴我「Undeclared identifier: 'info_t'」,就是他看不懂什麼叫info_t 所以,要怎麼樣共用record 再麻煩各位先進了~
------
先查HELP 再查GOOGLE 最後才發問 沒人有義務替你解答問題 在標題或文章中標明很急 並不會增加網友回答速度 Developing Tool: 1.Delphi 6 2.Visual Studio 2005 3.Visual Studio 2008 DBMS: MS-SQL |
shihyi
一般會員 發表:8 回覆:12 積分:4 註冊:2009-01-03 發送簡訊給我 |
非常感謝大家
我的問題已經解決了~ ^O^ ===================引 用 eaglewolf 文 章=================== 把type 宣告放在var前面 你要先宣告type info_t compiler才會知道有info_t [code delphi] type info_t = record name: String; height: double; weight : double; end; var student_info : array[1..20] of info_t ; [/code] ===================引 用 shihyi 文 章=================== 謝謝先進們的回覆 可能我說的不是很清楚 我盡可能再說明的詳細一點 我Unit1與Unit2想要共用Unit3的變數 然後我Unit3長成這樣 [code delphi] unit Unit3; interface uses StrUtils; var a : integer; //student_info : array[1..20] of info_t ; type info_t = record name : String; height : double; widght : double; end; implementation end. [/code] 意思就是說我在Unit1改變了a的值,Unit2也知道a的值改變了 這樣子的做法用Integer之類的型態是OK的 但是如果把上面的「student_info : array[1..20] of info_t ;」這行註解拿掉 Delphi會告訴我「Undeclared identifier: 'info_t'」,就是他看不懂什麼叫info_t 所以,要怎麼樣共用record 再麻煩各位先進了~ |
max5020
資深會員 發表:30 回覆:277 積分:321 註冊:2003-06-04 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |