1 / 16

FireMonkey - Torry's Delphi Developers

Several last versions allow Firemonkey to use View technology, where user can define exact look of the app on various resolutions (we define Master and customize it then). Working with Master only will be enough for us because application adapts itself and detailed resolution settings won't be necessary.

Download Presentation

FireMonkey - Torry's Delphi Developers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FiremonkeyMobile Application for Android How to create simple mobile application for Android using Delphi in few minutes (Apple device) PUBLISHED By : Torry.net

  2. All the development will be carried out on Windows platform as a 32bit application, only the result will be adapted for target device or platform. Our application allows to enter ID and returns business record for given company (business name, address and more) in JSON format – result will be processed and displayed within an application. Prerequisities : Delphi with Mobile development an Android device on which USB debugging is enabled

  3. Let's Start : In first step, create a new application, i.e. select Multi Device Application and Header/Footer layout. As soon as first step is done, save basic app anywhere you like.

  4. Several last versions allow Firemonkey to use View technology, where user can define exact look of the app on various resolutions (we define Master and customize it then). Working with Master only will be enough for us because application adapts itself and detailed resolution settings won't be necessary.

  5. View options – Master Enoughs Now is pretty important to set Layout – it means assure app to customize target device in case if layout for various resolutions is not set. We can choose among many Layout options (you can imagine as a panel with certain behavior), but let's use TListBox component (another reasonable option is MultiView or TListView).

  6. To be frank, do forget VCL based TListBox, this is strongly different solution. Each Item within the list can be a component with type at pleasure, with different style, and can contain further miscellaneous components. ListBox in action Choose ListBox and place it onto the Form with setting Align=alClient. Titles Now we will insert particular items which will represent a cornerstone of our user interface. Starting with title (I've already inserted it there).

  7. In the next step add an Item on ListBox through context menu: and set desired style: Finally, type title text.

  8. Items Intended look is depicted below: So we insert TListBoxItem ten times and set Style if necessary. Edit field is common TEdit but with special style and Align set to alCenter (however, you can use any other align method).

  9. How do we create delete key for TEdit? Simply click at TEdit and add TClearEditButton by means of context menu, that's all. Please observe tree structure regarding TEdit. FireMonkey allows to combine components as you like and as you need. Styles what are able to "do miracles" are additional value too. Well, we've created basic user interface. This UI will be adapted according to target platform while compiling.

  10. Main Programme At this moment, we can compile application for target platform, i.e. for Windows, iOS, Mac OSX or Android. I strictly recommend to develop completely using Windows target and tune up e.g. for Android – it's more comfortable regarding speed of compiling and deployment. You can see I wrote no-one line of code until now and we'll fix it just now. How it will work? We are about to use certain Czech local webservice that can return business information for given company (based on its ID, so called IČO) in JSON format. So we simply create URL, download data using THTTPClient Delphi component and parse and display returned data by means of multiplatform System.JSON.

  11. Code for Button uses// Windows,System.Net.httpclient,System.JSON;{$R *.fmx} procedure THeaderFooterForm.Button1Click(Sender: TObject);varoClient: THTTPClient;oStream: TStringStream;iStatus: Integer;sResponse: string;oJsonValue: TJSONValue;s: string;o: TObject;constciLen = length('ico_back('); // odpovedobsahujekus JSbeginoClient := THTTPClient.Create;oStream := TStringStream.Create;try Next page

  12. // pro ladeniiStatus := oClient.Get('http://data.fin.cz/json/subject/45274649.js', oStream, nil).StatusCode;// iStatus := oClient.Get('http://data.fin.cz/json/subject/'+edtICO.Text+'.js', oStream, nil).StatusCode;iStatus := iStatus div 200;if iStatus <> 1 thenbeginedtName.Text := 'Error:'+iStatus.ToString;Exit;end;sResponse := oStream.DataString.Substring(ciLen);sResponse := sResponse.Remove(Length(sResponse) - 1);finallyoStream.DisposeOf; // ignoruj ARC oClient.DisposeOf;end;(*'ico_back({id:''25247484'',count:1,name:''AB - AKCIMA, s.r.o.'',url:''http://rejstrik-firem.kurzy.cz/25247484/ab-akcima-sro/'',addr_main:{city:''Cheb'',citypart:''Cheb'',street:''Havl\u00ED\u010Dkova 1803/2'',zip:''35002'',no:''1803/2'',code:{city:''554481'',district:''CZ0411''}},vat:{id:''CZ25247484''},date:{start:''2000-08-03'',last:''2014-09-01'',end:null}})'*)sResponse := NormaliseJSON(sResponse);// Windows.MessageBox(0, Pchar(sResponse), nil, 0);oJsonValue := TJSONObject.parseJSONValue(sResponse);if oJsonValue is TJSONObject thenbegins := TJSONObject(oJsonValue).Values['id'].Value;edtName.Text := TJSONObject(oJsonValue).Values['name'].Value;o := TJSONObject(oJsonValue).Values['addr_main'];if o is TJSONObject thenbeginedtAdr1.Text := TJSONObject(o).Values['street'].Value;edtAdr2.Text := TJSONObject(o).Values['citypart'].Value;edtPost.Text := TJSONObject(o).Values['zip'].Value;end;end; Next page

  13. First part of code downloads JSON, second one goes through and returns requested information. It's straightforward except NormaliseJSON which partially edits returned JSON. function THeaderFooterForm.NormaliseJSON(const s: string): string;varc: char;bInQuote: Boolean;beginResult := '';bInQuote := False;for c in s dobeginif c = '''' thenbeginbInQuote := not bInQuote;Result := Result + '"';continue;end;if bInQuote thenResult := Result + celseif CharInSet(c, ['{', ',']) thenResult := Result + c+ '"'elseif CharInSet(c, [':']) thenResult := Result + '"'+celseResult := Result + cend;Result := Result + '';end; Try it out for Windows, translate for Android and we've done.

  14. Notes Be aware of zero-terminated strings in mobile applications – if you do not want to use switch which turns it off, simply remember that all the functions called by String.xxxx start from zero.

  15. Size of Application Remove all unnecessary parts from your app via the Project Manager. Final application compile as a Release, package size is in my case 6 119 782 bytes. It should have been video tutorial initially but it wouldn't be good. In addition, I like rather textual instruction so I'm sorry for that :-)

  16. Contact Information Address : Prostějovičky79  79803, PLUMLOV  (District Prostějov, Olomouc region)  Telephone: 731 616 511 Mobile: 731616511 Email:yamaco@yamaco.czWeb: Torry.net Thank You… Visit Again My Page…

More Related