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

有關變數傳遞的笨問題

尚未結案
caeser
一般會員


發表:4
回覆:3
積分:1
註冊:2005-06-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-10-07 11:09:33 IP:140.131.xxx.xxx 未訂閱
引言: --------------------------------------------------------------------------------    請問各位前輩 當程式去create一個form時 該如何將變數傳遞過去 或是該如何去讀取到原本form的變數    --------------------------------------------------------------------------------    在 FormA 的 pulib 加入您想要 share 的變數    在 FormB 中 uses FormA;    就可以直接使用了 FormA.變數    -- Skyer    這是之前找的到  可是我不知道把指令放在哪一塊....   
huangeider
高階會員


發表:288
回覆:492
積分:231
註冊:2003-02-26

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-10-07 12:26:43 IP:61.222.xxx.xxx 未訂閱
//FORM1
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 }
    DEMOSTR:STRING;
  end;    var
  Form1: TForm1;    implementation    uses Unit2;    {$R *.dfm}    procedure TForm1.Button1Click(Sender: TObject);
begin
    DEMOSTR:='TEST';
    TRY
      FORM2:=TFORM2.Create(SELF);
      FORM2.ShowModal;
    FINALLY
      FORM2.Free;
    END;    end;    end.    //FORM2    unit Unit2;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;    type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form2: TForm2;    implementation    uses Unit1;    {$R *.dfm}    procedure TForm2.Button1Click(Sender: TObject);
begin
SHOWMESSAGE(FORM1.DEMOSTR);
end;    end.    
cashxin2002
版主


發表:231
回覆:2555
積分:1937
註冊:2003-03-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-10-07 17:08:33 IP:202.62.xxx.xxx 未訂閱
您好﹗    請參考如下說明﹕ http://delphi.ktop.com.tw/topic.php?TOPIC_ID=63180    ================================= 有空來瞅瞅我﹗因為我是您的朋友﹐有您真好﹗ ================================
------
忻晟
sos_admin
版主


發表:121
回覆:697
積分:768
註冊:2003-07-23

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-10-07 17:31:52 IP:218.94.xxx.xxx 未訂閱
unit Unit2;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;    type
  TVarForm = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
   
    a, b: string;
    c: Boolean;
    
    { Public declarations }
  end;    var
  VarForm: TVarForm;    implementation    {$R *.dfm}    procedure TVarForm.FormCreate(Sender: TObject);
begin
  if c then
    Self.Caption := a
  else
    Self.Caption := b;
end;    end.    
传递参数
procedure TBaseForm.Button1Click(Sender: TObject);
var
  VarForm: TVarForm;
begin
  VarForm := TVarForm.Create(self);
  VarForm.a := 'Test';
  VarForm.b := 'Pass';
  VarForm.c := False;
  if VarForm.ShowModal = id_ok then
  begin
    ;
  end;
  VarForm.Free;
end;
风花雪月 e梦情缘 网络代号:wnhoo or sos_admin 网名:e梦缘 Mail:wnhoo@163.com 發表人 - sos_admin 於 2005/10/07 17:32:47
系統時間:2024-04-25 21:01:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!