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

如何專案中2個form傳遞變數

答題得分者是:mi86018
Komuro
一般會員


發表:27
回覆:46
積分:14
註冊:2004-02-19

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-03-17 11:07:08 IP:61.66.xxx.xxx 未訂閱
專案(dpr)中有2個Form,一個Form如何取用另一個Form的變數?
mi86018
一般會員


發表:20
回覆:39
積分:21
註冊:2003-11-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-03-17 11:56:23 IP:61.222.xxx.xxx 未訂閱
假設:form2 有一個變數temp,要讓form1的buttom1按下後,form1的edit1顯示temp的值。    form2程式碼:     
unit Unit2;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;    type
  TForm2 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    temp:String;
    { Public declarations }
  end;    var
  Form2: TForm2;    implementation    {$R *.dfm}    procedure TForm2.FormCreate(Sender: TObject);
begin
  temp := 'abcd';
end;    end.
 
------------------------- form1程式碼:
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;    type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    implementation    uses Unit2;    {$R *.dfm}    procedure TForm1.Button1Click(Sender: TObject);
begin
  edit1.Text := form2.temp;
end;    end. 
我是頭號「問題」份子...
Komuro
一般會員


發表:27
回覆:46
積分:14
註冊:2004-02-19

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-03-17 13:25:39 IP:61.66.xxx.xxx 未訂閱
一時疏忽犯了錯誤,將temp變數放在{ Public declarations }這行之後造成 [Error] frmMainMess.pas(35): Field definition not allowed after methods or properties,感謝你的範例讓我找出錯誤
系統時間:2024-05-12 14:33:55
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!