Category: Firemonkey

Delphi FMX Verify if EditText contains Numbers Only?

I need to use different procedure depending on the Edittext.text i need to call ProcessA(value: string); with Parameters of last 4 Char of string if Edittext.text's first 4 char are string and next 4 are number. and Call ProcessB(value:integer) with last four numbers as parameter if all 8 char are numbers ? For Example: If EditText.Text is ASDF1234 then i'll call ProcessA and if EdiText.Text is 12345678 then i need to call ProcessB. Show Error if string is like ASD12345 or ASDFG123 or 1234567A or if Numbers are in decimal. How can i verify this ?
Read More

Join Multiple Images IN FMX?

In VCL this is how i make a single image from two images while creating space between them: procedure TForm2.Button1Click(Sender: TObject); var p1,p2:string; b1,b2:TBitmap; bitmap: TBitmap; begin p1:='C:\Users\John\Desktop\p1.bmp'; p2:='C:\Users\John\Desktop\p2.bmp'; b1:=TBitmap.Create; b1.LoadFromFile(p1); b2:=TBitmap.Create; b2.LoadFromFile(p2); sBit:= TBitmap.Create; try sBit.Height:=b1.Height; sBit.Width:=b1.Width+5+b2.Width; sBit.Canvas.Draw(0,0,b1); //Drawing First Bitamp here sBit.Canvas.Draw(b1.Width + 5,0,b2);// Drawing Second one Image1.Picture.Bitmap.Assign(sBit); finally sBit.FreeImage; end; end; Now How Can i draw the same in FMX ? EDIT Using Bitmap.CopyFromBitmap Works!! procedure process; var p1,p2: String; b1,b2,b3:TBitmaps; rect: TRect; begin //load both bitmaps to b1 and b2. rect.Left:=0; rect.Top:=0; rect.Width:=b1.Width; rect.Height:=b1.Height; b3:= TBitmaps.Create; b3.Height:= b1.height; b3.widht:=b1.width; b3.CopyFromBitmap(b1,rect,0,0); b3.CopyFromBitmap(b2,rect,b1r.Width+5,0); Image1.Bitmap.Assign(b3); end;
Read More

Responsive GUI when using Bluetooth LE

Delphi 10.3 Rio, Android 8 When I am using BLE in the code (subscribing, readind, writing...), my GUI is frozen for several seconds. I'd like to give immediate feedback to the user that an action is currently processed. How can I make sure that the few lines of code (i.e. displaying a progress wheel) will be displayed right after the click event and before any BLE transaction?
Read More

Persistence with Spring4D

My blog tagline is certainly no accident.  I have been interested in persistence frameworks for a long time, and thought I would use Spring4D’s Marshmellow ORM for a project.  Spring4D has been around for quite some time and just had it’s first conference in Italy so I figured the framework was mature and warranted a closer look.  I had previously used the Spring4D DI container, and decided this time to use Spring4D collections as well to avoid as much code bloat as possible. The first thing I discovered is that the Spring persistence layer aka Marshmellow has a very unfortunate name.  Trying to google it with “delphi” leads to all sorts of hits related that Android version.  The next thing I learned is that development has been put on hold as of September 2018 due to a lack of resources.  This is unfortunate, as there are not that many open source ORMs that use the newer language features of Delphi when compared C# or Java. The third thing I quickly learned is that other than the Tests, there is not a whole lot of documentation available.  There is the reference help which is really not that helpful.  It doesn’t contain descriptions of the class interactions or architecture and has no examples of usage.  Really it’s not much more informative than drilling through the code.  The best source of “getting started” help that I could find is the previous bitbucket repo. There is of course also the google groups if you need to get clarification of something, and reading previous posts can help you from running into common issues. As a newbie, it’s not clear how the [InheritenceAttribute()] works so I will have to investigate it further. I assume if the last descendant in a class hierarchy is the only one marked as an entity, it will by default have all the fields marked with the Column() attribute in all ancestor classes. Another thing that is not particularly clear from any documentation is how the underlying datatype employed by the database is determined.  There are really only 3 pertinent parameters supplied to the Column() attribute, namely length, precision and scale.  Length only applies to string types and precision, scale to numeric.  It is unclear how precision and scale effectively change the numeric datatype and it’s corresponding precision or scale, other than for Integer datatypes you specify 0,0 for precision,scale. I’m sure all this will become clear as I use the framework more, but some more thorough ‘Getting Started’ documentation would have been really nice.
Read More

How to get Login Dialogs Appearing on the TaskBar

