Category: StackOverflow

What is the best general way to pre-set username and password INPUT fields inside a Website loaded at TWebBrowser FMX

What is the best method and general solution to get input fields username and password pre-set from inside an application for an loaded Website inside Delphi TWebBrowser FMX? For example: Var iuser,ipassword: String; ... WebBrowser.URL := www.facebook.com; WebBrowser.Navigate; WebBrowser.EvaluateJavaScript( '<script>' + 'var e = document.getElementById("email");' + 'e.value = "' +iuser+'";}' + 'var s = document.getElementById("pass");' + 's.value = "' +ipassword+'";}' + '</script>' ); The above way seems not to work (fields are empty and after calling code a second time causing error) and this way is even not general, because the ID for username and password will be different on most websites.
Read More

Delphi: How to include resources into a component relativ to this component

I'm trying to create a Delphi component. This component needs some images which are included with {$R *.res *.rc} in this unit. Additional I have a Delphi BPL project which contains this component. I can compile, build and install this project without problems. The problem comes when I try to use this component in other projects which are not in the same directory. There I get the error that he could not find the .res-file. Only when I include the .rc-file in these other projects or when I change {$R *.res *.rc} to absolute paths it works. But both solutions I don't like. What I want is to include only the .pas-file and then the compiler should find the corresponding resources based on {$R *.res *.rc}. Is this possible and if yes how? NOTE: The path to the .pas- and rc-file is inside of the searchpath. I'm using Delphi 10 Seattle and it is a FMX-component.
Read More

Firemonkey TListBox.OnClick – which item is clicked?

Delphi 10.2.2 mobile Starting with a blank mobile project, I drop a TListBox on the form. I add two TListBoxItems. procedure TForm1.ListBox1Click(Sender: TObject); begin ShowMessage('ListBoxItem.itemindex = ' + ListBox1.ItemIndex.ToString); end; When I click on the first item in Windows and Macintosh, the OnClick() correctly reports that item index 0 has been clicked. When I click on the first item in mobile (iOS and Android) the OnClick() reports the item index as -1 (not 0 as it should). Then it goes on to highlight the first item. If I then click on the second item in mobile, the OnClick() reports the item index as 0 (not 1 as it should). Then it goes on to highlight the second item. How can I get the correct item in OnClick() when clicking in a TListBox on mobile?
Read More

How to change dragmode property of a label (firemonkey)

This must be so simple for you guys, but I don't have a clue what the problem is. This is the code: unit Unit7; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls, FMX.Controls.Presentation; type TForm7 = class(TForm) Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form7: TForm7; implementation {$R *.fmx} procedure TForm7.Button1Click(Sender: TObject); begin label1.dragmode:=dmautomatic; end; end. All I've done is created a form, put a label and a button on it, and attempt to change the DragMode property of the label to dmAutomatic when the button is clicked. The program won't compile, the compiler simply states: undeclared identifier: dmautomatic. I've missed something incredibly obvious, but I can't see what it is.
Read More

Why won’t controls span multiple columns or rows in an Android FireMonkey app?

I have a FireMonkey app with a GridPanelLayout, aligned to client. It's got 6 columns and 16 rows. Controls include glyphs, edits, and buttons. The TEdits span multiple columns, and the TButtons span both multiple columns and rows. The controls are currently all aligned to client. When I compile and run on Windows everything looks and acts as expected. However, on Android devices (I tried two, Android 6.0.1, and Amazon FireOS) none of the controls span more than one column or row. They're each just one cell big. Instead of spanning 6 cols, TEdits span just 1 col; instead of spanning 2 cols and 2 rows, TButtons also span 1 col and 1 row. Why won't the controls span multiple columns or rows on Android?
Read More

Delphi Berlin 10.1 create file/folder OS X

