但是当同时打开几个用户的对应窗体时,(比如依次动态创建了f1,f2,f3),只能对f3操作,就算对f1,f2操作(比如说,按f1窗体的“退出”按钮,就会把f3的窗体关掉,而且f3关掉后,f1,f2任何按钮都失效)
为什么,怎么解决啊,
第一次发贴,毕业设计着急,谢谢啦
35 个解决方案
#1
看完你的问题,发现自己什么也不懂了,天哪!
#2
看不出名堂
#3
头晕,什么东西……
有代码么?
有代码么?
#4
procedure TForm1.Button1Click(Sender: TObject);//确定
begin
StatusBar1.Panels[0].Text:='用户:['+UserQuery.FieldByName('c_code').Value+']';
CreateForm;
end;
procedure TForm1.CreateForm;
begin
f1:=TForm.Create(Self);
f1.Name:='jianpan'+inttostr(Count);
Inc(Count);
......//f1的属性设置
f1.OnClose:=FormClose;
f1.show;
GroupBox3:=TGroupBox.Create(nil);
...... //GroupBox3的属性设置
GroupBox3.Caption:='数字键';
GroupBox3.Parent:=f1;
GroupBox3.Visible:=True;
......//在动态创建的f1窗体上动态创建动态组件
......//在f1上动态创建ADOQuery
end;
#5
#6
……两个叉叉,看不到图
#7
每选择一个用户,按“确定”一次,就会创建一个f1
问题是:同时打开几个用户,除了最后一个打开的窗体以外,其他窗体全都失效
什么情况啊
问题是:同时打开几个用户,除了最后一个打开的窗体以外,其他窗体全都失效
什么情况啊
#8
......我也不知道图怎么了
#9
怀疑是你没有把代码独立开来写
如果是f3调用了f2或者f1的api函数,退出之后api的调用会失效,自然不能操作了
如果是f3调用了f2或者f1的api函数,退出之后api的调用会失效,自然不能操作了
#10
(gyk120)能给出个解决方法吗
我总不能100个用户就写一百个创建的函数啊
我总不能100个用户就写一百个创建的函数啊
#11
想了想,觉得总有点不对劲
你是不是把句柄给冲掉了?
句柄一旦冲掉,就不能操作了
你是不是把句柄给冲掉了?
句柄一旦冲掉,就不能操作了
#12
.....不懂
#13
我愚钝了,没能明白楼主说的是什么?
#14
恩,句柄就相当于窗口的一个特殊印记,每个窗口都有一个句柄,相关问题可以上baidu搜索
具体是什么问题也不好说……
SmallHand前辈,看你了……
具体是什么问题也不好说……
SmallHand前辈,看你了……
#15
代码贴出来看看
#16
代码贴在了4楼呢
#17
是不是你的FormClose有问题?
#18
FormClose方法怎么写的?
肯定是这的问题
肯定是这的问题
#19
你的CreateForm过程会被多次调用,变量f1在每次调用时都会被重新赋值(指向新创建的窗体),这样就会丢失掉之前窗体的指针,你的程序也就没有办法再引用到之前创建的窗体。
建议楼主使用一个数组来存放动态创建的多个窗体。
将f1的声明改为
f1: array of TForm;
建议楼主使用一个数组来存放动态创建的多个窗体。
将f1的声明改为
f1: array of TForm;
procedure TForm1.CreateForm;
begin
Inc(Count); //Count变量初值为0
SetLength(f1, Count);
f1[Count - 1] := TForm.Create(Application);
with f1[Count - 1] do begin
......//属性设置
end;
f1[Count - 1].OnClose := FormClose;
f1[Count - 1].Show;
GroupBox3:=TGroupBox.Create(nil);
...... //GroupBox3的属性设置
GroupBox3.Caption:='数字键';
GroupBox3.Parent:=f1[Count - 1];
GroupBox3.Visible:=True;
......//在动态创建的f1[Count - 1]窗体上动态创建动态组件
......//在f1[Count - 1]上动态创建ADOQuery
end;
#20
果然是指针和句柄的问题……
#21
我试了一下,出现错误:
Access violation at address 0045EC49 in module 'CLIENT.EXE'.Read of address 000000E5.
我觉得你的很对的啊
Access violation at address 0045EC49 in module 'CLIENT.EXE'.Read of address 000000E5.
我觉得你的很对的啊
#22
是不是因为我组件的parent是GroupBox,还要将GroupBox设成数组?
#23
如果你GroupBox也是动态创建多个的话,也需要用数组对其进行管理。
#24
试了很久,把组件创建部分都注释掉了,就留了一个“退出”按钮在f1上,还是和原来一样的
纳闷
纳闷
#25
不知道你在FormClose事件里是如何写的。
下面的代码可以动态创建多个窗体,并正确关闭之(省略了动态创建其他组件部分)。
下面的代码可以动态创建多个窗体,并正确关闭之(省略了动态创建其他组件部分)。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FFormCount: Integer;
FormArray: array of TForm;
protected
procedure FormClose(Sender: TObject; var Action: TCloseAction);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FFormCount := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(FFormCount);
SetLength(FormArray, FFormCount);
FormArray[FFormCount - 1] := TForm.Create(Application);
FormArray[FFormCount - 1].OnClose := FormClose;
FormArray[FFormCount - 1].Caption := Format('Form%d', [FFormCount]);
FormArray[FFormCount - 1].Width := 200;
FormArray[FFormCount - 1].Height := 200;
FormArray[FFormCount - 1].Position := poScreenCenter;
FormArray[FFormCount - 1].Show;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShowMessage(TForm(Sender).Caption + ' has been closed.');
TForm(Sender).Free;
end;
end.
#26
我关闭这么写的
procedure Tdiaer.FormClose_Self(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
测试了你的程序,Error reading Form1.OnClose :Invalid property value
。。。。。。
procedure Tdiaer.FormClose_Self(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
测试了你的程序,Error reading Form1.OnClose :Invalid property value
。。。。。。
#27
Form1的OnClose不需要指定事件!
#28
强
#29
好聪明
我试试
我试试
#30
各个窗体独立了 呵呵 谢谢你
unit phone;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
FFormCount: Integer;
FormArray: array of TForm;
Button15Array: array of TButton;
GroupBox3Array: array of TGroupBox;
k:array[0..100] of integer;
Presstimes:integer;
{ Private declarations }
protected
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button15Click(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Presstimes := 0;
FFormCount := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(Presstimes);
Inc(FFormCount);
k[Presstimes-1]:=FFormCount-1;
SetLength(FormArray, FFormCount);
FormArray[FFormCount - 1] := TForm.Create(Application);
FormArray[FFormCount - 1].OnClose := FormClose;
FormArray[FFormCount - 1].Caption := Format('Form%d', [FFormCount]);
FormArray[FFormCount - 1].Width := 303;
FormArray[FFormCount - 1].Height := 439;
FormArray[FFormCount - 1].Position := poScreenCenter;
FormArray[FFormCount - 1].Show;
SetLength(GroupBox3Array, FFormCount);
GroupBox3Array[FFormCount - 1]:=TGroupBox.Create(nil);
GroupBox3Array[FFormCount - 1].Width:=265;
GroupBox3Array[FFormCount - 1].Height:=225;
GroupBox3Array[FFormCount - 1].Top:=16;
GroupBox3Array[FFormCount - 1].Left:=16;
GroupBox3Array[FFormCount - 1].Caption:='数字键';
GroupBox3Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
GroupBox3Array[FFormCount - 1].Visible:=True;
SetLength(Button15Array, FFormCount);
Button15Array[FFormCount - 1]:=TButton.Create(nil);
Button15Array[FFormCount - 1].Width:=76;
Button15Array[FFormCount - 1].Height:=25;
Button15Array[FFormCount - 1].Top:=376;
Button15Array[FFormCount - 1].Left:=104;
Button15Array[FFormCount - 1].Caption:='退出';
Button15Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
Button15Array[FFormCount - 1].OnClick:=Button15Click;//总是无法确定要关闭的窗体
Button15Array[FFormCount - 1].Visible:=True;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShowMessage(TForm(Sender).Caption + ' has been closed.');
TForm(Sender).Free;
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
FormArray[k[Presstimes]].Hide;
end;
end.
很想把函数也放进数组里
每个创建的窗体没法获得唯一标记啊,指教(chirs_mao)怎么写Button15Click啊
unit phone;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
FFormCount: Integer;
FormArray: array of TForm;
Button15Array: array of TButton;
GroupBox3Array: array of TGroupBox;
k:array[0..100] of integer;
Presstimes:integer;
{ Private declarations }
protected
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button15Click(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Presstimes := 0;
FFormCount := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(Presstimes);
Inc(FFormCount);
k[Presstimes-1]:=FFormCount-1;
SetLength(FormArray, FFormCount);
FormArray[FFormCount - 1] := TForm.Create(Application);
FormArray[FFormCount - 1].OnClose := FormClose;
FormArray[FFormCount - 1].Caption := Format('Form%d', [FFormCount]);
FormArray[FFormCount - 1].Width := 303;
FormArray[FFormCount - 1].Height := 439;
FormArray[FFormCount - 1].Position := poScreenCenter;
FormArray[FFormCount - 1].Show;
SetLength(GroupBox3Array, FFormCount);
GroupBox3Array[FFormCount - 1]:=TGroupBox.Create(nil);
GroupBox3Array[FFormCount - 1].Width:=265;
GroupBox3Array[FFormCount - 1].Height:=225;
GroupBox3Array[FFormCount - 1].Top:=16;
GroupBox3Array[FFormCount - 1].Left:=16;
GroupBox3Array[FFormCount - 1].Caption:='数字键';
GroupBox3Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
GroupBox3Array[FFormCount - 1].Visible:=True;
SetLength(Button15Array, FFormCount);
Button15Array[FFormCount - 1]:=TButton.Create(nil);
Button15Array[FFormCount - 1].Width:=76;
Button15Array[FFormCount - 1].Height:=25;
Button15Array[FFormCount - 1].Top:=376;
Button15Array[FFormCount - 1].Left:=104;
Button15Array[FFormCount - 1].Caption:='退出';
Button15Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
Button15Array[FFormCount - 1].OnClick:=Button15Click;//总是无法确定要关闭的窗体
Button15Array[FFormCount - 1].Visible:=True;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShowMessage(TForm(Sender).Caption + ' has been closed.');
TForm(Sender).Free;
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
FormArray[k[Presstimes]].Hide;
end;
end.
很想把函数也放进数组里
每个创建的窗体没法获得唯一标记啊,指教(chirs_mao)怎么写Button15Click啊
#31
你可以把创建的窗体序号,即FormArray中的索引值存放在窗体的Tag属性中。
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(Presstimes);
Inc(FFormCount);
k[Presstimes-1]:=FFormCount-1;
SetLength(FormArray, FFormCount);
FormArray[FFormCount - 1] := TForm.Create(Application);
FormArray[FFormCount - 1].OnClose := FormClose;
FormArray[FFormCount - 1].Tag := FFormCount - 1;
FormArray[FFormCount - 1].Caption := Format('Form%d', [FFormCount]);
FormArray[FFormCount - 1].Width := 303;
FormArray[FFormCount - 1].Height := 439;
FormArray[FFormCount - 1].Position := poScreenCenter;
FormArray[FFormCount - 1].Show;
SetLength(GroupBox3Array, FFormCount);
GroupBox3Array[FFormCount - 1]:=TGroupBox.Create(nil);
GroupBox3Array[FFormCount - 1].Width:=265;
GroupBox3Array[FFormCount - 1].Height:=225;
GroupBox3Array[FFormCount - 1].Top:=16;
GroupBox3Array[FFormCount - 1].Left:=16;
GroupBox3Array[FFormCount - 1].Caption:='数字键';
GroupBox3Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
GroupBox3Array[FFormCount - 1].Visible:=True;
SetLength(Button15Array, FFormCount);
Button15Array[FFormCount - 1]:=TButton.Create(nil);
Button15Array[FFormCount - 1].Width:=76;
Button15Array[FFormCount - 1].Height:=25;
Button15Array[FFormCount - 1].Top:=376;
Button15Array[FFormCount - 1].Left:=104;
Button15Array[FFormCount - 1].Caption:='退出';
Button15Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
Button15Array[FFormCount - 1].OnClick:=Button15Click;//总是无法确定要关闭的窗体
Button15Array[FFormCount - 1].Visible:=True;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShowMessage(TForm(Sender).Caption + ' has been closed.');
TForm(Sender).Free;
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
//FormArray[k[Presstimes]].Hide;
FormArray[TForm(TButton(Sender).Parent).Tag].Hide;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(Presstimes);
Inc(FFormCount);
k[Presstimes-1]:=FFormCount-1;
SetLength(FormArray, FFormCount);
FormArray[FFormCount - 1] := TForm.Create(Application);
FormArray[FFormCount - 1].OnClose := FormClose;
FormArray[FFormCount - 1].Tag := FFormCount - 1;
FormArray[FFormCount - 1].Caption := Format('Form%d', [FFormCount]);
FormArray[FFormCount - 1].Width := 303;
FormArray[FFormCount - 1].Height := 439;
FormArray[FFormCount - 1].Position := poScreenCenter;
FormArray[FFormCount - 1].Show;
SetLength(GroupBox3Array, FFormCount);
GroupBox3Array[FFormCount - 1]:=TGroupBox.Create(nil);
GroupBox3Array[FFormCount - 1].Width:=265;
GroupBox3Array[FFormCount - 1].Height:=225;
GroupBox3Array[FFormCount - 1].Top:=16;
GroupBox3Array[FFormCount - 1].Left:=16;
GroupBox3Array[FFormCount - 1].Caption:='数字键';
GroupBox3Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
GroupBox3Array[FFormCount - 1].Visible:=True;
SetLength(Button15Array, FFormCount);
Button15Array[FFormCount - 1]:=TButton.Create(nil);
Button15Array[FFormCount - 1].Width:=76;
Button15Array[FFormCount - 1].Height:=25;
Button15Array[FFormCount - 1].Top:=376;
Button15Array[FFormCount - 1].Left:=104;
Button15Array[FFormCount - 1].Caption:='退出';
Button15Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
Button15Array[FFormCount - 1].OnClick:=Button15Click;//总是无法确定要关闭的窗体
Button15Array[FFormCount - 1].Visible:=True;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShowMessage(TForm(Sender).Caption + ' has been closed.');
TForm(Sender).Free;
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
//FormArray[k[Presstimes]].Hide;
FormArray[TForm(TButton(Sender).Parent).Tag].Hide;
end;
#32
procedure TForm1.Button1Click(Sender: TObject);
begin
......
SetLength(Butn0Array, FFormCount);
Butn0Array[FFormCount - 1]:=TButton.Create(nil);
Butn0Array[FFormCount - 1].Width:=41;
Butn0Array[FFormCount - 1].Height:=41;
Butn0Array[FFormCount - 1].Top:=176;
Butn0Array[FFormCount - 1].Left:=8;
Butn0Array[FFormCount - 1].Caption:='0';
Butn0Array[FFormCount - 1].Parent:=GroupBox3Array[FFormCount - 1];
Butn0Array[FFormCount - 1].OnClick:=Butn0Click;
Butn0Array[FFormCount - 1].Visible:=True;
SetLength(Memo1Array, FFormCount);
Memo1Array[FFormCount - 1]:=TMemo.Create(nil);
Memo1Array[FFormCount - 1].Width:=81;
Memo1Array[FFormCount - 1].Height:=33;
Memo1Array[FFormCount - 1].Top:=184;
Memo1Array[FFormCount - 1].Left:=168;
Memo1Array[FFormCount - 1].Text:='';
Memo1Array[FFormCount - 1].Parent:=GroupBox3Array[FFormCount - 1];
Memo1Array[FFormCount - 1].Visible:=True;
......
end;
procedure TForm1.Butn0Click(Sender: TObject);
begin
PostMessage((Memo1Array[TForm(TButton(Sender).Parent).tag]).Handle, WM_KEYDOWN, 48, 0);//0为什么总是显示在第一个创建的窗里?
end;
#33
Tag属性默认值是0,你需要检查一下你取到的Tag值是多少!
#34
为什么TForm(sender)的tag值不能被其他数组引用?
我为每个控件都保存了自己的tag值,才正确引用的
我现在的全局变量也需要编程数组,starttime[0..100]:array of integer,第i个窗体用starttime[i],但是i的值不能用TForm的索引,确定不了,怎么解决啊?
我为每个控件都保存了自己的tag值,才正确引用的
我现在的全局变量也需要编程数组,starttime[0..100]:array of integer,第i个窗体用starttime[i],但是i的值不能用TForm的索引,确定不了,怎么解决啊?
#35
我自己解决了,谢谢
#1
看完你的问题,发现自己什么也不懂了,天哪!
#2
看不出名堂
#3
头晕,什么东西……
有代码么?
有代码么?
#4
procedure TForm1.Button1Click(Sender: TObject);//确定
begin
StatusBar1.Panels[0].Text:='用户:['+UserQuery.FieldByName('c_code').Value+']';
CreateForm;
end;
procedure TForm1.CreateForm;
begin
f1:=TForm.Create(Self);
f1.Name:='jianpan'+inttostr(Count);
Inc(Count);
......//f1的属性设置
f1.OnClose:=FormClose;
f1.show;
GroupBox3:=TGroupBox.Create(nil);
...... //GroupBox3的属性设置
GroupBox3.Caption:='数字键';
GroupBox3.Parent:=f1;
GroupBox3.Visible:=True;
......//在动态创建的f1窗体上动态创建动态组件
......//在f1上动态创建ADOQuery
end;
#5
#6
……两个叉叉,看不到图
#7
每选择一个用户,按“确定”一次,就会创建一个f1
问题是:同时打开几个用户,除了最后一个打开的窗体以外,其他窗体全都失效
什么情况啊
问题是:同时打开几个用户,除了最后一个打开的窗体以外,其他窗体全都失效
什么情况啊
#8
......我也不知道图怎么了
#9
怀疑是你没有把代码独立开来写
如果是f3调用了f2或者f1的api函数,退出之后api的调用会失效,自然不能操作了
如果是f3调用了f2或者f1的api函数,退出之后api的调用会失效,自然不能操作了
#10
(gyk120)能给出个解决方法吗
我总不能100个用户就写一百个创建的函数啊
我总不能100个用户就写一百个创建的函数啊
#11
想了想,觉得总有点不对劲
你是不是把句柄给冲掉了?
句柄一旦冲掉,就不能操作了
你是不是把句柄给冲掉了?
句柄一旦冲掉,就不能操作了
#12
.....不懂
#13
我愚钝了,没能明白楼主说的是什么?
#14
恩,句柄就相当于窗口的一个特殊印记,每个窗口都有一个句柄,相关问题可以上baidu搜索
具体是什么问题也不好说……
SmallHand前辈,看你了……
具体是什么问题也不好说……
SmallHand前辈,看你了……
#15
代码贴出来看看
#16
代码贴在了4楼呢
#17
是不是你的FormClose有问题?
#18
FormClose方法怎么写的?
肯定是这的问题
肯定是这的问题
#19
你的CreateForm过程会被多次调用,变量f1在每次调用时都会被重新赋值(指向新创建的窗体),这样就会丢失掉之前窗体的指针,你的程序也就没有办法再引用到之前创建的窗体。
建议楼主使用一个数组来存放动态创建的多个窗体。
将f1的声明改为
f1: array of TForm;
建议楼主使用一个数组来存放动态创建的多个窗体。
将f1的声明改为
f1: array of TForm;
procedure TForm1.CreateForm;
begin
Inc(Count); //Count变量初值为0
SetLength(f1, Count);
f1[Count - 1] := TForm.Create(Application);
with f1[Count - 1] do begin
......//属性设置
end;
f1[Count - 1].OnClose := FormClose;
f1[Count - 1].Show;
GroupBox3:=TGroupBox.Create(nil);
...... //GroupBox3的属性设置
GroupBox3.Caption:='数字键';
GroupBox3.Parent:=f1[Count - 1];
GroupBox3.Visible:=True;
......//在动态创建的f1[Count - 1]窗体上动态创建动态组件
......//在f1[Count - 1]上动态创建ADOQuery
end;
#20
果然是指针和句柄的问题……
#21
我试了一下,出现错误:
Access violation at address 0045EC49 in module 'CLIENT.EXE'.Read of address 000000E5.
我觉得你的很对的啊
Access violation at address 0045EC49 in module 'CLIENT.EXE'.Read of address 000000E5.
我觉得你的很对的啊
#22
是不是因为我组件的parent是GroupBox,还要将GroupBox设成数组?
#23
如果你GroupBox也是动态创建多个的话,也需要用数组对其进行管理。
#24
试了很久,把组件创建部分都注释掉了,就留了一个“退出”按钮在f1上,还是和原来一样的
纳闷
纳闷
#25
不知道你在FormClose事件里是如何写的。
下面的代码可以动态创建多个窗体,并正确关闭之(省略了动态创建其他组件部分)。
下面的代码可以动态创建多个窗体,并正确关闭之(省略了动态创建其他组件部分)。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FFormCount: Integer;
FormArray: array of TForm;
protected
procedure FormClose(Sender: TObject; var Action: TCloseAction);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FFormCount := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(FFormCount);
SetLength(FormArray, FFormCount);
FormArray[FFormCount - 1] := TForm.Create(Application);
FormArray[FFormCount - 1].OnClose := FormClose;
FormArray[FFormCount - 1].Caption := Format('Form%d', [FFormCount]);
FormArray[FFormCount - 1].Width := 200;
FormArray[FFormCount - 1].Height := 200;
FormArray[FFormCount - 1].Position := poScreenCenter;
FormArray[FFormCount - 1].Show;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShowMessage(TForm(Sender).Caption + ' has been closed.');
TForm(Sender).Free;
end;
end.
#26
我关闭这么写的
procedure Tdiaer.FormClose_Self(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
测试了你的程序,Error reading Form1.OnClose :Invalid property value
。。。。。。
procedure Tdiaer.FormClose_Self(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
测试了你的程序,Error reading Form1.OnClose :Invalid property value
。。。。。。
#27
Form1的OnClose不需要指定事件!
#28
强
#29
好聪明
我试试
我试试
#30
各个窗体独立了 呵呵 谢谢你
unit phone;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
FFormCount: Integer;
FormArray: array of TForm;
Button15Array: array of TButton;
GroupBox3Array: array of TGroupBox;
k:array[0..100] of integer;
Presstimes:integer;
{ Private declarations }
protected
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button15Click(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Presstimes := 0;
FFormCount := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(Presstimes);
Inc(FFormCount);
k[Presstimes-1]:=FFormCount-1;
SetLength(FormArray, FFormCount);
FormArray[FFormCount - 1] := TForm.Create(Application);
FormArray[FFormCount - 1].OnClose := FormClose;
FormArray[FFormCount - 1].Caption := Format('Form%d', [FFormCount]);
FormArray[FFormCount - 1].Width := 303;
FormArray[FFormCount - 1].Height := 439;
FormArray[FFormCount - 1].Position := poScreenCenter;
FormArray[FFormCount - 1].Show;
SetLength(GroupBox3Array, FFormCount);
GroupBox3Array[FFormCount - 1]:=TGroupBox.Create(nil);
GroupBox3Array[FFormCount - 1].Width:=265;
GroupBox3Array[FFormCount - 1].Height:=225;
GroupBox3Array[FFormCount - 1].Top:=16;
GroupBox3Array[FFormCount - 1].Left:=16;
GroupBox3Array[FFormCount - 1].Caption:='数字键';
GroupBox3Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
GroupBox3Array[FFormCount - 1].Visible:=True;
SetLength(Button15Array, FFormCount);
Button15Array[FFormCount - 1]:=TButton.Create(nil);
Button15Array[FFormCount - 1].Width:=76;
Button15Array[FFormCount - 1].Height:=25;
Button15Array[FFormCount - 1].Top:=376;
Button15Array[FFormCount - 1].Left:=104;
Button15Array[FFormCount - 1].Caption:='退出';
Button15Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
Button15Array[FFormCount - 1].OnClick:=Button15Click;//总是无法确定要关闭的窗体
Button15Array[FFormCount - 1].Visible:=True;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShowMessage(TForm(Sender).Caption + ' has been closed.');
TForm(Sender).Free;
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
FormArray[k[Presstimes]].Hide;
end;
end.
很想把函数也放进数组里
每个创建的窗体没法获得唯一标记啊,指教(chirs_mao)怎么写Button15Click啊
unit phone;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
FFormCount: Integer;
FormArray: array of TForm;
Button15Array: array of TButton;
GroupBox3Array: array of TGroupBox;
k:array[0..100] of integer;
Presstimes:integer;
{ Private declarations }
protected
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button15Click(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Presstimes := 0;
FFormCount := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(Presstimes);
Inc(FFormCount);
k[Presstimes-1]:=FFormCount-1;
SetLength(FormArray, FFormCount);
FormArray[FFormCount - 1] := TForm.Create(Application);
FormArray[FFormCount - 1].OnClose := FormClose;
FormArray[FFormCount - 1].Caption := Format('Form%d', [FFormCount]);
FormArray[FFormCount - 1].Width := 303;
FormArray[FFormCount - 1].Height := 439;
FormArray[FFormCount - 1].Position := poScreenCenter;
FormArray[FFormCount - 1].Show;
SetLength(GroupBox3Array, FFormCount);
GroupBox3Array[FFormCount - 1]:=TGroupBox.Create(nil);
GroupBox3Array[FFormCount - 1].Width:=265;
GroupBox3Array[FFormCount - 1].Height:=225;
GroupBox3Array[FFormCount - 1].Top:=16;
GroupBox3Array[FFormCount - 1].Left:=16;
GroupBox3Array[FFormCount - 1].Caption:='数字键';
GroupBox3Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
GroupBox3Array[FFormCount - 1].Visible:=True;
SetLength(Button15Array, FFormCount);
Button15Array[FFormCount - 1]:=TButton.Create(nil);
Button15Array[FFormCount - 1].Width:=76;
Button15Array[FFormCount - 1].Height:=25;
Button15Array[FFormCount - 1].Top:=376;
Button15Array[FFormCount - 1].Left:=104;
Button15Array[FFormCount - 1].Caption:='退出';
Button15Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
Button15Array[FFormCount - 1].OnClick:=Button15Click;//总是无法确定要关闭的窗体
Button15Array[FFormCount - 1].Visible:=True;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShowMessage(TForm(Sender).Caption + ' has been closed.');
TForm(Sender).Free;
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
FormArray[k[Presstimes]].Hide;
end;
end.
很想把函数也放进数组里
每个创建的窗体没法获得唯一标记啊,指教(chirs_mao)怎么写Button15Click啊
#31
你可以把创建的窗体序号,即FormArray中的索引值存放在窗体的Tag属性中。
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(Presstimes);
Inc(FFormCount);
k[Presstimes-1]:=FFormCount-1;
SetLength(FormArray, FFormCount);
FormArray[FFormCount - 1] := TForm.Create(Application);
FormArray[FFormCount - 1].OnClose := FormClose;
FormArray[FFormCount - 1].Tag := FFormCount - 1;
FormArray[FFormCount - 1].Caption := Format('Form%d', [FFormCount]);
FormArray[FFormCount - 1].Width := 303;
FormArray[FFormCount - 1].Height := 439;
FormArray[FFormCount - 1].Position := poScreenCenter;
FormArray[FFormCount - 1].Show;
SetLength(GroupBox3Array, FFormCount);
GroupBox3Array[FFormCount - 1]:=TGroupBox.Create(nil);
GroupBox3Array[FFormCount - 1].Width:=265;
GroupBox3Array[FFormCount - 1].Height:=225;
GroupBox3Array[FFormCount - 1].Top:=16;
GroupBox3Array[FFormCount - 1].Left:=16;
GroupBox3Array[FFormCount - 1].Caption:='数字键';
GroupBox3Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
GroupBox3Array[FFormCount - 1].Visible:=True;
SetLength(Button15Array, FFormCount);
Button15Array[FFormCount - 1]:=TButton.Create(nil);
Button15Array[FFormCount - 1].Width:=76;
Button15Array[FFormCount - 1].Height:=25;
Button15Array[FFormCount - 1].Top:=376;
Button15Array[FFormCount - 1].Left:=104;
Button15Array[FFormCount - 1].Caption:='退出';
Button15Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
Button15Array[FFormCount - 1].OnClick:=Button15Click;//总是无法确定要关闭的窗体
Button15Array[FFormCount - 1].Visible:=True;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShowMessage(TForm(Sender).Caption + ' has been closed.');
TForm(Sender).Free;
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
//FormArray[k[Presstimes]].Hide;
FormArray[TForm(TButton(Sender).Parent).Tag].Hide;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(Presstimes);
Inc(FFormCount);
k[Presstimes-1]:=FFormCount-1;
SetLength(FormArray, FFormCount);
FormArray[FFormCount - 1] := TForm.Create(Application);
FormArray[FFormCount - 1].OnClose := FormClose;
FormArray[FFormCount - 1].Tag := FFormCount - 1;
FormArray[FFormCount - 1].Caption := Format('Form%d', [FFormCount]);
FormArray[FFormCount - 1].Width := 303;
FormArray[FFormCount - 1].Height := 439;
FormArray[FFormCount - 1].Position := poScreenCenter;
FormArray[FFormCount - 1].Show;
SetLength(GroupBox3Array, FFormCount);
GroupBox3Array[FFormCount - 1]:=TGroupBox.Create(nil);
GroupBox3Array[FFormCount - 1].Width:=265;
GroupBox3Array[FFormCount - 1].Height:=225;
GroupBox3Array[FFormCount - 1].Top:=16;
GroupBox3Array[FFormCount - 1].Left:=16;
GroupBox3Array[FFormCount - 1].Caption:='数字键';
GroupBox3Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
GroupBox3Array[FFormCount - 1].Visible:=True;
SetLength(Button15Array, FFormCount);
Button15Array[FFormCount - 1]:=TButton.Create(nil);
Button15Array[FFormCount - 1].Width:=76;
Button15Array[FFormCount - 1].Height:=25;
Button15Array[FFormCount - 1].Top:=376;
Button15Array[FFormCount - 1].Left:=104;
Button15Array[FFormCount - 1].Caption:='退出';
Button15Array[FFormCount - 1].Parent:=FormArray[FFormCount - 1];
Button15Array[FFormCount - 1].OnClick:=Button15Click;//总是无法确定要关闭的窗体
Button15Array[FFormCount - 1].Visible:=True;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShowMessage(TForm(Sender).Caption + ' has been closed.');
TForm(Sender).Free;
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
//FormArray[k[Presstimes]].Hide;
FormArray[TForm(TButton(Sender).Parent).Tag].Hide;
end;
#32
procedure TForm1.Button1Click(Sender: TObject);
begin
......
SetLength(Butn0Array, FFormCount);
Butn0Array[FFormCount - 1]:=TButton.Create(nil);
Butn0Array[FFormCount - 1].Width:=41;
Butn0Array[FFormCount - 1].Height:=41;
Butn0Array[FFormCount - 1].Top:=176;
Butn0Array[FFormCount - 1].Left:=8;
Butn0Array[FFormCount - 1].Caption:='0';
Butn0Array[FFormCount - 1].Parent:=GroupBox3Array[FFormCount - 1];
Butn0Array[FFormCount - 1].OnClick:=Butn0Click;
Butn0Array[FFormCount - 1].Visible:=True;
SetLength(Memo1Array, FFormCount);
Memo1Array[FFormCount - 1]:=TMemo.Create(nil);
Memo1Array[FFormCount - 1].Width:=81;
Memo1Array[FFormCount - 1].Height:=33;
Memo1Array[FFormCount - 1].Top:=184;
Memo1Array[FFormCount - 1].Left:=168;
Memo1Array[FFormCount - 1].Text:='';
Memo1Array[FFormCount - 1].Parent:=GroupBox3Array[FFormCount - 1];
Memo1Array[FFormCount - 1].Visible:=True;
......
end;
procedure TForm1.Butn0Click(Sender: TObject);
begin
PostMessage((Memo1Array[TForm(TButton(Sender).Parent).tag]).Handle, WM_KEYDOWN, 48, 0);//0为什么总是显示在第一个创建的窗里?
end;
#33
Tag属性默认值是0,你需要检查一下你取到的Tag值是多少!
#34
为什么TForm(sender)的tag值不能被其他数组引用?
我为每个控件都保存了自己的tag值,才正确引用的
我现在的全局变量也需要编程数组,starttime[0..100]:array of integer,第i个窗体用starttime[i],但是i的值不能用TForm的索引,确定不了,怎么解决啊?
我为每个控件都保存了自己的tag值,才正确引用的
我现在的全局变量也需要编程数组,starttime[0..100]:array of integer,第i个窗体用starttime[i],但是i的值不能用TForm的索引,确定不了,怎么解决啊?
#35
我自己解决了,谢谢