Delphi berlin ShowMessage的改進與使用

來源:互聯網
上載者:User

標籤:phi   跨平台   option   調用   name   函數實現   rate   通過   代碼   

這個版本的delphi對ShowMessage進行了重新實現,更好的適應移動跨平台,即在移動平台下是非同步執行的,而在Windows及os X下是同步執行的,如果自己控制是否非同步顯示對話方塊,也可以通過TDialogServiceAsync(非同步對話方塊)及TDialogServiceSync(同步對話方塊)來顯示對話方塊,如果使用這個兩個類,需要手工uses對應的單元。當然了,最簡捷的方法還是ShowMessage.下面我直接上了代碼並對三種使用方法做了注釋,分享之。 unit Unit2; interface uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.StdCtrls, FireDAC.Stan.Intf,
  FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
  FireDAC.Phys.Intf, FireDAC.DApt.Intf, Data.DB, FireDAC.Comp.DataSet,
  FireDAC.Comp.Client, System.Rtti, FMX.Grid.Style, Data.Bind.EngExt,
  Fmx.Bind.DBEngExt, Fmx.Bind.Grid, System.Bindings.Outputs, Fmx.Bind.Editors,
  Data.Bind.Components, Data.Bind.Grid, Data.Bind.DBScope, FMX.ScrollBox,
  FMX.Grid,FMX.DialogService.Async; //  FMX.Grid,FMX.DialogService.Async實現非同步對話方塊的單元,需要手工加入.  type
  TForm2 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    procedure ShowMessageDialogCallBack(Sender: TObject; const AResult: TModalResult);
  end; var    //
  Form2: TForm2; implementation {$R *.fmx} procedure TForm2.Button1Click(Sender: TObject);
begin
//在移動平台下非同步執行,在windows,osx上同步執行,查看源碼,會發現具體實現中判斷了是否是android
//與ios,是的話,通過TDialogServiceAsnyc這個類來顯示非同步對話方塊
  ShowMessage(‘Hello world.‘);
//如果要在Windows及os X上也非同步顯示對話方塊,則需要直接用TDialogServiceAsnyc來顯示
//  TDialogServiceAsync.ShowMessage(‘Hello world async.‘);
end; procedure TForm2.Button2Click(Sender: TObject);
begin
//直接顯示非同步對話方塊,並通過匿名函數實現回調,當使用者點擊確定按鈕時,執行該匿名函數
//在所有平台下測試的結果,都是非同步執行的,換句話說,在Windows及osX上也不是模態顯示。
  TDialogServiceAsync.ShowMessage(‘Hello world‘,
  procedure (const AResule:TModalResult)
  begin
    ShowMessage(‘Click ok‘);
  end
  );
end; procedure TForm2.Button3Click(Sender: TObject);
begin
//通過回調事先寫好的事件函數,來非同步顯示對話方塊,即當使用者按下確定按鈕時,執行
//ShowMessageDialogCallBack.
//在所有平台下測試的結果,都是非同步執行的,換句話說,在Windows及osX上也不是模態顯示。
  TDialogServiceAsync.ShowMessage(‘Test‘,ShowMessageDialogCallBack,nil);
end; procedure TForm2.ShowMessageDialogCallBack(Sender: TObject;
  const AResult: TModalResult);
begin
  showMessage(‘Call Back.‘);
end; end.  後記,進一步看了MessageDialog的實現,基本同TDialogServiceAsync.ShowMessage,只不過,可以指定顯示幾個按鈕,象Yes,No,Cancel等,官方內部實現的代碼,看起來很囉嗦,一點都不好看。試著調用這個方法,寫起來也不爽,同時在IOS模擬器,osX,Windows下運行,按鈕都是英文的,沒找到哪裡個性成中文,這就不完美了,總不能讓中文app顯示出一個帶Yes No的對話方塊吧,不論不類的。 怎麼辦呢?難怪當我說Showmessage這個實現完美的時候,高老師說不完美,還真是如此,如果想完美,還是用高師的通用介面好了! 再後記:找到解決方案,把fmx.consts複製到項目下,修改其中的資訊為漢字即可。 http://blog.sina.com.cn/s/blog_44fa172f0102w23d.html

Delphi berlin ShowMessage的改進與使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.