Most of the applications I have worked on in Delphi are database apps that may present a splash form quickly followed by a login dialog.  If the user fails to authenticate, the application needs to terminate gracefully.  The only way to do so cleanly is to modify the DPR code with some conditional logic. I’ve seen scenarios where after the main form was created the login dialog was invoked and if authentication failed everything was torn down. This complicates the shutdown logic, and often didn’t work well, encouraging a call to Halt() and sometimes leaving the process in memory. Any long time Delphi user knows that messing with the generated DPR code in Delphi can cause all sorts of grief later when Delphi tries to auto create forms and add units to the uses clause.  That is out of scope for this post, suffice to say that it is possible to write something like this: var User :TUser; begin Screen.Cursor := crAppStart; try Application.Initialize; Application.MainFormOnTaskbar := True; Application.Title := 'My Secure App'; Application.CreateForm(TMainDm, MainDm); finally Screen.Cursor := crDefault; end; User := TfrmLogin.Login ( function (const UserName,Password :string) :TObject begin Result := MainDm.Session.FindWhere<TUser>( Restrictions.&And( Restrictions.Eq('UserName',UserName), Restrictions.Eq('Password',Password) ) ).FirstOrDefault; end, { UserName can be passed as first parameter so don't have to type it in all the time } ParamStr(1), 3 {credential retries available } ) as TUser; if User <> nil then begin Application.CreateForm(TfrmMain, frmMain); frmMain.CurrentUser := User; Application.Run; end; end. The problem is that the Login Dialog does not appear on the Windows Taskbar. If it is hidden behind other windows, the user may think the application has not been launched and attempt to start another instance. There is no easy way for the user to bring the login dialog to the foreground short of closing other windows that may be in front of it. Putting the form on the taskbar solves this. As a quick solution I looked at the SetMainForm method in the Vcl.Forms unit, and decided to extract the ChangeAppWindow() procedure since it is not available outside of the Forms unit. Then I simply called it from this event, and voila! a taskbar button showing the Login form. procedure TfrmLogin.FormCreate(Sender: TObject); begin ChangeAppWindow(handle,True,True); end; I’m sure there are reasons why this method is not exposed as a public TApplication class procedure, but perhaps it could be with a usage caveat.
Read More

How to make a tab invisible, but not the sheet that would show when the tab is selected? – Delphi FireMonkey

I want to be able to open tabA from a button on tabB. But I don't want the user to be able to open tabA, apart from using that button. However if you set the TabA.Visible := False it sets the tab and the tab sheet as not visible. Is there any way around this? My idea would be to cover tabB with a blank white image when I need tabA showing, and when I need tabB showing just hide all the tabA controls. Would this be the best thing to do for this issue?
Read More

Why does accessing a fmx controls "height" in "DoRealign" crash the Delphi designer?

Writing my own slider control in Firemonkey that works fine at runtime but will often crash the designer. I have tracked the crash down to accessing the controls Height called from my overridden "DoRealign". It does not crash all of the time and often pressing "OK" will allow me to continue designing the form but it never crashes at runtime. My only work around is to simply exit this routine on the condition "csDesigning in ComponentState". I am curious to know where I am going wrong with my component design. procedure TLFFader.DoRealign; var vI, T: TFmxObject; NewSize: Single; begin inherited; if not FDisableAlign then begin FDisableAlign := True; try T := FindStyleResource('vtrack'); if Assigned(T) and (T is TControl) then TControl(T).Visible := True; if Assigned(T) and (T is TControl) and (Max > Min) then begin vI := FindStyleResource('vindicator'); if Assigned(vI) and (vI is TControl) then begin NewSize := (TControl(T).Height - TControl(T).Padding.top - TControl(T).Padding.bottom - TControl(vI).Margins.top - TControl(vI).Margins.bottom) * FValueRange.RelativeValue; TControl(vI).Height := Round(NewSize); TControl(vI).Visible := TControl(vI).Height > 2; end; end; if assigned(FThumb) then begin FThumb.Width := Width; FThumb.Height := FThumbHeight; FThumb.Position.X := 0; FThumb.Position.Y := (Height - FThumbHeight) * (1-FValueRange.RelativeValue); FThumbText.Text := FPercentPrefix + IntToStr(Round(FValueRange.RelativeValue * 100))+'%'; end; finally FDisableAlign := False; end; end; end;
Read More

Cannot assign TBitmapOfItem to TClipBoard?

I need to crop pdf and create word document of that cropped png image by pasting that in word document. I am using Firemonkey Platform this is code : procedure TForm2.Button1Click(Sender: TObject); begin ShellExecute(FormToHWND(Self),'open',PChar(GetCurrentDir+'\cairo.exe') ,PWideChar('-opw '+Edit1.Text+ ' -cropbox -png -x 64 -y 215 -W 144 -H 375 -r 167 '+ PdfFile+' tools/card'),'',SW_Hide); Sleep(500); Image1.Bitmap.LoadFromFile(Output); end; procedure TForm2.Button2Click(Sender: TObject); begin ClipBoard.Assign(Image1.Bitmap); end; procedure TForm2.FormCreate(Sender: TObject); begin Output:= GetCurrentDir+'\tools\card-1.png'; end; Clicking on button2 pops the error Cannot assign TBitmapOfItem to TClipBoard. How to copy the image to clipboard and create word document (don't know much about it) ?
Read More

The Story of an intern at TMSSoftware

Hello, this is the intern speaking (or writing) about his experience at TMSSoftware.
I’m a second year graduate student in programming-informatics who has been given the opportunity to do my internship here at TMSSoftware.

Getting started

My first week starting here was interesting as I had no real background experience in Delphi or Object Pascal, as the primary languages I learned at school were Java and C#. Thankfully, I had a lot of resources available, which includes the Object Pascal Handbook by Marcu Cantù. So getting started went smooth.

My internship was split up into three parts, were the first part was to study and test different REST services. The second part was based on implementing the APIs such as Google Translate and Microsoft Vision. The third part involved using the implementation in an application called TMS Vision.

TMS Vision should allow visually impaired people to be informed about their environment by simply tapping on their mobile phone and getting a spoken response in the native language. That response can be a series of keywords, or a short description on the object that has been recognized by the camera.

Used technologies

Doing my internship at TMSSoftware, I got access to the newest tools TMS had to offer.
With the TMS FNC Cloud Pack I had the foundation to build a set of classes that implement the services needed to send and receive data via REST. For the GUI, I used FNC. For those not yet familiar with ‘FNC’ , these are what we call Framework Neutral Components. This means that these components can be simultaneously used with different frameworks, are fully cross platform, can be used from Delphi, C++Builder and Lazarus and most spectacularly can be used to create web applications with TMS WEB Core. Read more about FNC for the web here.

TMS FNC Controls can be simultaneously used on these frameworks:

TMS FNC Controls can be simultaneously used on these operating systems/browsers:

TMS FNC Controls can be simultaneously used on these IDE’s:

Because TMS FNC Cloud Pack contains a core layer to handle asynchronous REST request, it became really easy to send and receive data.

Example of translating text via the Google Translate API. In the code below, the TTMSFNCSimpleCloudBase class allows you to quickly send and receive data via REST without OAuth 2.0 authentication flow requirements.

// form class private variables
private
  c: TTMSFNCSimpleCloudBase;
  target : string;

procedure TGoogleTranslateForm.Button1Click(Sender: TObject);
begin
  c.Request.Clear;
  c.Request.Host := 'https://translation.googleapis.com';
  c.Request.Path := '/language/translate/v2';
  c.Request.Query := 'q=' + TTMSFNCUtils.URLEncode(Edit1.Text) +'&format=text'+
   '&target=' + target + '&key=' + c.Authentication.Key;
  c.Request.Method := rmGET;
  c.ExecuteRequest(DoTranslate);
end;

Also parsing the request result data was very easy with TMS FNC Core, which exposes a set of ready to use functions for parsing JSON.

procedure TGoogleTranslateForm.DoGetList(const ARequestResult: TTMSFNCCloudBaseRequestResult);
var
  j, jd, ja, jav: TJSONValue;
  I: Integer;
  siso, sname: string;
  l: TLanguage;
begin
  lst.Clear;
  if ARequestResult.ResultString  ''  then
  begin
    j := TTMSFNCUtils.ParseJSON(ARequestResult.ResultString);
    try
      jd := TTMSFNCUtils.GetJSONValue(j, 'data');
      if Assigned(jd) then
      begin
        ja := TTMSFNCUtils.GetJSONValue(jd, 'languages');
        if Assigned(ja) and (ja is TJSONArray) then
        begin
          for I := 0 to TTMSFNCUtils.GetJSONArraySize (ja as TJSONArray) - 1do
          begin
            jav := TTMSFNCUtils.GetJSONArrayItem(ja as TJSONArray, I);
            if Assigned(jav) then
            begin
              siso := TTMSFNCUtils.GetJSONProp(jav, 'language');
              sname := TTMSFNCUtils.GetJSONProp(jav, 'name');

(Code snippets were written for Google Translate in the first week of the internship)
Here is an example to test the REST API for Google Translate.

Starting on components

After getting used to the different platforms, investigating and testing the various cloud services to be implemented in TMS Vision, I got started on transferring the sample code into components that work cross-platform. Doing the internship here, made this easy as the TMS FNC Cloud Pack already provided a solid base to work on, and additionally my colleagues were eager to lend their advice when I needed help.

Here is an example of how the final code looks with the Google Translate component.

procedure TGoogleTranslateForm.FormCreate(Sender: TObject);
begin
  c := TTMSFNCCloudGoogleTranslate.Create;
  TLanguage := TStringList.Create;
  c.Authentication.Key := 'My-API-Key';
  c.OnIsoLanguageList  := doLanguageList;
  c.GetSupportedLanguageList;
  c.OnTranslate := DoTranslate;
end;

procedure TGoogleTranslateForm.Button1Click(Sender: TObject);
begin
  if FTarget  '' then 
    c.Translate(Edit1.Text, FTarget)
  else 
    c.Translate(Edit1.Text) ;
end;

This shows how compact your final code can be.

TMS Vision

I decided to use the knowledge I collected to make an application that works cross-framework and cross-platform to assist people who are visually impaired. The application allowed them to be informed about the environment around them. There were some critical parts in TMS Vision related to the Google Vision and Microsoft Vision APIs that involved uploading the picture taken from the camera. The data required by Google Vision, for example, needed to be in a base64 string. This was handled by the TTMSFNCUtils.FileToBase64 function included in TMS FNC Core. Below you can see a code snippet that uses this functionality to upload the picture data to Google Vision.

procedure TTMSFNCCustomCloudGoogleVision.AnalysePicture(const AFile: TTMSFNCUtilsFile);
var
 basestring :String;
begin
  try
    basestring := TTMSFNCUtils.FileToBase64(AFile);
    Request.Clear;
    Request.Host := Service.BaseURL;
    Request.Path := '/v1/images:annotate';
    Request.Method := rmPOST;
    Request.AddHeader('Content-Type','application/json; charset=utf-8');
    Request.Query := 'key='+Authentication.Key;
    Request.PostData := '{"requests": [{"image": {"content":"'+      
    basestring+'"}'+',"features": [{"type": "LABEL_DETECTION"},{"type":    
    "OBJECT_LOCALIZATION","maxResults": 5},{"type": "WEB_DETECTION"}]}]}' ;
    ExecuteRequest({$IFDEF LCLWEBLIB}@{$ENDIF}DoRequestAnalyse);
  finally
  end;
