全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1040
推到 Plurk!
推到 Facebook!

不同Unit之間,如何共用record

答題得分者是:eaglewolf
shihyi
一般會員


發表:8
回覆:12
積分:4
註冊:2009-01-03

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-03-18 09:11:49 IP:112.78.xxx.xxx 訂閱
各位先進

有個資料共用的問題
想請教大家
我在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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-03-18 09:34:20 IP:211.75.xxx.xxx 未訂閱
所謂的行不通是指?
------
先查HELP
再查GOOGLE
最後才發問

沒人有義務替你解答問題
在標題或文章中標明很急
並不會增加網友回答速度

Developing Tool:
1.Delphi 6
2.Visual Studio 2005
3.Visual Studio 2008
DBMS:
MS-SQL
chenyk
高階會員


發表:14
回覆:95
積分:171
註冊:2002-07-08

發送簡訊給我
#3 引用回覆 回覆 發表時間:2010-03-18 10:08:19 IP:125.230.xxx.xxx 未訂閱
範例:
//=======================================
{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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2010-03-18 10:58:35 IP:220.130.xxx.xxx 訂閱
謝謝先進們的回覆
可能我說的不是很清楚
我盡可能再說明的詳細一點

我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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2010-03-18 15:23:20 IP:211.75.xxx.xxx 未訂閱
把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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2010-03-18 16:58:24 IP:220.130.xxx.xxx 訂閱
非常感謝大家
我的問題已經解決了~ ^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
資深會員


發表:29
回覆:277
積分:321
註冊:2003-06-04

發送簡訊給我
#7 引用回覆 回覆 發表時間:2010-03-18 16:59:55 IP:59.125.xxx.xxx 訂閱
改成這樣子

[code delphi]
unit Unit3;
interface
uses
StrUtils;

type
info_t = record
name : String;
height : double;
widght : double;
end;

var
a : integer;
student_info : array[1..20] of info_t ;

implementation
end.
[/code]

系統時間:2024-04-26 19:38:39
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!