1。需要获取当前application中所有已create的 Form 实例。
2。如果再次调用该实例。则不用再创建,只需显示原有Form即可。小弟的程序如下:
procedure TForm1.Button2Click(Sender: TObject);
var
i,j :integer;
v :TComponent;
begin
i := Application.ComponentCount;
vlist.clear;
for j :=0 to i-1 do
begin
v :=Application.Components[j];
if (Copy(String(v.ClassType.ClassName),1,5)='TForm') then
begin
vlist.Add(v.ClassName);
end;
end;
end;
//
procedure TForm1.Button3Click(Sender: TObject);
var
admGlobal: TCustomForm;
ClassForm: TPersistentClass;
begin
ClassForm := GetClass(vlist.Strings[1]);
if ClassForm<> nil then
begin
//需要显示ClassForm 的原有实例窗体,而无需创建。???
不知怎么实现!!
end;
end;急用。。thanks。如果分不够的话,直接说,我再开一贴。。
2。如果再次调用该实例。则不用再创建,只需显示原有Form即可。小弟的程序如下:
procedure TForm1.Button2Click(Sender: TObject);
var
i,j :integer;
v :TComponent;
begin
i := Application.ComponentCount;
vlist.clear;
for j :=0 to i-1 do
begin
v :=Application.Components[j];
if (Copy(String(v.ClassType.ClassName),1,5)='TForm') then
begin
vlist.Add(v.ClassName);
end;
end;
end;
//
procedure TForm1.Button3Click(Sender: TObject);
var
admGlobal: TCustomForm;
ClassForm: TPersistentClass;
begin
ClassForm := GetClass(vlist.Strings[1]);
if ClassForm<> nil then
begin
//需要显示ClassForm 的原有实例窗体,而无需创建。???
不知怎么实现!!
end;
end;急用。。thanks。如果分不够的话,直接说,我再开一贴。。
2:窗体使用全局变量.
Screen.Forms2: if not Assigned(AForm) then
TAForm.Create(Application);
AForm.Show
AFrom是实现AForm窗体单元的一个全局变量
记住
在AForm的OnDestroy事件种写上
AForm:=nil
在AForm的OnClose事件种写上
Action:=caFree
var
i:integer;
begin
for i := 0 to Application.ComponentCount -1 do
begin
if Application.Components[i] is TForm then
lst1.Items.Add(Application.Components[i].Name);
end;
end;procedure TForm1.btn1Click(Sender: TObject);
var
i:integer;
begin
if lst1.ItemIndex = -1 then exit;
for i := 0 to Application.ComponentCount -1 do
begin
if Application.Components[i].Name = lst1.Items.Strings[lst1.ItemIndex] then
(Application.Components[i] as TForm).ShowModal;
end;
end;
var
SelForm: TForm;
i: Integer;
begin
……
for i:= 0 to AList.Count-1 do
begin
if AList.Items[i] is TForm then
begin
SelForm:= TForm(AList.Items[i]); //取得对象后,SelForm就是Form实例了
SelForm.Show;
end;
end;
end;
var
AppName: String; //application.title
PreviousInstanceWindow: HWND; //find previouswindows return handle
myMutexHandle: HWND;//CreateMutex return handle
begin
myMutexHandle:=CreateMutex(nil,True,Pchar('Only_One_jjj'));
try
if GetlastError<>ERROR_ALREADY_EXISTS then
begin
Application.Initialize;
Application.Title := 'jjj';
Application.CreateForm(TFrmMain, FrmMain);
Application.CreateForm(TAboutForm, AboutForm);
Application.Run;
end
else begin
AppName:=Application.Title;
Application.ShowMainForm:=False;
Application.Title:='destroy me';
PreviousInstanceWindow:=FindWindow(nil,PChar(AppName));
if PreviousInstanceWindow<>0 then
if IsIconic(PreviousInstanceWindow) then//if Windows Minx then
ShowWindow(PreviousInstanceWindow,SW_RESTORE)
else
SetForegroundWindow(PreviousInstanceWindow);
end;
finally
ReleaseMutex(myMutexHandle);
2:AForm 需要动态获取的,我在第一点中需要获取screen上的所有form,
记录这些信息(比如有一个列表)。点击某一行时,需show出原有窗体。
记录这些信息(比如有一个列表)。点击某一行时,需show出原有窗体。
为什么要实现这个功能,
做多窗体菜单的窗口菜单吗?这个菜单是自动的哦?
如果真要实现可以加到TList中..
procedure TForm1.Button3Click(Sender: TObject);
var
admGlobal: TCustomForm;
ClassForm: TPersistentClass;
begin
ClassForm := GetClass(vlist.Strings[1]);
if ClassForm<> nil then
begin
if not ClassForm.SHowing then ClassForm.SHow
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,j :integer;
v :TComponent;
begin
i := Application.ComponentCount;
vlist.clear;
for j :=0 to i-1 do
begin
v :=Application.Components[j];
if (Copy(String(v.ClassType.ClassName),1,5)='TForm') then
begin
vlist.Add(Copy(v.ClassName, 2, 1000));
end;
end;
end;procedure TForm1.Button2Click(Sender: TObject);
var
admGlobal: TCustomForm;
begin
admGlobal := application.FindComponent(vlist.Strings[1]) as TForm;
if admGlobal <> nil then
begin
admGlobal.Show;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
vlist:= TStringList.Create;
end;
记录这些信息(比如有一个列表)。点击某一行时,需show出原有窗体。
为什么要实现这个功能,
做多窗体菜单的窗口菜单吗?这个菜单是自动的哦?
______________________
是啊,我就是要实现多窗口的切换这个菜单怎么加?一直没做过这一块。。^_^自己先寒一个。