ShowModal在FireMonkey移动应用程序对话框

This is the only code that changes between the first and second code snippets:
 dlg.ShowModal(procedure(ModalResult: TModalResult)
    begin
      if ModalResult = mrOK then
      // if OK was pressed and an item is selected, pick it
      if dlg.ListBox1.ItemIndex >= 0 then
        edit1.Text := dlg.ListBox1.Items [dlg.ListBox1.ItemIndex];
      dlg.DisposeOf;
    end);
复制代码
 dlg.ShowModal(procedure(ModalResult: TModalResult)
    begin
      if ModalResult = mrOK then
      // if OK was pressed and an item is selected, pick it
      if dlg.ListBox1.ItemIndex >= 0 then
        edit1.Text := dlg.ListBox1.Items [dlg.ListBox1.ItemIndex];
      dlg.DisposeOf;
    end);
复制代码

第一个代码片段:典型的代码调用的ShowModal

procedure THeaderFooterForm.btnPickClick(Sender: TObject);
var
  dlg: TForm1;
begin
  dlg := TForm1.Create(nil);
  try
    // select current value, if avaialble in the list
    dlg.ListBox1.ItemIndex := dlg.ListBox1.Items.IndexOf(edit1.Text);
 
    if dlg.ShowModal = mrOK then
      // if OK was pressed and an item is selected, pick it
      if dlg.ListBox1.ItemIndex >= 0 then
        edit1.Text := dlg.ListBox1.Items [dlg.ListBox1.ItemIndex];
  finally
    dlg.Free;
  end;
 
end;
复制代码
procedure THeaderFooterForm.btnPickClick(Sender: TObject);
var
  dlg: TForm1;
begin
  dlg := TForm1.Create(nil);
  try
    // select current value, if avaialble in the list
    dlg.ListBox1.ItemIndex := dlg.ListBox1.Items.IndexOf(edit1.Text);
 
    if dlg.ShowModal = mrOK then
      // if OK was pressed and an item is selected, pick it
      if dlg.ListBox1.ItemIndex >= 0 then
        edit1.Text := dlg.ListBox1.Items [dlg.ListBox1.ItemIndex];
  finally
    dlg.Free;
  end;
 
end;
复制代码

 

伪代码典型的ShowModal代码片段解读

这里是一个描述每个此过程的一部分:

声明局部变量
dlg: TForm1;
创建表格的形式和初始化成员
dlg := TForm1.Create(nil);
        dlg.ListBox1.ItemIndex := dlg.ListBox1.Items.IndexOf(edit1.Text);
显示的形式模态
if dlg.ShowModal = mrOK then
检查用户的结果和处理数据
if dlg.ListBox1.ItemIndex >= 0 then
      edit1.Text := dlg.ListBox1.Items [dlg.ListBox1.ItemIndex];
 释放表单 dlg.Free;
复制代码
声明局部变量
dlg: TForm1;
创建表格的形式和初始化成员
dlg := TForm1.Create(nil);
        dlg.ListBox1.ItemIndex := dlg.ListBox1.Items.IndexOf(edit1.Text);
显示的形式模态
if dlg.ShowModal = mrOK then
检查用户的结果和处理数据
if dlg.ListBox1.ItemIndex >= 0 then
      edit1.Text := dlg.ListBox1.Items [dlg.ListBox1.ItemIndex];
 释放表单 dlg.Free;
复制代码

第二个代码片段:作为一个匿名的方式在所有平台上调用的ShowModal

随着移动平台,你应该改变这种代码,悦目,让所有支持的目标平台上工作的ShowModal

procedure THeaderFooterForm.btnPickClick(Sender: TObject);
var
  dlg: TForm1;
begin
  dlg := TForm1.Create(nil);
  // select current value, if available in the list
  dlg.ListBox1.ItemIndex := dlg.ListBox1.Items.IndexOf(edit1.Text);
 
  dlg.ShowModal(procedure(ModalResult: TModalResult)
    begin
      if ModalResult = mrOK then
      // if OK was pressed and an item is selected, pick it
      if dlg.ListBox1.ItemIndex >= 0 then
        edit1.Text := dlg.ListBox1.Items [dlg.ListBox1.ItemIndex];
      dlg.DisposeOf;
    end);
 
end;
复制代码
procedure THeaderFooterForm.btnPickClick(Sender: TObject);
var
  dlg: TForm1;
begin
  dlg := TForm1.Create(nil);
  // select current value, if available in the list
  dlg.ListBox1.ItemIndex := dlg.ListBox1.Items.IndexOf(edit1.Text);
 
  dlg.ShowModal(procedure(ModalResult: TModalResult)
    begin
      if ModalResult = mrOK then
      // if OK was pressed and an item is selected, pick it
      if dlg.ListBox1.ItemIndex >= 0 then
        edit1.Text := dlg.ListBox1.Items [dlg.ListBox1.ItemIndex];
      dlg.DisposeOf;
    end);
 
end;
复制代码

 

匿名方法的ShowModal代码片段的伪代码解读

这里是一个描述发生了什么(做同样的事情,第一个代码段)在第二个代码片段:

 

复制代码
Declare local variables
    dlg: TForm1;

Create form and initialize member in the form
    dlg := TForm1.Create(nil);
        dlg.ListBox1.ItemIndex := dlg.ListBox1.Items.IndexOf(edit1.Text);

Show the form modal
      dlg.ShowModal(procedure(ModalResult: TModalResult)

Check the user's result and process the data
    if ModalResult = mrOK then
      if dlg.ListBox1.ItemIndex >= 0 then
        edit1.Text := dlg.ListBox1.Items [dlg.ListBox1.ItemIndex];

Free the form
          dlg.DisposeOf;
复制代码
Declare local variables
    dlg: TForm1;

Create form and initialize member in the form
    dlg := TForm1.Create(nil);
        dlg.ListBox1.ItemIndex := dlg.ListBox1.Items.IndexOf(edit1.Text);

Show the form modal
      dlg.ShowModal(procedure(ModalResult: TModalResult)

Check the user's result and process the data
    if ModalResult = mrOK then
      if dlg.ListBox1.ItemIndex >= 0 then
        edit1.Text := dlg.ListBox1.Items [dlg.ListBox1.ItemIndex];

Free the form
          dlg.DisposeOf;

转载于:https://www.cnblogs.com/china1/p/3377655.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值