首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi 页面间传值有关问题

2012-02-23 
delphi 页面间传值问题unit songinterfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphic

delphi 页面间传值问题
unit song;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,question;

type
  TForm1 = class(TForm)
  Label1: TLabel;
   
  procedure Label1Click(Sender: TObject);
  procedure Label2Click(Sender: TObject);
  private
  { Private declarations }
  public
  temp_id:string;
  { Public declarations }
  end;

var
  Form1: TForm1;
   
implementation






{$R *.dfm}

procedure TForm1.Label1Click(Sender: TObject);
begin
temp_id:=trim(label1.Caption) ;
label1.Font.Color :=clHighlight;
form2.Show ;

end;


想把变量temp_id传到form2窗体中,如下:

unit question;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,StdCtrls, DB, ADODB;

type
  TForm2 = class(TForm)
  Label1: TLabel;
  ADOConnection1: TADOConnection;
  DataSource1: TDataSource;
  ADODataSet1: TADODataSet;
  Label2: TLabel;
  Memo1: TMemo;
  Button1: TButton;
  Button2: TButton;
  procedure FormCreate(Sender: TObject);
  procedure Button1Click(Sender: TObject);
  procedure Button2Click(Sender: TObject);
  private
  { Private declarations }
  public
  { Public declarations }
  end;

var
  Form2: TForm2;

implementation
 uses song;{Form1}

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
begin
  label1.Caption :=song.Form1.temp_id; //这里没有传过来,是空值,请教???????end;

[解决办法]
song.Form1.temp_id是否有值,另外这种窗体之间传值,可以用参数,不推荐直接用全局变量。

热点排行