DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: forget66
今日帖子: 65
在线用户: 12
导航: 论坛 -> 移动应用开发 斑竹:flyers,iamdream  
作者:
男 mp654kk (mp654kk) ▲△△△△ -
普通会员
2023/3/30 19:33:53
标题:
新手求助安卓环境里怎么像VCL那样同时显示两个窗体 浏览:1234
加入我的收藏
楼主: 比如主窗体是Form1还有一个窗体是Form2,如果用Form2.show就把Form1遮住了,怎么重叠显示,谢谢!
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2023/3/30 21:50:19
1楼: I think that, first, you should understand that the mobile environment is much more restrictive than the desktop environment, and not everything should be thought of the same way. Each one has its purpose!

I think that on a 5 inch screen, there wouldn't be much space for so many forms, wouldn't there?

If you want to have 2 forms on the same screen in a mobile environment, then you could try using a "container" to accommodate the two forms (otherwise, I don't think it would be feasible):

1) a form with a TLayout (myLayoutMain), for example (it would be your container)
2) inside "myLayoutMain", you could put 2 other layouts (myLayoutTop and myLayoutBottom)
3) now, create a form and place it inside "myLayoutTop", and another form inside "myLayoutBottom", for example

will it help?
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2023/3/30 21:55:05
2楼: using FRAMES
此帖子包含附件:
PNG 图像
大小:30.8K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 mp654kk (mp654kk) ▲△△△△ -
普通会员
2023/3/30 22:37:21
3楼: 谢谢,我要的不是这种效果,是弹出另一个窗口,显示在主窗口的上层,像对话框那样.
直接用form2.show会把form1全部遮住看不见form1了.
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2023/3/31 0:42:00
4楼: in mobile, there is not exists "modal" way... you'll have that "simulating" this mode...

Android uses the whole screen to display forms (not Delphi). This is a pattern!

To show a Modal form, you need to direct all message calls from the operating system to the window with focus, so you need to hack the operating system to change this pattern.

Delphi has an overloaded "ShowModal( AModalResult:TModalResult)" procedure for use on Android, since DelphiX5, but it wasn't 100%... maybe now it is.
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2023/3/31 0:42:40
5楼: ---- test Form2  - sub-forms

var
  Form2: TForm2;

implementation

{$R *.fmx}

procedure TForm2.Button1Click(Sender: TObject);
begin
  // Self.ModalResult := mrOK; MSWindows
  //
  Self.Close; // Android
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  Memo1.Lines.Add(Format('%dx%d', [Self.Width, Self.Height]));
  //
  FScreenWidth  := Trunc(Screen.Width * 0.60); // try new windows-size
  FScreenHeight := Trunc(Screen.Height * 0.60);
end;

procedure TForm2.FormShow(Sender: TObject);
begin
  //
  // does not works, because the O.S. Android usage all "screen space" to show your forms Modal or Non-Modal!!!
  //
  Self.Width  := FScreenWidth;
  Self.Height := FScreenHeight;
  //
  Memo1.Lines.Add(Format('%dx%d', [Self.Width, Self.Height]));
end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2023/3/31 0:43:00
6楼: --- form Main tests

implementation

{$R *.fmx}

uses
  Unit2;

var
  MyForms: TArray<TForm2>;

procedure MyCloseMyForm2;
begin
  // free all forms when end... or in any other situation necessary!
  for var F in MyForms do
    begin
      if (F <> nil) then
        F.DisposeOf;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
begin
  // not use "FREE" in mobile!!!
  //
  i       := length(MyForms);
  MyForms := MyForms + [TForm2.Create(self)];
  //
  MyForms[i].FormShow(self);
  MyForms[i].Show;
  //
  (* ShowModal( { }
    procedure(AResult: TModalResult)
    begin
    case AResult of
    mrOK:
    ShowMessage('mrOK');
    mrCancel:
    ShowMessage('mrCancel');
    else
    ShowMessage('mr Else');
    end;
    end); *)
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  MyCloseMyForm2;
end;

initialization

ReportMemoryLeaksOnShutdown := true;

end.
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2023/3/31 0:43:21
7楼: Marco Cantu words....

https://blog.marcocantu.com/blog/xe5_anonymous_showmodal_android.html
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 mp654kk (mp654kk) ▲△△△△ -
普通会员
2023/4/3 0:50:08
8楼: form2依然是满屏的,大小调整无效,完全挡住了form1呢.
有办法把form2作为控件添加到form1来实现这个效果吗?
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2023/4/3 8:27:17
9楼: look, as I said:  the O.S. do the form stay in full screen... not a Delphi!!!

if want "simulating" an overload: Form2 over Form1 ... like in MSWindows you need hack Android... 

you can some like this:
0) put all components from Form1 into a TLayout ( layMainForm )
1) in Form1 put other TLayout (layHidedToForm2 )  ... it should fill all client screen, and stay hided
2) create your Form2  with Parent = layHidedToForm2
3) before show Forn2, hide the layMainForm and  show your layHidedToForm2 to see your Form2
4) at end, do the inverse sequence
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2023/4/3 8:33:02
10楼: 调整窗口大小不起作用,因为操作系统。  Android 使用所有“屏幕空间”来显示您的表单模态或非模态!!!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2023/4/3 10:23:16
11楼: 楼主,你要的是不是对话框?

先看看这个:

https://www.jianshu.com/p/d6c9a485c061

安卓下如果采用 Toast,看看这篇 Delphi 的实现:

https://blog.csdn.net/tht2009/article/details/41412439

