![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
|
А у меня не получается перенести переменную qw123 с 2ой на 3ю форму. Главное переменную видно во всех процедурах, а на другой форме нет. Она там будт видна толкьо когда я присвою ей значение сразу же при открытии формы, т.е. в самом конце перед "end."
var Form2: TForm2; qw:integer; implementation uses Unit1, Unit3; {$R *.dfm} procedure TForm2.k(Sender: TObject); begin form1.close; end; procedure TForm2.Button1Click(Sender: TObject); begin form1.show; form2.close; end; procedure TForm2.Button2Click(Sender: TObject); begin form3.show ; form2.close ; end; procedure TForm2.DBLookupComboBox1Click(Sender: TObject); var s11:integer; begin q:=DBLookupComboBox1.KeyValue; Label4.Caption:=inttostr(qw123); ADOQuery2.Close; ADOQuery2.SQL.Clear; ADoquery2.sql.text := 'select wbs_id, wbs_short_name, parent_wbs_id,wbs_name from PROJWBS'; ADoquery2.sql.add ('Where parent_wbs_id=:q order by wbs_short_name'); ADoquery2.parameters.paramByName('q').value := q; ADOQuery2.ExecSQL; ADoQuery2.open ; s11:=Adoquery2.recordcount; label2.Caption:=inttostr(s11); end; procedure TForm2.FormCreate(Sender: TObject); var s:integer; begin s:=Adoquery1.recordcount; //label2.Caption:=inttostr(s); end; procedure TForm2.BitBtn1Click(Sender: TObject); begin form1.show; form2.close; end; procedure TForm2.BitBtn2Click(Sender: TObject); begin ShowMessage(inttostr(qw123)); form3.show ; form2.close ; end; procedure TForm2.BitBtn3Click(Sender: TObject); begin form1.close; end; procedure TForm2.DBGrid1CellClick(Column: TColumn); var e,e1:string; begin e:=Adoquery2.FieldByName(Column.FieldName).asstrin g; label5.Caption:=e; e1:=DBGrid1.Columns[3].Field.asstring; qw123:=strtoint(e1); Label1.caption:=inttostr(qw123); end; //если тут присвоить к qw123 переменую она перенесётся на 3ю форму end. |
|
#2
|
||||
|
||||
|
Добавь в uses Unit2.
И код нужно выделять тегом [code] |
|
#3
|
|||
|
|||
|
не может вставить, т.к. это и есть Unit2 ...
|
|
#4
|
||||
|
||||
|
Код:
var Form3: TForm3; implementation uses Unit2; |
|
#5
|
||||
|
||||
|
объяви переменную как член класса TForm2:
Код:
TForm2 = class(TForm)
...
public
qw123 : integer;
... |
|
#6
|
|||
|
|||
|
А где её таким образом обявлять?
Если можешь добавь в мой код... |
|
#7
|
||||
|
||||
|
у тя нет этой части кода...вот например:
Код:
interface
uses ...;
type
TForm2 = class(TForm)
//тут всякие контролы и их процедуры типа
Button1 : TButton;
procedure Button1Click(Sender: TObject);
private
//тут закрытые переменные процедуры
public
//а вот тут открытые для других классов(и форм;) ) переменные и процедуры
//здесь и нужно объявлять переменную
eq123 : integer; //без слова var и перед процедурами!!!
protected
//а тут защищенные процедуры
end;
implementation
... |
|
#8
|
|||
|
|||
|
Написал так, всё равно не пашет. Когда переходит на другую форму всё равно обнуляет значение ((( пипец, просто...
|
|
#9
|
||||
|
||||
|
Код:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm2 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
qw123: Integer;
implementation
{$R *.dfm}
end.Код:
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm3 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
uses
Unit2
{$R *.dfm}
end. |
|
#10
|
|||
|
|||
|
Ребята извини но я походу дебил, всё равно не получается.. Даже создал маленькую программку, и даже с ней не пашет (((
Код:
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 }
end;
var
Form1: TForm1;
x:integer;
implementation
uses Unit2;
//uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
x:=12311;
form2.show;
end;
end.Код:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
Uses
Unit1;
{$R *.dfm}
procedure TForm2.FormCreate(Sender: TObject);
begin
label1.Caption:=inttostr(x);
end;
end.
При нажатии на Button1 на форме 1 должна открться форма 2 и в label1 должно быть значение 12311, а он показывает '0' !!! |
|
#11
|
||||
|
||||
|
Ты пиши label1.Caption:=inttostr(x); не в OnCreate а в OnShow
|
|
#12
|
|||
|
|||
|
А ясн, пасибки всё получилось ))) Правда написал в FormActivate
|