推 chchwy:就說要貼能重現錯誤的完整code了 你貼的部分都沒問題 09/09 09:35
→ chchwy:錯的是你沒貼出來的其他部分 09/09 09:35
→ chchwy:繼承的變數就是這樣設值沒有錯 有設了就應該會變true 09/09 09:36
對不起,為了要簡化說明,我的程式碼會與例子有出入
↓這是類別Parameter
public class Parameter
{
public string filepath;
public bool open_bin = false; //contorl open file as bin map
public bool open_distribution = false; //contorl open file as distribution data
}
public class Function:Parameter
{
public bool binmap = false; //contorl function of map enabled
public bool distribution = false; //contorl function of distribution enable
public bool ampi_test = false; //contorl cp test as ampi
public bool apce = false; //contorl cp test as apce
//==============================================================================
//↓這是form2上button click
string filename = fileListBox1.FileName;
Parameter file=new Parameter();
file.filepath = filename;
file.open_bin = true;
Function mfunction = new Function();
mfunction.binmap = true;
mfunction.ampi_test=true;
//==============================================================================
//↓這是主程式form1 上button click
Function mfunction = new Function();
Parameter file = new Parameter();
if (file.open_bin == true)
{
if (mfunction.binmap == true)
{
string filename = file.filepath;
System.IO.StreamReader machinefile = new System.IO.StreamReader(filename);
}
else
{
MessageBox.Show("The Function have mistake,Please Check your data and datalog file!", "Caution", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Please Open File", "Caution", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
理論上來說,我form2按下button後 open_bin要=true,但我實際執行後 open_bin確還是
false
※ 編輯: chrishappy11 來自: 182.234.232.171 (09/09 09:46)
※ 編輯: chrishappy11 來自: 182.234.232.171 (09/09 09:47)
※ 編輯: chrishappy11 來自: 182.234.232.171 (09/09 09:54)
→ XFantasyX:你那兩個button_click裡面的Parameter跟Function是不同 09/09 10:05
→ XFantasyX:的物件 去google一下"變數生命周期" 就會了解了 09/09 10:06