![]() |
|
Barkod Okutma El Terminali - Baskı Önizleme +- Delphi Can (https://www.delphican.com) +-- Forum: Delphi (https://www.delphican.com/forumdisplay.php?fid=3) +--- Forum: Mobil Platform - FireMonkey (FMX) (https://www.delphican.com/forumdisplay.php?fid=7) +--- Konu Başlığı: Barkod Okutma El Terminali (/showthread.php?tid=757) |
Barkod Okutma El Terminali - sametkayaoglu - 13-03-2017 Herkese iyi günler bu problem hakkında bilgisi olan var mıdır? Aşağıda bulunan kod yardımı ile listemi oluşturup klavyeyi bir defa açtıktan sonra el terminalinden okunan değeri alabiliyorum ancak showmessage sonrası veya TdateEdit gibi nesnelere tıkladıktan sonra tekrar okutma işleminde problem çıkıyor klavyenin tekrar açılıp kapanması gerekiyor bunun ekrana getirmeden gizli bir şekli var mı? yoksa buna ihtiyaç olmadan tekrar okutulan değeri alabilir miyiz procedure TForm1.FormCreate(Sender: TObject);
begin
if Assigned(FTextListener) then
exit;
FTextListener := TCustomAndroidTextListener.Create(self);
FFMXTxp := FMX.Platform.Android.MainActivity.getTextEditorProxy;
FFMXTxp.setInputType(TJFMXTextEditorProxy.JavaClass.INPUT_ALPHABET);
FFMXTxp.addTextListener(FTextListener);
end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
Shift: TShiftState);
begin
if key = 13 then
begin
ShowMessage(JCharSequenceToStr(FMX.Platform.Android.MainActivity.getTextEditorProxy.getText));
end;
end;
procedure UnregisterTextListener;
var
FFMXTxp: JFMXTextEditorProxy;
begin
if not Assigned(FTextListener) then
exit;
FFMXTxp := FMX.Platform.Android.MainActivity.getTextEditorProxy;
FFMXTxp.removeTextListener(FTextListener);
FTextListener.Free;
end;
{ TCustomTextListener }
constructor TCustomAndroidTextListener.Create(aForm: TCommonCustomForm);
begin
inherited Create;
FForm := aForm;
end;
function TCustomAndroidTextListener.TryAsKey(const aChar: Char;
var Key: Word): Boolean;
var
LOrd: Word;
LType: TUnicodeCategory;
begin
LOrd := 0;
LType := System.Character.TCharacter.GetUnicodeCategory(aChar);
// lo spazio va calcolato a parte perché è presente un BUG in FForm.KeyDown(LKey, LChar, []);
// in quanto il carattere di spazio lo trasforma in #0 impedendone l'invio
case LType of
TUnicodeCategory.ucControl:
begin
LOrd := Ord(aChar);
if LOrd in [vkReturn, vkLineFeed] then
LOrd := vkReturn;
end;
TUnicodeCategory.ucSpaceSeparator:
LOrd := vkSpace;
end;
Result := LOrd > 0;
if Result then
Key := LOrd;
end;
procedure TCustomAndroidTextListener.onComposingText(beginPosition,
endPosition: Integer);
begin
end;
procedure TCustomAndroidTextListener.onSkipKeyEvent(event: JKeyEvent);
begin
end;
procedure TCustomAndroidTextListener.onTextUpdated(text: JCharSequence;
position: Integer);
var
LStr: string;
LKey: Word;
LChar: Char;
LPosition: Integer;
LValidString: string;
begin
LStr := JCharSequenceToStr(text);
LKey := 0;
try
// no valid character
if position = 0 then
exit;
// string on mobile are 0 based
// the input string contain all characters pressed until this time. So if I pressed f then o then o is something like this "[3]foo"
// I have to calculate the last digit character
LPosition := 2 + ifthen(position = 0, 1, Trunc(Log10(position) + 1))
+ position;
LValidString := LStr.Substring(LPosition - position);
if FLastStr.Contains(LValidString) and
((FLastStr.Length - LValidString.Length) = 1) then
begin
// delete command was pressed
LChar := #0;
LKey := System.UITypes.vkBack;
end
else
LChar := LStr[LPosition - 1];
// I need to understand if the key is not a char but a key to respect the method signature.
// See documentation for more details http://docwiki.embarcadero.com/Libraries/Berlin/en/FMX.Forms.TCommonCustomForm.KeyDown
if TryAsKey(LChar, LKey) then
LChar := #0;
FForm.KeyDown(LKey, LChar, []);
finally
FLastStr := LValidString;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Edit1.SetFocus;
end;
Cvp: Barkod Okutma El Terminali - Abdullah ILGAZ - 06-07-2017 (13-03-2017, Saat: 10:55)sametkayaoglu Adlı Kullanıcıdan Alıntı: Herkese iyi günler bu problem hakkında bilgisi olan var mıdır? Merhaba, Değer okuma işlemini yapmadan önce klavyenin durumunu formun açılışında ve run-time'da yönetebilirsiniz. Bunun için yazmış olduğum prosedürleri paylaşıyorum. uses FMX.VirtualKeyboard; Form üzerindeki bir komponent (yada kontrol)'e girince gizlemek için procedure HideKeyboardOn(AControl: TControl); var FService: IFMXVirtualKeyboardService; begin TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(FService)); if (FService <> nil) then begin FService.HideVirtualKeyboard; AControl.SetFocus; end; end; Form üzerindeki bir komponent (yada kontrol)'e girince aktif etmek için procedure ShowKeyboardOn(AControl: TControl); var FService: IFMXVirtualKeyboardService; begin TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(FService)); if (FService <> nil) then begin FService.ShowVirtualKeyboard(AControl); AControl.SetFocus; end; end; İhtiyaç durumunda Form'da Klavyeyi Aktif etmek için /// var FService: IFMXVirtualKeyboardService; begin TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(FService)); if (FService <> nil) then begin VKAutoShowMode := TVKAutoShowMode.Always; end; İhtiyaç durumunda Form'da Klavyeyi Gizlemek için /// var FService: IFMXVirtualKeyboardService; begin TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(FService)); if (FService <> nil) then begin VKAutoShowMode := TVKAutoShowMode.Never; end; end; |