另外,类似效果,在 Fmx 里面,搞一个 Frame 浮在上面就好了。
----------------------------------------------
-
作者:
男 janker (janker) ★☆☆☆☆ -
盒子活跃会员
2023/4/3 10:36:17
12楼: android里没有模态窗体的概念,并且所有窗体都是满屏显示的。所以要转变设计思路。
如果是对话框可以用Toast,或者是用透明窗体来模拟。
https://bbs.2ccc.com/topic.asp?topicid=607677
----------------------------------------------
-
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2023/4/3 11:24:03
13楼: 另外需要注意一个概念:

Delphi 的模态窗口,Form1.ShowModal 出来的窗口,当这个窗口弹出来以后,程序(这里是主线程)就被阻塞了,一直到用户在这个窗口里面点选后,关闭这个窗口,程序才会继续往下走。比如:

AResult := Form1.ShowModal;

-- 窗口显示,程序阻塞,等待用户在窗口里面的点选操作;
-- 用户关闭窗口(用户点了 OK 按钮或者 Cancel 按钮,等等,用户按不同的按钮,返回值不同)

--- 窗口关闭后,程序解除阻塞,继续往下执行以下代码
if AResult = mrOK then
begin
  //-- 这里根据用户的选择,执行一些操作
end;

上述过程中,窗口弹出来以后,主线程就阻塞没有运行了。而用户点选,可能要花几秒或者几十秒。此时主线程就阻塞几秒或者几十秒直到窗口关闭,主线程才会继续运行。

而安卓底下,主线程不能阻塞。如果主线程被阻塞,程序会被安卓系统杀死。

所以安卓底下,不能用模态窗口,不能用这种阻塞模式编程。

阻塞模式编程的好处是,程序一行一行往下执行,比较容易看明白上下文前后执行逻辑关系,程序易读。

但安卓底下因为不允许阻塞,所以就变成了非阻塞的异步编程,代码会稍微麻烦一些。

比如你可以在 Windows 底下模拟一下不阻塞弹出的窗口的代码,也就是给一个对话框窗口让用户点选项目,然后根据用户点选项目执行一些操作,如果是 ShowModal 模态的阻塞编程,就是我在前面写的那种代码。如果不是 ShowModal,而是Show,那代码就不能那样写了。一种写法是给弹出来的窗口一个事件。比如:

begin
  Form1.OnClose := MyDoClose;
  Form1.Show; //-- 执行完这行代码就结束,假设你把用户在 Form1 里面点选后的处理代码放在这行代码后面,是会出问题的,因为还没等用户选完关闭 Form1,这里已经继续往下执行了,因为这里没有阻塞。
end;

procedure TFormMain.MyDoClose(Sender: TObject);
begin
  //用户在 Form1 里面选择,然后关闭 Form1 窗口时,会执行这个事件方法
  //处理用户输入的点选的代码写在这里。
end;

异步的方式编程,就是要麻烦一点,而且代码的可读性就差了很多。

然后,为了代码的可读性,这里可以使用匿名函数的方式。匿名函数的写法这里就不啰嗦了。

12 楼贴的那个链接里面,说:丑陋的代码。

其实就是因为安卓下不能阻塞,必须异步(非阻塞)模式编程导致。
----------------------------------------------
-
作者:
男 mp654kk (mp654kk) ▲△△△△ -
普通会员
2023/4/3 11:43:18
13楼: @emailx45 @pcplayer @janker 感谢,解释的真详细,比对话框复杂,还要摆很多控件在上面然后弹出来,看来还不如直接弄个panel弹显示出来.
如果窗体能像panel那样添加进form1去用就好了.c#里面可以设置窗体的toplevel属性为false添加到form1里面当控件用,不知delphi能否这样.
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2023/4/3 21:07:05
14楼: TForm is a control!!!

TApplication  use TFORM as your UI representant for user!

You can put it into a container like another TFORM, but you need changes some properties... as a MDI mode!!!

You can put a TForm into a TPANEL, or other container allowed!!!
TLayout for example!

BUT the BIG PROBLEM IS:  ANDROID ALWAYS USE A FORM IN FULL SCREEN!!!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 mp654kk (mp654kk) ▲△△△△ -
普通会员
2023/4/4 0:34:02
15楼: 直接当控件用的话在VCL里直接这样就可以
form2.parent := form1;
form2.show;
form2.BringToFront;
但fmx里不行.看来窗体始终是窗体没法像panel那样用.
当成mdi子窗体的话fmx里tformstyle也没有fsMDIChild的属性了
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2023/4/4 5:30:47
16楼: You are using VCL concepts!!! This does not working in FMX!!!

you are trying put "Earth" into the "Moon"!!! it's not possible!

In Android NOT EXITS the "Modal concept"... all forms is a non-modal by default!!! always the "last form opened on the screen" stay on full screen in Android!!!
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2023/4/4 5:38:20
17楼: try this my sample in FireMonkey

simple way to add "objects from FormA" into FormB using TLayout simulanting a new form on the screen!!!
此帖子包含附件:emailx45_20234453819.zip 大小:93.0K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 mystery (艾伦希亚) ★☆☆☆☆ -
普通会员
2023/4/4 18:56:43
18楼: 使用动态创建Frame可以达到类似的界面效果吧。
----------------------------------------------
-
作者:
男 mp654kk (mp654kk) ▲△△△△ -
普通会员
2023/4/5 19:53:18
19楼: @emailx45 谢谢 您的代码windows可以 但安卓报错
@mystery 谢谢 有代码么
----------------------------------------------
-
作者:
男 janker (janker) ★☆☆☆☆ -
盒子活跃会员
2023/4/5 22:28:37
20楼: FMX框架下,如果想像FORM那样使用FRAME,就用TFrameStand.(github下载)
但是要花点时间适应TFrameStand的用法,一开始感觉有点奇怪。
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行187.5毫秒 RSS