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

如何從Form3呼叫Form1

答題得分者是:GrandRURU
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-04-21 12:32:52 IP:59.125.xxx.xxx 未訂閱
Form3是主視窗Form1、Form2是次視窗
那要如何按Form3Button1去呼叫Form1的次視窗呢
請大大幫忙解答一下,在下是個新手
或是應該怎麼重新寫才好

[code cpp]
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Form1->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
[/code]

[code cpp]
#include
#pragma hdrstop

#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
Form2->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TForm2::Button1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------

[/code]

[code cpp]
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm3::Form3Button1Click(TObject *Sender)
{
???????????????????
}
//---------------------------------------------------------------------------

[/code]





------
-謝謝大大熱心的回覆!謝謝!
編輯記錄
l90425 重新編輯於 2008-04-21 12:35:09, 註解 無‧
l90425 重新編輯於 2008-04-21 13:20:09, 註解 無‧
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-04-21 13:19:10 IP:203.75.xxx.xxx 未訂閱
[code cpp]
//---------------------------------------------------------------------------
#include
#pragma hdrstop

#include "Unit3.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm3::Form3Button1Click(TObject *Sender)
{
Form1->Show();
}
//---------------------------------------------------------------------------
[/code]
編輯記錄
GrandRURU 重新編輯於 2008-04-21 13:21:09, 註解 無‧
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-04-21 13:32:11 IP:59.125.xxx.xxx 未訂閱
謝謝大大的回答
請問大大按Form3Button1去呼叫Form1的次視窗
然後按Form1的Button1還能回到Form2
然後再按Form2的Button1還能回到Form3
這要怎麼寫呀
------
-謝謝大大熱心的回覆!謝謝!
編輯記錄
l90425 重新編輯於 2008-04-21 13:34:05, 註解 無‧
l90425 重新編輯於 2008-04-21 13:37:32, 註解 無‧
l90425 重新編輯於 2008-04-21 14:30:36, 註解 無‧
l90425 重新編輯於 2008-04-21 21:10:31, 註解 無‧
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-04-21 15:27:15 IP:203.75.xxx.xxx 未訂閱
按照這個方式就可以以此類推了,如果還有遇到問題再提出來問吧
===================引 用 l90425 文 章===================
謝謝大大的回答
請問大大按Form3Button1去呼叫Form1的次視窗
然後
按Form1的Button1還能回到Form2
然後再按Form2的Button1還能回到Form3
這要怎麼寫呀
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-04-21 16:48:14 IP:59.125.xxx.xxx 未訂閱

===================引 用 GrandRURU 文 章===================
按照這個方式就可以以此類推了,如果還有遇到問題再提出來問吧
===================引 用 l90425 文 章===================
謝謝大大的回答
請問大大按Form3Button1去呼叫Form1的次視窗
然後按Form1的Button1還能回到Form2
然後再按Form2的Button1還能回到Form3
這要怎麼寫呀

Form3主視窗Form1、Form2次視窗
如果用以下的方法就無法讓Form1在一開始就出現要
如何讓Form1一開始就出現,而且Form3為主視窗呢?

[code cpp]
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{

Form2->Show();
Close();
}
//---------------------------------------------------------------------------

[/code]

[code cpp]
//---------------------------------------------------------------------------

#include
#pragma hdrstop
#include "Unit3.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm2::Button1Click(TObject *Sender)
{
Form3->Show();
Close();
}
//---------------------------------------------------------------------------
[/code]

[code cpp]
//---------------------------------------------------------------------------

#include
#pragma hdrstop
#include "Unit1.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm3::Button1Click(TObject *Sender)
{
Form1->Show();
}
//---------------------------------------------------------------------------

[/code]

------
-謝謝大大熱心的回覆!謝謝!
編輯記錄
l90425 重新編輯於 2008-04-21 16:52:03, 註解 無‧
l90425 重新編輯於 2008-04-21 21:11:16, 註解 無‧
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#6 引用回覆 回覆 發表時間:2008-04-21 19:08:16 IP:220.139.xxx.xxx 未訂閱
Form3的onCreate事件中帶出Form1->Show()的方法,這樣就可以做到你所要求的了
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#7 引用回覆 回覆 發表時間:2008-04-21 21:23:04 IP:59.125.xxx.xxx 未訂閱

===================引 用 GrandRURU 文 章===================
Form3的onCreate事件中帶出Form1->Show()的方法,這樣就可以做到你所要求的了



會出現錯誤請問這是為什麼

[code cpp]
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------