How to create file/folder on OS X via delphi? I'm trying to use functions System.SysUtils.FileCreate And System.IOUtils.TDirectory.CreateDirectory Code: if FileCreate('/var/folders/bla.txt') = INVALID_HANDLE_VALUE then raise Exception.Create('File already exists'); or `TDirectory.CreateDirectory('/var/folders/mydirdelete');` Anyway when i run app i get Exception EFileNotFoundException in module blprtl240.dylib at 0053AFAF. The specified file was not found. Even if i create folder. Any advices?
Read More

Matrix View for Photos from database

I am wanting to display on Android a grid of photos that are retrieved from a database. I thought that maybe using ListView with LiveBinding might work but I can't see how it allows multiple records per line. Anyone have any ideas or can point me in the right direction? Happy to also look at 3rd party components if diffiicult. Thanks
Read More

Firemonkey android crash without no code

hope somebody can help i just put one rectangle and 1 listbox without code the deploy to device. i use oppo A33W, sdk-27 ndk-r9. the problem is (1) when i unplug the usb cable from device and screen goes to dim and sleep. then i turn on the screen then app crash not responding. but this problem not happen when device always wake up. problem (2), before screen goes off app send to back (press device home button) and i let device sleep mode. turn on the screen and select the app icon, app suddenly crash somebody help please
Read More

avoid onclick event while scroll box is scrolling firemonkey

I've having a little trouble that I hope you all can help me or orient me, I have a TVertScrollBox, it control held many TRectangle components, each has assing an OnClickEvent that execute some logic, but, when the scroll is scrolling and the user stop it on an TRectangle its event OnClick is fired, I would like avoid it, but I cannot solve this problem. I've created an simple code example to show you the problem. 1-Create new Multi-Device Application(C++) 2-Drop on the form an TVertScrollBox from the tool palette. 3-Align to client the TVertScrollBox. in User declarations Add __fastcall ~TForm1(); // destructor void __fastcall RectLogicClick(TObject *Sender); // event for OnClickEvent in the TRectangles TRectangle* rects[20]; // array of rectangles for delete at the end. in FormCreate void __fastcall TForm1::FormCreate(TObject *Sender) { for(int i=0; i<20; ++i) { TRectangle * rect = new TRectangle(VertScrollBox1); rect->Parent = VertScrollBox1; rect->OnClick = RectLogicClick; rect->Width = 100; rect->Height = 50; rect->Position->X = 10; rect->Position->Y = 20 + i*50; rects[i] = rect; } } in destructor __fastcall TForm1::~TForm1() { for(int i=0; i<20; ++i) { rects[i]->Parent = nullptr; delete rects[i]; } } And in RectLogicClick void __fastcall TForm1::RectLogicClick(TObject *Sender) { ShowMessage("Rect Clicked"); } if you run this in an Android device and you scroll and stop over any Rectangle it's OnClick event is fired. Is any way of lock the event onClick when the Scroll is scrolling ? this project is orient to an mobile devices, using firemonkey(C++) framework and Rad Studio 10.2.1 tokyo
Read More

Find contact name by phone number in Android service (Delphi + Firemonkey)

