How to activate the Sensor Proximity with Firemonkey on IOS
The sensor proximity (which is located at the top of the monitor) is for detecting the proximity of any object (e.g. your face during a call)in order to turn off the monitor avoiding to push wrong buttons. If you want to activate the proximity sensor, it’s a very very simple procedure, you have just to enter the following line of code:
{$ IFDEF FPC}
UIDevice.CurrentDevice.setProximityMonitoringEnabled (true);
{$ ENDIF}
of course, remember to include “iphoneall” in Uses
Sqlite based IOS by Delphi XE2 and Firemonkey
The last weekend I downloaded the new Rad Studio XE2 Trial by the Embarcadero site. I realized that there are many and interesting news, especially the introduction of Firemonkey and the possibility to create with Delphi some applications for Mac OSX and IOS. Apart testing all the examples included in the trial version, the first thing I did was try to connect to a local database, which is the necessary condition to develop any app that is not a calculator. The result was somewhat disappointing, components and classes of db will not work on IOS. This was a big constraint, so I tried to create a small test-app and to edit the code via XCode (which in this case uses FPC) and from there I was able to connect to a SQLite database.
uses
… SQLite3db,SQLite;
….
var
QryResult,RecResult : Classes.TStringList;
fdb:TSQLiteDatabase;
begin
QryResult := Classes.TStringList.Create
fdb:=TSQLite.Create(Filename);
if fdb.Query(sql,QryResult) then
begin
for i1 := 0 to QryResult.Count-1 do
begin
….
end;
end;
end;
However, the programming becomes very uncomfortable because in this way by Delphi I could only program the graphical interface and a bit more (might as well work directly from Xcode…)
So that I downloaded in internet a class with basic functions for using SQLite under windows. I found functions and methods in compiling with Xcode which are very different from that ones used in compiling with windows.Tthen I created my own class that contains the Compiler Directive which selects functions / methods depending on the environment.
uses
…
{$IFDEF MSWINDOWS}
SQLiteTable3
{$ELSE}
SQLite3db,SQLite
{$ENDIF }
;
…
constructor TBBSqlite.Create(Filename : String);
begin
{$IFDEF MSWINDOWS}
fdb:=TSQLiteDatabase.Create(Filename);
{$ELSE}
fdb:=TSQLite.Create(Filename);
{$ENDIF }
end;
The result I get is being able to program directly in Delphi without worrying about the necessity to enter every time the code from XCode.
Here you can download the example: Example firemonkey sqlite delphi xe2
Reverse the mouse buttons
This feature allows you to reverse the mouse buttons:
SystemParametersInfo(SPI_SETMOUSEBUTTONSWAP, 1, nil, 0);
To return to the original state instead of the buttons:
SystemParametersInfo(SPI_SETMOUSEBUTTONSWAP, 0, nil, 0);
I used this feature only once since it can confuse the user, especially if you do not provide all the circumstances, for example in the event of an error that closes the application crashes the buttons are reversed. The result I think I will.
However, you can call the API SystemParametersInfo to set and get all the settings controlled by the Windows Control Panel. Over the next few notes as we shall see.
Simulate mouse clicks
It ‘s very useful if you plan to drive a third-party window or a web site, once acquired the right positions of the mouse.
Position the mouse
SetCursorPos(x, y);
Simulation of pressing the left mouse
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Count the lines scroll wheel mouse
To count the lines of the scroll wheel of the mouse using the API SystemParametersInfo already used in other notes. Here is a function that returns the number of lines:
function GETWHEELSCROLLLINES: Integer;
begin
SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, @Result, 0);
end;
If it returns -1 should be set to scroll the entire page.
Detecting the mouse position
Sometimes you can detect useful to obtain the current mouse position. In myapplication I used two different methods.
If I simply pointed out the location of the mouse on the form or a component you can use the onmousemove event of the component as follows:
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
begin
x_edit.Text :=’X=’+ IntToStr(X);
y_edit.Text:=’Y=’+ IntToStr(Y);
end;
Restart the application
Sometimes it is necessary to restart your application, for example, after installingupdates.
First retrieve the full path of the file name.
path := PChar(ParamStr(0));
Then we start the duplicate of your application:
WinExec(pchar(path), SW_SHOW);
Finish the current application
Application.Terminate;
Retrieve the default language of the system
This feature allows you to retrieve the default language set on the system, consists of two functions: GetSystemDefaultLangID that returns the binaryLanguage identifier in Microsoft Word format (eg 1040 for Italy) and function VerLanguageName that retrieves the description of the language associated with the binary Microsoft language identifier.
function retrieve_language: string;
var
language: array [0..50] of char;
begin
VerLanguageName(GetSystemDefaultLangID,language, 50);
Result := StrPas(language);
end;