void __fastcall TForm3::FormCreate(TObject *Sender)
{
Form1->Show();
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
Form1->Show();
}
//---------------------------------------------------------------------------
[/code]
------
-謝謝大大熱心的回覆!謝謝!
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#8 引用回覆 回覆 發表時間:2008-04-22 08:18:09 IP:203.75.xxx.xxx 未訂閱
剛剛測了一下,哈哈,寫到不該寫入的記憶體了,但不知道為什麼,哈!

另外提供程式碼:
[code cpp]
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit3.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
if(Form1)
Form1 = new TForm1(Application);

Form1->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm3::FormActivate(TObject *Sender)
{
Button1Click(Sender);
}
//---------------------------------------------------------------------------
[/code]

再試試看
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#9 引用回覆 回覆 發表時間:2008-04-22 09:46:56 IP:59.125.xxx.xxx 未訂閱

===================引 用 GrandRURU 文 章===================
剛剛測了一下,哈哈,寫到不該寫入的記憶體了,但不知道為什麼,哈!

另外提供程式碼:
[code cpp]
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit3.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
if(Form1)
Form1 = new TForm1(Application);

Form1->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm3::FormActivate(TObject *Sender)
{
Button1Click(Sender);
}
//---------------------------------------------------------------------------
[/code]

再試試看


成功了,實在太謝謝大大的用心指導了。3Q~
------
-謝謝大大熱心的回覆!謝謝!
jow
尊榮會員


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

發送簡訊給我
#10 引用回覆 回覆 發表時間:2008-04-22 11:05:14 IP:210.66.xxx.xxx 訂閱
嗯, 不正確的觀念, 如何寫出好程式?

即使是練習的程式範例,應該試著多方面考量
程式這樣寫的話, 似乎欠缺太多考量喔....

初學者應該多多建立正確的觀念, 這包括程式語言
及開發工具的特性...

個人觀點, 謹供參考...
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#11 引用回覆 回覆 發表時間:2008-04-22 11:18:20 IP:203.75.xxx.xxx 未訂閱
其實我也不太清楚正確的觀念是啥,只知道能動就好了 
還請jow大多多指點一番

對於多方面考量的部分~~~能不能再多說一點呢?

===================引 用 jow 文 章===================
嗯, 不正確的觀念, 如何寫出好程式?

即使是練習的程式範例,應該試著多方面考量
程式這樣寫的話, 似乎欠缺太多考量喔....

初學者應該多多建立正確的觀念, 這包括程式語言
及開發工具的特性...

個人觀點, 謹供參考...
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#12 引用回覆 回覆 發表時間:2008-04-22 19:35:48 IP:59.125.xxx.xxx 未訂閱

===================引 用 l90425 文 章===================

===================引 用 GrandRURU 文 章===================
剛剛測了一下,哈哈,寫到不該寫入的記憶體了,但不知道為什麼,哈!

另外提供程式碼:
[code cpp]
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Unit3.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
if(Form1)
Form1 = new TForm1(Application);

Form1->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm3::FormActivate(TObject *Sender)
{
Button1Click(Sender);
}
//---------------------------------------------------------------------------
[/code]

再試試看


成功了,實在太謝謝大大的用心指導了。3Q~

Form3是主視窗Form1、Form2是次視窗
不好意思小弟有一個問題如果用了以上的方法會出現一個問題
當Form2加入一個物件,如ComboBox有所選擇時會出現一個問題那就是
當按下
Form2的Button1按鈕後,他會在跳回 Form1,而不是Form3
ComboBox沒有做選擇時,就不會出現這個問題,正常的跳回 Form3
請問有辦法解決-謝謝大大
------
-謝謝大大熱心的回覆!謝謝!
編輯記錄
l90425 重新編輯於 2008-04-22 19:38:40, 註解 無‧
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#13 引用回覆 回覆 發表時間:2008-04-22 21:11:36 IP:220.139.xxx.xxx 未訂閱
把你實際想要表現的流程畫一下,再對照你目前的程式碼,大概就可以知道要加什麼了

比方說:
如果checkbox勾選的話…該怎麼做…
就是
if(checkbox->………)
xxx;
else
ooo;

這樣能懂嗎?
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#14 引用回覆 回覆 發表時間:2008-04-22 22:35:41 IP:59.125.xxx.xxx 未訂閱

===================引 用 GrandRURU 文 章===================
把你實際想要表現的流程畫一下,再對照你目前的程式碼,大概就可以知道要加什麼了

比方說:
如果checkbox勾選的話…該怎麼做…
就是
if(checkbox->………)
xxx;
else
ooo;