end;

Example of how the application looks now. The layout of the app has been created with the TMS FNC UI Pack, and runs on TMS WEB Core. The application is a PWA that is installable on the device.



CONCLUSION

Right now I’m in my second half of my internship and can say I enjoyed every moment of it,
gaining access to the tools of TMSSoftware and the wide variety of FNC components, made programming in Delphi or Pascal a lot easier than I thought.

I’m still expanding my knowledge of Delphi and Object Pascal and I plan to expand the TMS Vision application with other API services such as Google speech to text to remove the need to interact with the screen manually by implementing voice commands.

Author: Brutin Bjorn

Read More

Read More

Rad Studio 10.3.1 GetExceptionSeverity error

My application worked fine with RAD Studio 10.3, but after I upgraded to the 10.3.1 update, I receive the error message `GetExceptionSeverity - not found` I have searched for information about that message in RAD Studio & Firemonkey Help System and also in the Web, but found nothing on this issue. My machine configuration: AMD Athlon II X2 Processor 8 GB installed memory 64 bits OS Windows 10 Pro Does anybody know what causes this kind of error and how to fix it?
Read More

how to know if one of my childs get some mouse events?

If I m a custom Tcontrol and I want to know if one of my childs (or childs of my childs, etc..) get some mouse events (like mouseDown, MouseUp, MouseMove, etc..) How I can do under Firemonkey? I think it's impossible (except playing with CMGesture but this is different "flow" than the one used by mouseDown, MouseUp, MouseMove, etc) In a nutshell is there any mechanism to propagate mouse events in firemonkey ?
Read More

Delphi 10.3 RIO ImageList causes crash on Android 5.1.1

I recently moved from Delphi Berlin to Delphi Rio since I need the new Android stuff. Trough trial and error I figured out that the ImageList I have in my DataModule is causing a problem - It starts and stays at the Splash Screen. I've created a new Multi-Device application without anything, put a SpeedButton (SB_BTN1) and a ImageList on the main form. Loaded a small BMP image to the ImageList and attached it to the SpeedButton (SB_BTN1) - which causes for it to stay on the splash screen and not load. BUT if I add another SpeedButton (SB_BTN2) - and set (SB_BTN1) invisible, and on the (SB_BTN2) - code I add that it makes the (SB_BTN1) visible, the form gets past the loading screen and everything works. I aswell have attached it to Logcat to see what it says - to no success, it doesn't show any error. My Andrid SDK API Level is 26 and NDK Level is 14 -- If this helps in any way EDIT: Forgot to mention, that the sample: "ImageListDemo" also does this. EDIT-2: So I aswell tried to do a fresh install - I reseted my whole pc, and I upgraded from 10.3 to 10.3.1 - still the same problem.
Read More