比如一個結構體 position ,如何在FORM1和FORM2 共用,修改其資料?
struct position {
int x;
int y;
float p;
} ;
position position [17][41][20];
uj5u.com熱心網友回復:
包含對方的頭檔案應該就可以了。uj5u.com熱心網友回復:
不行的,我同時定義了變數和結構體例如
struct position {
int x;
int y;
float p;
} ;
position position [17][41][20];
int ABC;
在FORM2表單里修改 ABC ,在FORM1里看到
uj5u.com熱心網友回復:
在FORM2表單里修改 ABC ,在FORM1里看到ABC 變化了,但修改position [0][0][0],z
則不變化。
uj5u.com熱心網友回復:
代碼貼出來看看
uj5u.com熱心網友回復:
將下面的代碼放到一個.h檔案中,兩個視窗都包含這個.h檔案struct position {
int x;
int y;
float p;
} ;
extern position position [17][41][20];//宣告外部變數
其中一個視窗,再次定義position position [17][41][20];
這樣,這個 position [17][41][20];在工程中是全域的
uj5u.com熱心網友回復:
5樓即可
uj5u.com熱心網友回復:
參考:[初學者]C++ Builder一個最簡單的多檔案多表單的程式例子
http://download.csdn.net/detail/u010165006/8992607
uj5u.com熱心網友回復:
1.定義全域變數2.某個類中定義為public,另一個類訪問 class->XXXX
uj5u.com熱心網友回復:
兩個表單共用變數,互相包含對方頭檔案,然后在各自的頭檔案中宣告變數,在cpp檔案中定義即可。舉個例子:Unit1 中有結構體 A 的變數 a 需要共享,Unit2 中有結構體 B 的變數 b 需要共享,那么:
Unit1.h 檔案
struct A
{
...
};
extern A a;
Unit1.cpp 檔案
A a;
Unit2.h 檔案
struct B
{
...
};
extern B b;
Unit2.cpp 檔案
B b;
然后在 Unit1 和 Unit2 中就可以隨意使用 a 和 b 了。
uj5u.com熱心網友回復:
我一般都是在Form2里面使用Form1->a,
在Form1里面使用Form2->b,
這樣使用沒問題吧?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/85972.html
標籤:基礎類
上一篇:不知道哪里出錯
下一篇:警告用指標P時警告warning: assignment from incompatible pointer type| airline *modefy_air