這樣能懂嗎?

恩我懂
Form2裡面的物件有CheckBox1和CheckBox2和Button1
但是我的問題是
如果我選擇Form2的CheckBox1或CheckBox2時
並按下Button1時他會跳回Form1而不是Form3
但是如果不做選擇時按下Form2的Button1他會正常的跳會Form3
以下是我的程式碼
有辦法解決嗎-謝謝大大

[code cpp]
//---------------------------------------------------------------------------

#include
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form2->Show();
Close();
}
//---------------------------------------------------------------------------

[/code]

[code cpp]
//---------------------------------------------------------------------------

#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include
#include
#include
#include <Forms.hpp><br />#include
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TCheckBox *CheckBox1;
TCheckBox *CheckBox2;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif

[/code]

[code cpp]
#pragma hdrstop
#include "Unit3.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm2::Button1Click(TObject *Sender)
{
Form3->Show();
Close();
}
//---------------------------------------------------------------------------

[/code]

[code cpp]
//---------------------------------------------------------------------------

#include
#pragma hdrstop
#include "Unit1.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{

}
//---------------------------------------------------------------------------


void __fastcall TForm3::Button1Click(TObject *Sender)
{
if(Form1)
Form1= new TForm1(Application);

Form1->ShowModal();

}
//---------------------------------------------------------------------------


void __fastcall TForm3::FormActivate(TObject *Sender)
{
Button1Click(Sender);
}
//---------------------------------------------------------------------------

[/code]
------
-謝謝大大熱心的回覆!謝謝!
編輯記錄
l90425 重新編輯於 2008-04-22 22:37:06, 註解 無‧
l90425 重新編輯於 2008-04-22 22:37:46, 註解 無‧
l90425 重新編輯於 2008-04-22 22:40:02, 註解 無‧
l90425 重新編輯於 2008-04-22 22:40:47, 註解 無‧
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#15 引用回覆 回覆 發表時間:2008-04-23 08:49:06 IP:203.75.xxx.xxx 未訂閱
請善用偵錯,一步一步查,這樣自己會比較清楚
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#16 引用回覆 回覆 發表時間:2008-04-23 09:16:12 IP:59.125.xxx.xxx 未訂閱
問題他在run的時候並沒有偵察到錯誤
只是在執行是會出現這個奇怪現象
所以也不知道哪裡出了錯誤
請問有辦法解決嗎---謝謝
------
-謝謝大大熱心的回覆!謝謝!
編輯記錄
l90425 重新編輯於 2008-04-23 09:18:01, 註解 無‧
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#17 引用回覆 回覆 發表時間:2008-04-23 09:31:09 IP:203.75.xxx.xxx 未訂閱
呃…錯了…是中斷點…你把每個button都下中斷點之後再看程式變化
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#18 引用回覆 回覆 發表時間:2008-04-23 16:43:32 IP:59.125.xxx.xxx 未訂閱

===================引 用 GrandRURU 文 章===================
呃…錯了…是中斷點…你把每個button都下中斷點之後再看程式變化

我嘗過了
他的現象是當我在Form2做了選擇時,並按下Form2的Button1後
會重新再執行一次FormActivate並跳回Form1
但是當我按下Form1的Button1卻會奇怪的跳Form3
有辦法解決以上的問題嗎---謝謝
------
-謝謝大大熱心的回覆!謝謝!
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#19 引用回覆 回覆 發表時間:2008-04-24 09:48:06 IP:59.125.xxx.xxx 未訂閱
我又試了其他的方法可以解決
如有更好的方法請大大再回覆給小弟-謝謝以上或以下大大的回答

參考
[code cpp]
//---------------------------------------------------------------------------

#include
#pragma hdrstop
#include "Unit1.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{

}
//---------------------------------------------------------------------------


void __fastcall TForm3::Button1Click(TObject *Sender)
{
if(Form1)
Form1= new TForm1(Application);

Form1->ShowModal();

}
//---------------------------------------------------------------------------


void __fastcall TForm3::FormShow(TObject *Sender)
{
Button1Click(Sender);
}
//---------------------------------------------------------------------------

[/code]

[code cpp]
//---------------------------------------------------------------------------

#include
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form2->ShowModal();
Close();
}
//---------------------------------------------------------------------------

[/code]
------
-謝謝大大熱心的回覆!謝謝!
編輯記錄
l90425 重新編輯於 2008-04-24 10:11:12, 註解 無‧
系統時間:2024-04-27 9:14:23
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!