2021年1月13日 星期三

【Delphi Multi-Device Application】 ListBox 自訂 ListBoxItem

procedure TForm1.FormCreate(Sender: TObject);
begin
  ListBox1.ShowScrollBars := False;
  ListBox1.AniCalculations.Animation := True;
  ListBox1.AniCalculations.Averaging := True;
  ListBox1.AniCalculations.BoundsAnimation := True;
  ListBox1.AniCalculations.TouchTracking := [ttVertical];
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
var lbItem:TListBoxItem;
  frmItem:TFrame2;
begin
  lbItem := TListBoxItem.Create(Self);
  frmItem := TFrame2.Create(Self);
  frmItem.Parent := lbItem;
  frmItem.Name := 'frmItem_'+FormatDateTime('HHNNSSZZ', Now);
  lbItem.Height := frmItem.Height;
  frmItem.Align := TAlignLayout.alClient;
  lbItem.Parent := ListBox1;
end;

2021年1月12日 星期二

【Delphi Multi-Device Application】 ScrollBox滑動效果設定

  with VertScrollBox do
  begin
    ShowScrollBars := False;
    //
    AniCalculations.BeginUpdate;
    AniCalculations.TouchTracking:=[ttVertical];
    AniCalculations.AutoShowing := True;
    AniCalculations.Animation := True;
    AniCalculations.BoundsAnimation := True;
    AniCalculations.Averaging := True;
    AniCalculations.EndUpdate;
  end;

2021年1月6日 星期三

【Delphi Multi-Device Application】 動態呼叫 日期選擇器

uses FMX.Platform, FMX.Pickers,  FMX.DateTimeCtrls;

procedure TForm1.Button2Click(Sender: TObject);
var
  PickerService: IFMXPickerService;
  FDateTimePicker: TCustomDateTimePicker;
begin
  TPlatformServices.Current.SupportsPlatformService(IFMXPickerService, PickerService);
  FDateTimePicker := PickerService.CreateDateTimePicker;
  FDateTimePicker.Parent := Button2;
  FDateTimePicker.ShowMode := TDatePickerShowMode.psmDate;
  FDateTimePicker.Date := Date;
  FDateTimePicker.TodayDefault := True;
  FDateTimePicker.PreferedDisplayIndex := Screen.DisplayFromPoint(Screen.MousePos).Index;
  FDateTimePicker.OnDateChanged := WhenDateChanged;
  FDateTimePicker.Show;
end;

procedure TForm1.WhenDateChanged(Sender: TObject; const ADate: TDateTime);
begin
  ShowMessage(DateTimeToStr(ADate));
end;

【Delphi Multi-Device Application】 顯示/隱藏 虛擬鍵盤

 uses FMX.VirtualKeyboard, FMX.Platform;

In the .dpr set VKAutoShowMode to Never

begin
  Application.Initialize;
  VKAutoShowMode := TVKAutoShowMode.Never;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end. 

Show soft keyboard on the form (for example on TEdit.OnEnter event):

var
  FService: IFMXVirtualKeyboardService;
begin
  TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(FService));
  if (FService <> nil) then
  begin
    FService.ShowVirtualKeyboard(Edit1);
    Edit1.SetFocus;
  end;
end;

Hide soft keyboard on the form (Edit1 will be still focused with hidden soft keyboard):

var
  FService: IFMXVirtualKeyboardService;
begin
  TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(FService));
  if (FService <> nil) then
  begin
    FService.HideVirtualKeyboard;
    Edit1.SetFocus;
  end;
end;

轉貼至 https://stackoverflow.com/questions/27402101/how-to-hide-and-again-show-soft-keyboard-while-tedit-is-in-focus-delphi-xe7