線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1250
推到 Plurk!
推到 Facebook!

變數??

答題得分者是:Justmade
lilisn
一般會員


發表:35
回覆:62
積分:24
註冊:2003-03-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-03-14 19:51:30 IP:61.228.xxx.xxx 未訂閱
不要笑我是笨,看過之前發表 http://delphi.ktop.com.tw/topic.php?topic_id=21433    ,自己test有問題不知為何無法取得unit1 (s:string)        unit Unit1;    interface    uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, StdCtrls;    type   TForm1 = class(TForm)     Button1: TButton;     procedure Button1Click(Sender: TObject);   private     { Private declarations }   public     { Public declarations }     s:string; // 在此宣告   end;    var   Form1: TForm1;    implementation uses unit2;    {$R *.dfm}    procedure TForm1.Button1Click(Sender: TObject); begin   s:='1234';   Form2:= TForm2.create(self);   Form2.showmodal; end; end. ******************unit2********* unit Unit2; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, StdCtrls, Buttons; type   TForm2 = class(TForm)     Label1: TLabel;     BitBtn1: TBitBtn;     procedure FormActivate(Sender: TObject);   private     { Private declarations }   public     { Public declarations }   end;    var   Form2: TForm2;    implementation uses unit1;   // 使用unit1    {$R *.dfm}    procedure TForm2.FormActivate(Sender: TObject); begin   label1.Caption := S ; //run 時出錯,無法取得unit1 (s:string) end;    end.    
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-03-14 20:09:04 IP:218.16.xxx.xxx 未訂閱
因為你 S 是寫在 TForm1 裡,所以你是要通過 Form1 存取的。 label1.Caption := Form1.S ; 若你想 S 變數獨立於 TForm1 , 你可以 type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } // 不要在此宣告 end; var Form1: TForm1; S : String; // 在此宣告 implementation ... ... 這樣,你便可在 unit2 使用 label1.Caption := S ;
lilisn
一般會員


發表:35
回覆:62
積分:24
註冊:2003-03-09

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-03-14 22:48:01 IP:61.228.xxx.xxx 未訂閱
引言: ok , 謝謝
系統時間:2024-05-13 4:38:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!