How can i find contact name by phone number in Android service (Delphi + Firemonkey)? Delphi Tokyo + Firemonkey (FMX). I can not understand, why wSubCursor.getCount returns 0? The phone number in the address book is exactly present. The function is executed inside the service. function GetContactByPhoneNumber(const sTel: string): string; var wJDislpayName, wJFirstName, wJLastName, wJQueryStr: JString; wJQueryParams: TJavaObjectArray<JString>; wSubCursor: JCursor; wfilter: TJavaObjectArray<JString>; wDataUri: JNet_URI; begin wDataUri := TJContactsContract_Data.JavaClass.CONTENT_URI; wfilter := TJavaObjectArray<JString>.Create(3); wfilter[0] := TJCommonDataKinds_StructuredName.JavaClass.DISPLAY_NAME; wfilter[1] := TJCommonDataKinds_StructuredName.JavaClass.FAMILY_NAME; wfilter[2] := TJCommonDataKinds_StructuredName.JavaClass.GIVEN_NAME; wJQueryStr := StringToJString('mimetype = ? AND lookup = ?'); wJQueryParams := TJavaObjectArray<JString>.Create(2); wJQueryParams[0] := TJCommonDataKinds_Phone.JavaClass.NUMBER; wJQueryParams[1] := StringToJString(sTel); wSubCursor := TAndroidHelper.Context.getContentResolver.Query(wDataUri, wfilter, wJQueryStr, wJQueryParams, nil); try if wSubCursor.getCount > 0 then begin // Getting only first row, as we retrieving only names, a contact can have only one first name, one familyname, // for phone number for example, we need to loop on each row (while (wSubCursor.moveToNext) do) because a contact can have many phone number wSubCursor.moveToNext; wJDislpayName := wSubCursor.getString(0); wJLastName := wSubCursor.getString(1); wJFirstName := wSubCursor.getString(2); end; Result := JStringToString(wJDislpayName); finally wSubCursor.close; FreeAndNil(wSubCursor);// := nil; end; end; Thanx
Read More

Delphi – How to keep doing queries after closing the android app?

I'm working on a project. The project contains a service. This service processes queries at a MySQL database and shows the user a notification that depends on the result of the query. But the query stops when I close the main app. How can I keep doing the queries even if the main app is closed? (Like chat apps you know) PS: Queries and notifications codes are placed in service and queries are made with the PPL (Parallel Programming Library) PS: I don't think there is a problem with the code lines. I guess I need a triggering with the services for main app. unit ComPhoneService1; interface uses System.SysUtils, System.Classes, System.Android.Service, AndroidApi.JNI.GraphicsContentViewText, Androidapi.JNI.Os, System.Notification, Data.DB, DBAccess, Uni, MemDS, UniProvider, MySQLUniProvider, System.IOUtils, System.Threading; type TDM = class(TAndroidService) NotificationCenter1: TNotificationCenter; MySQLUniProvider1: TMySQLUniProvider; UniBaglanti: TUniConnection; UniQuery1: TUniQuery; function AndroidServiceStartCommand(const Sender: TObject; const Intent: JIntent; Flags, StartId: Integer): Integer; Procedure Sorgu; private { Private declarations } public { Public declarations } end; var DM: TDM; implementation {%CLASSGROUP 'FMX.Controls.TControl'} {$R *.dfm} uses AndroidAPI.JNI.APP; Procedure TDM.Sorgu; var ATask: ITask; IniFile: TStringList; Bildirim: TNotification; begin ATask := TTask.Create(Procedure() var A: Boolean; begin A := False; Repeat begin Sleep(10000); if FileExists(TPath.GetPublicPath + '/pcid.ini', True) = True then begin try IniFile := TStringList.Create; IniFile.LoadFromFile(TPath.GetPublicPath + '/pcid.ini'); UniQuery1.SQL.Text := 'select * from tblHareketler where PCID=:aydi and Goruldu=:Durum'; UniQuery1.ParamByName('aydi').Value := Trim(IniFile.Text); UniQuery1.ParamByName('Durum').Value := 'Gorulmedi'; UniQuery1.ExecSQL; UniQuery1.Open; if UniQuery1.RecordCount > 0 then begin Bildirim := NotificationCenter1.CreateNotification; Bildirim.AlertBody := 'Yeni eylemler mevcut! Görmek için lütfen tıklayınız'; NotificationCenter1.PresentNotification(Bildirim); end; finally IniFile.Free; end; end; end; Until A = True; end); ATask.Start; end; function TDM.AndroidServiceStartCommand(const Sender: TObject; const Intent: JIntent; Flags, StartId: Integer): Integer; begin Sorgu; Result := TJService.JavaClass.START_STICKY; end; end. https://i.hizliresim.com/nOjO55.gif Thanks already Best Regards...
Read More