News, Blogs, and Tips

Cross JIRA Analysis with FireDAC CDATA JIRA Connector

Marco Cantu - Fri, 11/24/2017 - 08:06

In Embarcadero, for the RAD Studio project, we have two JIRA systems. One is a public system better known as Quality Portal (https://quality.embarcadero.com), while the second is an internal JIRA system accessible only behind the firewall. The two systems are kept in sync, as I explained in the past, so that a bug opened in the public system is reflected in the internal one; as we close a bug in the internal system and ship the fix, the internal status is reflected in the public system.

Almost always. In fact, there are reasons (timing, specific configurations, unexpected workflows, timeouts during synch operations, scripts that get stuck...) that prevent the regular flow to happen, leaving bugs in an inconsistent state. Specifically, we often have bugs closed internally that remain open (indefinitely) in the public system. I've spent time in the past looking for these orphaned items, but it is a fairly tedous process. So I though of writing an application to automate this. I could have used JIRA own scripting, but the process needs manual overview, which makes it more complex. So why not use Delphi?

Using the CData JIRA Enteprise Connector to run a query against JIRA and storing the data in a dataset takes literally a few minutes. You can use FireDAC query editor to refine your query, and write fairly standard Delphi dataset processing code. This blog post is a description of what I did to achieve my goal -- and the application I build it going to save me a lot of time in the future.

First, I've added to a data module (of a good old VCL application) the components needed to access quality portal and query for all of the open issues:

object QualityportalConnection: TFDConnection Params.Strings = ( 'URL=http://quality.embarcadero.com' 'ConnectionDef=QualityPortal' 'IncludeCustomFields=true') LoginPrompt = False end object QPIssuesTable: TFDQuery Connection = QualityportalConnection SQL.Strings = ( 'SELECT Key, StatusName, IssueTypeName, Summary, InternalID FROM ' + 'CData.JIRA.Issues where ProjectKey = '#39'RSP'#39' AND StatusName = '#39'Open'#39) end

The connection uses the IncludeCustomFields flag to retrieve extra custom fields of our JIRA installation, namely the cross reference from one JIRA system to the other, stored in the InternalID field -- and something a regular user without admin permissions should not be able to see. In fact, you need to provide your user name and password, the regular ones you use on the site.

For query I've picked the fields I'm interested in, to reduce network traffic (I'm reading a lot of data!) and filtered on RSP (Data Studio Project) and Open status. You can see the query running in FireDAC query editor below:

I also created static field objects for all fields in the query. For the internal JIRA analysis I've defined a query to retrieve information about an individual item, using a parametric query (like in SQL):

SELECT Key, StatusName, FixVersionsAggregate, StatusName, ResolutionName FROM CData.JIRA.Issues where Key = :key

With this query I'm retrieving the status, the type of resolution and the fix version. The basic approach of the application is to iterate all of the items open in the public system, fetch the internal status and check for inconsistencies. This is the basic loop:

QPIssuesTable.Open; // for each, check internal status QPIssuesTable.First; while not QPIssuesTable.EOF do begin JiraIssuesTable.Close; JiraIssuesTable.Params[0].AsString := QPIssuesTableInternalID.AsString; JiraIssuesTable.Open; // consider only issues closed internally if (JiraIssuesTableStatusName.AsString = 'Closed') then begin   ...     end;     QPIssuesTable.Next; end;

There is another part of the code I'm omitting to examine the fixVersion, which is a string with same complex JSON structure (an array of records). I need to extract the version number to see if the issue was closed in the past or it has just been closed for a not-yet-released version (in which case, it is fine). For all of the matches (issues closed in released versions) I add them to an FDMemTable created with appropriate fields and connected to a DBGrid:

      begin         FDMemTable1.Insert;         FDMemTable1QPKey.AsString := QPIssuesTableKey.AsString;         FDMemTable1JiraKey.AsString := JiraIssuesTableKey.AsString;         FDMemTable1QPStatus.AsString := QPIssuesTableStatusName.AsString;         FDMemTable1JIRAStatus.AsString := JiraIssuesTableStatusName.AsString;         FDMemTable1IssueType.AsString := QPIssuesTableIssueTypeName.AsString;         FDMemTable1Resolution.AsString := JiraIssuesTableResolutionName.AsString;         FDMemTable1Summary.AsString := QPIssuesTableSummary.AsString;         FDMemTable1FixVersions.AsString := fixJSONString;         FDMemTable1.Post;       end;

With this code, I obtain a grid with all items most likely out of synch, as displayed below, which lists the two IDs, the status on both systems, the internal resolution, and the version is was fixed:

The version number are internal ones, but I imagine you can guess which public version they match to. With the help of the data in this grid, I can go over the issues, open them in the internal system (if in doubt), and decide what to do. If I want to synchronize them, I need to add them to a list in the format expected by a JIRA script we use to force the synchronization. By double clicking on the grid, I execute the trivial code below that creates the comma separated list of keys I need:

procedure TForm14.DBGrid1DblClick(Sender: TObject); begin Edit1.Text := Edit1.Text + ', ' + DataModule15.FDMemTable1JiraKey.AsString; end;

So much less copy and paste! And now I can use the next couple of days to cleanup the Quality Portal system a bit...

Categories: News, Blogs, and Tips

New on Embarcadero Academy: CodeRage Replays and my New Course and Bundle

Marco Cantu - Mon, 11/20/2017 - 08:10

Embarcadero Academy is an independent online training site available at https://www.embarcaderoacademy.com/. The site has an overall agreement with Embarcadero as a key destination for online training for the company development tools products.

The academy site co-hosted the CodeRage XII conference the other week and it is not offering the complete set of replays. All you need to do is create an account on the platform and sign up for the free CodeRage course at https://www.embarcaderoacademy.com/p/coderage-xii.

On my part, I added a new course on Anonymous Methods and a course bundle on Modern Delphi Language including the courses on interfaces, generics, and anonymous methods. This bundle includes 6 hours of content. Also, all of the courses have a 20% special CodeRage discount until the end of November.

There are many other great classes on Delphi by Alister and non-Delphi classes as well. It is also now possible to take the Delphi certification exams on the academy site. There are other ideas floating around to improve the academy, like live online classes and subscriptions: more than willing to get your feedback (that I can share with the academy site team) or suggestions to me for other topics to cover in future additional courses.

Categories: News, Blogs, and Tips

Explaining Tasks in Delphi Parallel Library... by Creating too Many Tasks

Marco Cantu - Thu, 11/16/2017 - 09:19

Recently, I wrote some new demo for Delphi PPL (Parallel Programming Library), while doing some research for an online class -- which is available since last week on the Embarcadero Academy site ("Anonymous Methods in Delphi"), along with a new overall bundle of my classes ("Master Modern Delphi Language Techniques").

In the past I've used different ways to explain tasks and compare them to threads. Tasks are lightweight and managed more efficiently, than threads. The PPL creates a thread pool and assigns pending tasks (and their code) to a pool of threads that depends on your CPU cores and current workload. But these descriptions might still explain tasks and threads as fairly similar in scope. Now let's look at this source code snippet:

procedure TForm12.btn100sClick(Sender: TObject); var tasks: array of ITask; Value: Integer; I: Integer; begin SetLength(tasks, 100000); Value := 0; for I := Low (tasks) to High (tasks) do begin tasks[I] := TTask.Create (procedure () begin TInterlocked.Increment (Value); end); tasks[I].Start; end; TTask.WaitForAll (tasks); Memo1.Lines.Add(Value.ToString); end;

As you can see this event handler creates not hundred, but hundred thousand tasks. Each of them has an extremely simple operation to complete -- fairly nonsensical, I know. But you can create 100,000 tasks and they'll all done done in less than a second, on my computer. Consider creating 100,000 threads! that would create a significant extra overhead. By running this code, the tasks are assigned to a few threads in a pool, as you can see in the debugger:

Small demo and pretty much useless code, but I think it does a good job in highlighting the lightweight and flexible nature of nature of tasks, when compared to threads.

Categories: News, Blogs, and Tips

CodeRage XII Starts Today (With European Schedule)

Marco Cantu - Tue, 11/07/2017 - 02:34

The online CodeRage conference by Embarcadero starts today: https://community.embarcadero.com/article/16578-coderage. Registration is still oepn at https://register.gotowebinar.com/register/7990350396754529539.

With dozens of session based on central US time zones, it is easy to get confised. So I've amended the official calendar for those based in Europe (warning, in case of last minute schedule changes, I won't probably be able to udpate it). Here are thre three PDFs for the 3 days with UTC+1 or Central Europe Time zone times:

Tuesday Nov 7thhttp://blog.marcocantu.com/images/forblog/CodeRageXIIScheduleEuropeTueNov7.pdf

Wednesday Nov 8thhttp://blog.marcocantu.com/images/forblog/CodeRageXIIScheduleEuropeWedNov8.pdf

Thursday Nov. 9thhttp://blog.marcocantu.com/images/forblog/CodeRageXIIScheduleEuropeThuNov9.pdf

Remember you can sign-up and follow the event also on the Embarcadero Academy site at https://www.embarcaderoacademy.com/

I'll be "live tweeting" any even vaguely Delphi-related CodeRage information https://twitter.com/delphitweetday. Follow the account if you don't do already!

Categories: News, Blogs, and Tips

CodeRage XII is Next Week

Marco Cantu - Fri, 11/03/2017 - 02:05

Next week, from Tuesday November 7th to Thursday November 9th will see the 12th edition of Embarcadero's yearly online conference, called "CodeRage" since the CodeGear days. This event goes beyond all other webinars and sessions, in scope, breadth and focus, and is really an online multi-day event. While most sessions will be available afterwards, I really recommend you to plan attending live and get involved into the Q&A and discussion and social media conversations around the conference. Reserve your time and don't be shy asking your boss some free time to attend the conference -- it will be so much cheaper than going to a real one!

You can see the temporary program at:  https://community.embarcadero.com/blogs/entry/coderage-xii-sessions-and-schedule

I won't comment on all of the sessions, but I'm going to mention a few highlight and list mine:

  • Two guess industry luminaries will be giving sessions, Robert Martin (aka Uncle Bob) is speaking on "The Clean Coder - An Introduction to Software Professionalism" and Steven McConnell (of "Code Complete" fame) is speaking on "Managing Technical Debt".
  • RAD Studio product address by the PM team (Sarina, David, and myself) in which we will provide hints (and screenshots) of new features to come in RAD Studio 10.2.2 -- Tuesday 9AM Central US Time or 4PM in Central Europe.
  • Many sessions by well-known Delphi gurus including Ray Konopka (he'll also provide some interesting previews), Cary Jensen, Brian Long, Bob Swart, Danny Wind, Olaf Monien.... and many many others
  • Sessions by most Embarcadero SC at all latitudes, covering many ways to use RAD Studio
  • Detailed covered of many third party tools (including FMX Linux, Arduino integration, reporting, DB tools, UI controls and libraries, code migration, and much much more)
  • Technical sessions by the PM team (David, Sarina, myself, and Sandeep for Sencha). Specifically, I'm giving a session titled "Introduction to Ext JS for Delphi Developers" in which I'll provide some initial information on Ext JS and the use of the Sencha Architect IDE for building the front end of a RAD Server web service -- Tuesday 11AM Central US Time or 6PM in Central Europe.

Finally notice that this year the online conference will be hosted both on GoToWebinar and on Embarcadero Academy at https://www.embarcaderoacademy.com/p/coderage-xii, where you can already sign up and see the detailed schedule.

Categories: News, Blogs, and Tips

Technical the same but different generated code

Andy’s Blog and Tools - Tue, 10/31/2017 - 02:12

While debugging the String4D code to hunt down a bug in the CompilerSpeedPack, I saw a lot of CopyRecord/FinalizeRecord calls with a try/finally that the compiler generated.

If you have a record with managed fields (string, interface, …) and use it as a function return type the Delphi compiler will change the function into a procedure with an extra var-parameter. So you would think that the compiler treats the result-parameter like a normal var-parameter, but that isn’t the case. The compiler will generate code that guarantees that the result record isn’t changed if the called function throws an exception. For this is adds a temporary record that is used for the function result and then copies it to the target record.

type TMyRec = record Value: string; end; function InternalGetRec: TMyRec; begin Result.Value := 'Hello'; end; function GetRec: TMyRec; begin Result := InternalGetRec; end; procedure Test; var R: TMyRec; begin R := GetRec; end;

The compiler rewrites the “Test” function to:

procedure Test; var R, TempR: TMyRec; begin try GetRec(TempR); CopyRecord(TempR, R, TypeInfo(TMyRec)); finally FinalizeArray([TempR, R], TypeInfo(TMyRec)); end; end;

The same happens if you assign another function’s record result value to your own record result value. The compiler rewrites the “GetRec” function’s code to:

function GetRec: TMyRec; var TempResult: TMyRec; begin try InternalGetRec(TempResult); CopyRecord(TempResult, Result, TypeInfo(TMyRec)); finally FinalizeRecord(TempRecord, TypeInfo(TMyRec)); end; end;

Because the compiler assumes that you may want to use “Result” in the function after the call, it has to guarantee that it is unchanged if an exception is thrown. But if it is the last statement in the function and not secured by an explicit try/finally/except where “Result” is used again, an optimization could be to omit the temporary record, making the code a lot faster.

Categories: News, Blogs, and Tips

IDE Fix Pack 6.1 released

Andy’s Blog and Tools - Sun, 10/29/2017 - 09:36

With the release of IDE Fix Pack 6.1, the Compiler Speed Pack not only makes the compiler compile faster but it can now also change the generated code, something that IDE Fix Pack has never done before. For this, new command line compiler options are introduced. They all start with “-x” (eXtension) followed by the Compiler Speed Pack option (-x-ff -x-fdi -x-fvs -x-fpr) and if you want to use them from the command line compiler you need to use fastdcc32/fastdcc64.
You can specify these options in the “Project/Options…” dialog under “Delphi Compiler/Compiling/Additional options to pass to the compiler”. You may need to rebuild the project to see an effect as only then the compiler will generate new code.

Windows 10 Creators Update 1703 caused issues with all Delphi programs, libraries and packages because it changed how Windows loads imported DLLs in such a way that it causes performance issues and can crash the debugger. Delphi 10.2 Tokyo Update 2 fixed this by not producing multiple dll import sections for one DLL anymore. IDE Fix Pack 6.1 implements that “feature” for all previous Delphi versions (2009-10.1 Berlin) and extends it to not only eliminate duplicate dll imports but also duplicate delay dll imports.
This patch changes the generated binary, the Win32 and Win64 compiler outputs, and it can be disabled by using the new “-x-fdi-“ option.

The next patch that changes the Win32 code generator is the “fast floating point” option that C++Builder users may know from the “bcc32.exe -ff” option. It removes all “fwait” instructions that the compiler usually emits after floating point operations. Removing “fwait” may cause FPU exceptions to be thrown at the wrong source code line.
This option is disabled by default and can be enabled by specifying the new option “-x-ff”.

When calling virtual methods through an interface the Win32 Delphi compiler has to route that call through a helper function that translates the interface reference into an object reference and calls the virtual method. For this helper the compiler uses the XCHG instruction that has an implicit CPU LOCK.
The new “-x-fvs” / “-x-fvs=1” option replaces the XCHG instruction with an alternative code and if the called virtual function doesn’t use the ECX register for the 3rd parameter, it generates a direct jump into the virtual method.
The “-x-fvs=2” option replaces the XCHG and uses ECX if available but if ECX is not available it keeps the CPU’s “return stack cache” valid by replacing the RET with a JMP instructions. For this it uses stack memory below ESP.

For some functions that meet special conditions the Win32 compiler emits stack frame code that fills the stack with zeros to clear variables with managed types. If there are too many of those the compiler uses a loop and the XCHG instruction to restore the ECX register that is used as the loop counter.
The option “-x-fpr” replaces the XCHG with an alternative code.

 

Changelog:

  • Added: Option -x-ff to enable “fast floating point” (like Borland C++’s -ff command line option)
  • Added: Option -x-fvs and -x-fvs=n to enable fast interface virtual stub (n=1: replace XCHG, n=2: keep the CPU’s return stack buffer in order)
  • Added: Option -x-fpr to remove XCHG from the function prolog code.
  • Added: DLL import table section folding and duplicate name/ordinal elimination, also for delay dll imports
  • Changed: Split “Compiler64.X86″ patch into multiple smaller patches and removed the “Compiler64.X86” patch name
  • Changed: EditorFocusFix now skips the SetActiveWindow call if the mainform (undocked) is not the active window

Download:

Name IDE Version File Size Downloads Added IDE Fix Pack 6.1.1 2009 (UP4) IDEFixPack2009Reg61.1.7z 188.6 KB 34 times 2017-10-30 IDE Fix Pack 6.1.1 2010 (UP5) IDEFixPack2010Reg61.1.7z 185.1 KB 42 times 2017-10-30 IDE Fix Pack 6.1.1 XE (UP1) IDEFixPackXEReg61.1.7z 172.72 KB 41 times 2017-10-30 IDE Fix Pack 6.1.1 XE2 (UP4+HF1) IDEFixPackXE2Reg61.1.7z 257.66 KB 33 times 2017-10-30 IDE Fix Pack 6.1.1 XE3 (UP2) IDEFixPackXE3Reg61.1.7z 211.76 KB 21 times 2017-10-30 IDE Fix Pack 6.1.1 XE4 (UP1) IDEFixPackXE4Reg61.1.7z 214.83 KB 16 times 2017-10-30 IDE Fix Pack 6.1.1 XE5 (UP2) IDEFixPackXE5Reg61.1.7z 211.58 KB 19 times 2017-10-30 IDE Fix Pack 6.1.1 XE6 (UP1) IDEFixPackXE6Reg61.1.7z 371.44 KB 14 times 2017-10-30 IDE Fix Pack 6.1.1 XE7 (UP1) IDEFixPackXE7Reg61.1.7z 387.64 KB 44 times 2017-10-30 IDE Fix Pack 6.1.1 XE8 (UP1) IDEFixPackXE8Reg61.1.7z 385.29 KB 25 times 2017-10-30 IDE Fix Pack 6.1.1 10 Seattle (RTM/UP1) IDEFixPackD10Reg61.1.7z 393.88 KB 64 times 2017-10-30 IDE Fix Pack 6.1.1 10.1 Berlin IDEFixPackD101Reg61.1.7z 391.56 KB 87 times 2017-10-30 IDE Fix Pack 6.1.1 10.2 (RTM/UP1) IDEFixPackD102Reg61.1.7z 392.96 KB 177 times 2017-10-30

Download (fastdcc):

Name IDE Version File Size Downloads Added fastdcc 6.1.1 2009 (UP4) fastdcc2009v61.1.7z 82.74 KB 11 times 2017-10-30 fastdcc 6.1.1 2010 (UP5) fastdcc2010v61.1.7z 90.04 KB 13 times 2017-10-30 fastdcc 6.1.1 XE (UP1) fastdccXEv61.1.7z 91.83 KB 13 times 2017-10-30 fastdcc 6.1.1 XE2 (UP4+HF1) fastdccXE2v61.1.7z 129.47 KB 19 times 2017-10-30 fastdcc 6.1.1 XE3 (UP2) fastdccXE3v61.1.7z 137.35 KB 8 times 2017-10-30 fastdcc 6.1.1 XE4 (UP1) fastdccXE4v61.1.7z 140.06 KB 8 times 2017-10-30 fastdcc 6.1.1 XE5 (UP2) fastdccXE5v61.1.7z 139.37 KB 9 times 2017-10-30 fastdcc 6.1.1 XE6 (UP1) fastdccXE6v61.1.7z 186.19 KB 7 times 2017-10-30 fastdcc 6.1.1 XE7 (UP1) fastdccXE7v61.1.7z 200.05 KB 16 times 2017-10-30 fastdcc 6.1.1 XE8 (UP1) fastdccXE8v61.1.7z 199.91 KB 12 times 2017-10-30 fastdcc 6.1.1 10 Seattle (RTM/UP1) fastdccD10v61.1.7z 200.27 KB 27 times 2017-10-30 fastdcc 6.1.1 10.1 Berlin fastdccD101v61.1.7z 199.99 KB 40 times 2017-10-30 fastdcc 6.1.1 10.2 (RTM/UP1) fastdccD102v61.1.7z 200.58 KB 62 times 2017-10-30
Categories: News, Blogs, and Tips

Delphi Blogs of the Month #56

Marco Cantu - Fri, 10/27/2017 - 07:59

While clearly difficult to have a weekly summary, Iv'e fully retitled this installment, although the URL stays as part of the original weekly sequence. Let's get started.

Embarcadero News

A Busy Summer at https://community.embarcadero.com/article/16572-a-busy-summer

Embarcadero Academy Debuts with Online Courses for Developers of All Levels press release at http://www.businesswire.com/news/home/20170918005798/en/Embarcadero-Academy-Debuts-Online-Courses-Developers-Levels

New in 10.2.1: Debug visualisers for Delphi generics at https://community.embarcadero.com/blogs/entry/new-in-10-2-1-debug-visualisers-for-delphi-generics

Build iOS 11 ready apps with RAD Studio 10.2.1 at https://community.embarcadero.com/blogs/entry/build-ios-11-ready-apps-with-rad-studio-10-2-1

Updating IDE Subversion DLLs to address security issues at https://community.embarcadero.com/blogs/entry/updating-ide-subversion-dlls-to-address-security-issues

Blog Posts

Working with big data databases in Delphi - Cassandra, Couchbase and MongoDB (Part 3 of 3) at https://blog.grijjy.com/2017/09/21/working-with-big-data-databases-in-delphi-cassandra-couchbase-and-mongodb-part-3-of-3/

Debugging RTL/VCL Code with CodeSite at http://www.davidghoyle.co.uk/WordPress/?p=1754 and the follow up ,Notify Me of Everything - Part 2, at http://www.davidghoyle.co.uk/WordPress/?p=1761

5 Minute Snack: Reading floats with StrToFloat and TFormatSettings independent of system region settings at https://flixengineering.com/archives/612

Easily Make Asynchronous REST Calls In Delphi 10.2.1 Tokyo On Android, iOS, macOS, and Windows 10 at https://community.embarcadero.com/blogs/entry/easily-make-asynchronous-rest-calls-in-delphi-10-2-1-tokyo-on-android-ios-macos-and-windows-10

Face Detection on Android and iOS at https://blog.grijjy.com/2017/09/11/face-detection-on-android-and-ios/

Experimenting with Neural Networks - Part 1 (and following in subsequent posts) - http://chapmanworld.com/2017/09/20/experimenting-with-neural-networks-part-1/

Adding a Custom Icon to a FireMonkey Button at https://community.embarcadero.com/blogs/entry/adding-a-custom-icon-to-a-firemonkey-button

RAD Studio 10.2: Windows 10 VCL UWP/WinRT Support at https://community.embarcadero.com/blogs/entry/rad-studio-10-2-windows-10-vcl-uwp-winrt-support

Amazon DynamoDB with Delphi (video) at https://community.embarcadero.com/blogs/entry/amazon-dynamodb-with-delphi

5 Minute Snack: Is a package installed? The Package Manager icons tell you! https://flixengineering.com/archives/618

Third Party Libraries

TLanguage localization tool: https://delphitipsandtrick.blogspot.it/2017/10/delphi-tlanguage-localizaton-tool.html

Not new but fairly interesting.... Python for Delphi at https://github.com/pyscripter/python4delphi and you can read about it at http://www.atug.com/andypatterns/pythonDelphiTalk.htm

Delphi RNL ("Realtime Network Library") at https://github.com/BeRo1985/rnl

Use this RFID library in Delphi at https://github.com/islog/liblogicalaccess/wiki/Use-this-RFID-library-in-Delphi

Built with Delphi

Roselt Color Picker in Windows Store: https://www.microsoft.com/en-za/store/p/roselt-color-picker/9nq8c70flp0r?rtc=1

Smart IDE for OpenSCAD at https://github.com/senCille/senCilleSCAD/wiki

 

That's all for this month.

Categories: News, Blogs, and Tips

Implementing AJAX and JSONP Support in RAD Server for ExtJS

Marco Cantu - Thu, 10/19/2017 - 06:36

Idera recently acquired Sencha (https://www.sencha.com/) and has added the company products to the Embarcadero business unit, which produced RAD Studio and also the RAD Server web service technology. A natural question arises on how to use the two products together. While there are several options, in this blog post I want to highlight the simple and direct integration of RAD Server and FireDAC with an ExtJS client based on Sencha’s data model architecture. Most of the considerations in this blog post would equally apply to using WebBroker or DataSnap to build the web service..

A Simple Test

As first step, I’ve created a simple blank RAD Server application. What this does is to expose standard REST endpoints like “version”. In an ExtJS client build with the Architect IDE, I’ve added a button, picked the Tap event, and written code like the following:

onButtonTap: function(button, e, eOpts) { Ext.Ajax.request({ url: 'http://192.168.1.102::8080/version', cors: true, success: function(response, opts) { var obj = Ext.decode(response.responseText); console.dir(obj); button.setText (obj.server); }, }); }

What this code does is make a call to the version REST API, create a JavaScript object with the resulting JSON (decode), display the data on the browser console, and display the server field as button text.

Defining a Data Model

This just proves that the JavaScript application can invoke RAD Server. Next I moved to the data processing. ExtJS has the concept of a data model, so using the visual tool I created a simple one like the following:

Ext.define('MyEmployeeApp.model.EmployeeData', { extend: 'Ext.data.Model', requires: [ 'Ext.data.field.Field' ], fields: [ { name: 'first_name' }, { name: 'last_name' }, { name: 'phone_ext' }, { name: 'dept_no' }, { name: 'job_country' } ] }); Returning JSON from RAD Server

Next, I had to define a data store. First I used an AJAX data store and to keep things simple I wrote a custom method in RAD Server to expose a plain JSON data structure, built using the TJSONObject and TJSONArray classes. In this code EmployeeTable is a TFDQuery dropped in the data module along with a connection to the classic InterBase employee demo database:

procedure TEmployeeDataResource1.Get(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse); var empDataObj: TJSONObject; data: TDataSet; emplArray: TJSONArray; emplObj: TJSONObject; aField: TField; begin data := EmployeeTable; data.Open; empDataObj := TJSONObject.Create; emplArray := TJSONArray.Create; while (not data.EOF) do begin emplObj := TJSONObject.Create; for aField in data.Fields do begin emplObj.AddPair(LowerCase(aField.FieldName), aField.AsString); end; emplArray.Add(emplObj); data.Next; end; empDataObj.AddPair ('employee', emplArray); AResponse.Body.SetValue(empDataObj, True); end;

This is the resulting JSON in a browser:

With this code and the use of an AJAX call, the JavaScript application by default ends up with with cross-server invocation security problems, when executed in the browser. There is  however a fairly simple solution in RAD Server, which is set a single line in the EMS.INI file, with a configuration like:

[Server.APICrossDomain] ;# Write here the domains allowed to call the API. Used for Cross-Domains CrossDomain=*

This is fairly over-permissive, in production you’d want to indicate a specific domain rather than *. With this setting and possibly even some proxy configuration in your web server,  you can handle the cross-domain resource access.

Implementing JSONP in RAD Server

The alternative options (a little older and considered less secure) is to implement a JSONP server. You can read the documentation here: http://docs.sencha.com/extjs/6.5.2/modern/src/JsonP.js-1.html.

In short, rather than returning JSON data, a JSONP call returns the JavaScript source code of a function that includes the JSON text as a parameter. The name of the function to call is passed in a parameter named “callback” in a regular GET HTTP call. A common implementation is to check for that parameter and return JSONP (that is, JavaScript) in the specific case, JSON if the parameter is not present. It actually takes less time to read the code than the description. In the code above, the last line becomes:

var callBackParam: string; strStream: TStringStream; begin ... // check for JSONP request if ARequest.Params.TryGetValue ('callback', callBackParam) then begin strStream := TStringStream.Create ( callBackParam + '(' + empDataObj.ToString + ');'); AResponse.Body.SetStream(strStream, 'text/javascript', True); end else AResponse.Body.SetValue(empDataObj, True); end; Defining Storage in ExtJS

Now that we have a proper source of either JSON or JSONP data (both work at the same URL), we can define a data storage for them in ExtJS. Again, using Architect this can be done by setting a few properties, and here is the resulting code for AJAX:

Ext.define('MyApp.store.MyJsonStore', { extend: 'Ext.data.Store', requires: [ 'MyApp.model.MyModel', 'Ext.data.proxy.Ajax', 'Ext.data.reader.Json' ], constructor: function(cfg) { var me = this; cfg = cfg || {}; me.callParent([Ext.apply({ storeId: 'MyJsonStore', autoLoad: true, model: 'MyApp.model.EmployeeData', proxy: { type: 'ajax', url: 'http://192.168.1.102:8080/EmployeeData/', reader: { type: 'json', rootProperty: 'employee' } } }, cfg)]); } });

The rootProperty is the name of the core JSON object, under which there is the actual data. It could be a more complex and nested sequence. With this configuration, you can use the Architect IDE to load the data and preview it:

The configuration of a JSONP data store is very similar, as listed below:

Ext.define('MyEmployeeApp.store.MyJsonPStore', { extend: 'Ext.data.Store', requires: [ 'MyEmployeeApp.model.EmployeeData', 'Ext.data.proxy.JsonP', 'Ext.data.reader.Json' ], constructor: function(cfg) { var me = this; cfg = cfg || {}; me.callParent([Ext.apply({ storeId: 'MyJsonPStore', model: 'MyEmployeeApp.model.EmployeeData', proxy: { type: 'jsonp', url: 'http://192.168.1.102:8080/EmployeeData/', reader: { type: 'json', rootProperty: 'employee' } } }, cfg)]); } }); An EXtJS Grid for the UI

Now that we have a model and a data store (or actually two), we can wire up the user interface. For this simple case, I’ve just added a grid to the UI, added 5 columns to it, and tied each column to each field in the data model:

{ xtype: 'grid', height: '100%', width: '100%', store: 'MyJsonPStore', columns: [ { xtype: 'gridcolumn', width: 70, dataIndex: 'first_name', text: 'First Name' }, { xtype: 'gridcolumn', width: 80, dataIndex: 'last_name', text: 'Last Name' }, { xtype: 'gridcolumn', width: 80, dataIndex: 'phone_ext', text: 'Phone' }, ....

With this configuration, you can preview your grid at design time in the Architect IDE, as shown here:

And finally, this is the final application running in a browser, with the ability to sort and rearrange the columns in a very sophisticated JavaScript grid in the browser, powered by the InterBase employee database and a RAD Server web service:

Summary

In summary the data flow is: InterBase database, FireDAC connection and SQL query, REST server method with custom JSON processing, ExtJS data storage, ExtJS grid for the UI. And something you can put together in 15 minutes!

While there are several different options on the table for using ExtJS and RAD Studio web services together, and more will be made available by Embarcadero in the future to further simplify the process, as you can see accessing to data produced by a Delphi application from an ExtJS client is reasonably simple.

Categories: News, Blogs, and Tips

Talking at ITDevCon 2017, Tomorrow

Marco Cantu - Tue, 10/10/2017 - 07:46

The conference is organized by Embarcadero partner BitTime and their consulting company BitTime Professionals at their office in Franscati, near Rome, and all of the information is at:

http://www.itdevcon.it/

Well, it might be a little late to join, but I realized I forgot mentioning the event on my blog, so here it goes. If you plan attending, I'll be there tomorrow afternoon and also join the dinner. See the final agenda at http://www.itdevcon.it/agenda

I'll be giving a keynote on the status of RAD Studio, but also two technical sessions covering FireDAC CData Enterprise connectors and offering an introduction to Sencha's ExtJS and Architect tool, along with demos of integration with Delphi powered back ends. Would be interesting, and I'll make sure to share my demos with everyone -- and possibly repeating them at the coming CodeRage online conference next month.

Categories: News, Blogs, and Tips

My Courses on the New Embarcadero Academy

Marco Cantu - Wed, 10/04/2017 - 07:21

The online training site Embarcadero Academy, an independently-run but Embarcadero affiliated training web site, was launched a couple of weeks ago: http://www.businesswire.com/news/home/20170918005798/en/Embarcadero-Academy-Debuts-Online-Courses-Developers-Levels. The academy features classes on different topics, but a lot of them are focused on Delphi programming. You can see the list of Delphi classes here:

https://www.embarcaderoacademy.com/courses/category/Delphi

The site has paid online classes by several Delphi experts and it is going to be expanded rapidly with new content and options (live training, beside self-paced tutorials, subscriptions, etc). The classes are mostly video oriented and, in my case, they are slide free and focused on code.

I have currently 3 classes listed, two on interfaces (and there is a bundle to get both at once, as shown in the image) and one on generics. Another one on anonymous methods is in the works. As you can see my initial effort is to focus on the most recent and more complex features of the Object Pascal language, with content that matches my book but is presented in a different way. What I do, in fact, is building the example step by step, showing the feature but also reasoning on alternative coding options and ideas. I plan expanding my contribution completing the advanced area (RTTI, reflection, attributes), and add more core topics (properties and events, classes and objects, etc) and possibly even beginners Pascal material. Ideas are welcome. As an example, the bundle shown and linked here with the two classes on interfaces and my ebook, is currently priced at 29 US$. See https://www.embarcaderoacademy.com/p/interfaces-in-delphi-intro-to-advanced for more information.

Categories: News, Blogs, and Tips

Why I Choose Delphi Summary

Marco Cantu - Tue, 10/03/2017 - 02:58

Over the summer, there has been a number of blog posts on the "Why I Choose Delphi?" topic. While providing personal ideas, they do have common themes and I think there are very interesting to read, for anyone who is using Delphi today (or used it in the past). Here is the list of the blogs I noted, and I migh have missed others, let me know:

David Harper: https://csvelocity.wordpress.com/2017/07/27/why-i-choose-delphi/

Andre Celestino: http://www.andrecelestino.com/why-i-choose-delphi/

Frank Lauter: http://delphiprofi.blogspot.it/2017/08/whyichoosedelphi.html

Ryan Potts: https://rpottsoh.github.io/Why-I-Choose-Delphi/

Jim McKeeth:  https://community.embarcadero.com/blogs/entry/why-i-keep-choosing-delphi and http://delphi.org/2017/08/why-i-keep-choosing-delphi/

Steffen Nyeland: https://fixedbycode.blogspot.it/2017/08/why-i-keep-preferring-delphi.html

Ray Konopka: https://delphibydesign.com/why-i-choose-delphi/

Jens Fudge: https://community.embarcadero.com/blogs/entry/why-i-choose-delphi

 Robert Calco: http://www.hitcompileandrun.com/2017/08/why-i-choose-delphi.html

"T Theobald":  http://borkedcode.com/wp/?p=1511

Categories: News, Blogs, and Tips

InterBase 2017 Update 1 and Delphi

Marco Cantu - Fri, 09/29/2017 - 01:56

A few months after the InterBase 2017 release, Embarcadero has just made available InterBase 2017 Update 1. If you are an existing InterBase user, this is a nice update the install, given it has some performance improvements, bug fixes, and new features, as explained in the announcement article I just publsihed at:

https://community.embarcadero.com/article/16575-interbase-2017-update-1-is-now-available

InterBase is a great embedded database, and the IBLite/IBToGo versions come included with RAD Studio for all supported platforms (desktop and mibile). The Windows developer edition of the full RDMBS (a fast, hassle free, fully powered SQL engine) is also included in RAD Studio and helps power the RAD Server database. Not only InterBase is on par with most competing (and often more expensive) solution, but it has unique features like ChangeViews that can be leveraged to greatly optimize the data traffic, something even more important in today's mobile and distributed world.

While RAD Studio Tokyo ships with the previous version, InterBase XE7, the InterBase 2017 versions of the developer server and IBLite/IBToGo are available in GetIt -- currently still the original release, Udpate 1 will be made available early next week. Read the linked article above for current download links and more information on this version of InterBase.

 

Categories: News, Blogs, and Tips

IDE Fix Pack 6.0 released – dcc64 and 10.2 Update 1 support

Andy’s Blog and Tools - Thu, 09/28/2017 - 12:51

The new IDE Fix Pack version 6.0 is available. It supports Delphi 10.2 RTM and 10.2 Update 1. And after over a year of being in BETA testing without any bug reports, I also included all the Win64 compiler performance optimizations. Thus the jump to version 6.0 can finally be done as they make the Win64 compiler up to 50% faster.

Changelog:

  • Added: Win64 compile speed optimizations
  • Added: Delphi 10.2 Update 1 support
  • Added: Editor Block Completion UTF8 fix (Delphi 2009 only)

Download:

Name IDE Version File Size Downloads Added IDE Fix Pack 6.1.1 2009 (UP4) IDEFixPack2009Reg61.1.7z 188.6 KB 34 times 2017-10-30 IDE Fix Pack 6.1.1 2010 (UP5) IDEFixPack2010Reg61.1.7z 185.1 KB 42 times 2017-10-30 IDE Fix Pack 6.1.1 XE (UP1) IDEFixPackXEReg61.1.7z 172.72 KB 41 times 2017-10-30 IDE Fix Pack 6.1.1 XE2 (UP4+HF1) IDEFixPackXE2Reg61.1.7z 257.66 KB 33 times 2017-10-30 IDE Fix Pack 6.1.1 XE3 (UP2) IDEFixPackXE3Reg61.1.7z 211.76 KB 21 times 2017-10-30 IDE Fix Pack 6.1.1 XE4 (UP1) IDEFixPackXE4Reg61.1.7z 214.83 KB 16 times 2017-10-30 IDE Fix Pack 6.1.1 XE5 (UP2) IDEFixPackXE5Reg61.1.7z 211.58 KB 19 times 2017-10-30 IDE Fix Pack 6.1.1 XE6 (UP1) IDEFixPackXE6Reg61.1.7z 371.44 KB 14 times 2017-10-30 IDE Fix Pack 6.1.1 XE7 (UP1) IDEFixPackXE7Reg61.1.7z 387.64 KB 44 times 2017-10-30 IDE Fix Pack 6.1.1 XE8 (UP1) IDEFixPackXE8Reg61.1.7z 385.29 KB 25 times 2017-10-30 IDE Fix Pack 6.1.1 10 Seattle (RTM/UP1) IDEFixPackD10Reg61.1.7z 393.88 KB 64 times 2017-10-30 IDE Fix Pack 6.1.1 10.1 Berlin IDEFixPackD101Reg61.1.7z 391.56 KB 87 times 2017-10-30 IDE Fix Pack 6.1.1 10.2 (RTM/UP1) IDEFixPackD102Reg61.1.7z 392.96 KB 177 times 2017-10-30

Download (fastdcc):

Name IDE Version File Size Downloads Added fastdcc 6.1.1 2009 (UP4) fastdcc2009v61.1.7z 82.74 KB 11 times 2017-10-30 fastdcc 6.1.1 2010 (UP5) fastdcc2010v61.1.7z 90.04 KB 13 times 2017-10-30 fastdcc 6.1.1 XE (UP1) fastdccXEv61.1.7z 91.83 KB 13 times 2017-10-30 fastdcc 6.1.1 XE2 (UP4+HF1) fastdccXE2v61.1.7z 129.47 KB 19 times 2017-10-30 fastdcc 6.1.1 XE3 (UP2) fastdccXE3v61.1.7z 137.35 KB 8 times 2017-10-30 fastdcc 6.1.1 XE4 (UP1) fastdccXE4v61.1.7z 140.06 KB 8 times 2017-10-30 fastdcc 6.1.1 XE5 (UP2) fastdccXE5v61.1.7z 139.37 KB 9 times 2017-10-30 fastdcc 6.1.1 XE6 (UP1) fastdccXE6v61.1.7z 186.19 KB 7 times 2017-10-30 fastdcc 6.1.1 XE7 (UP1) fastdccXE7v61.1.7z 200.05 KB 16 times 2017-10-30 fastdcc 6.1.1 XE8 (UP1) fastdccXE8v61.1.7z 199.91 KB 12 times 2017-10-30 fastdcc 6.1.1 10 Seattle (RTM/UP1) fastdccD10v61.1.7z 200.27 KB 27 times 2017-10-30 fastdcc 6.1.1 10.1 Berlin fastdccD101v61.1.7z 199.99 KB 40 times 2017-10-30 fastdcc 6.1.1 10.2 (RTM/UP1) fastdccD102v61.1.7z 200.58 KB 62 times 2017-10-30
Categories: News, Blogs, and Tips

Delphi and RAD Studio Roadmap Update Published

Marco Cantu - Tue, 09/19/2017 - 00:03

The article with the new roadmap slides is available at:

https://community.embarcadero.com/article/16563-rad-studio-roadmap-september-2017

The roadmap is updated with the 10.2.1 actual release and the specific 10.2.2 plans, along with the focus areas for 10.3 next year.

Categories: News, Blogs, and Tips

Visiting Delphi Conference in Poland Next Week

Marco Cantu - Thu, 09/14/2017 - 06:28

On September 21st and 22nd (next Thursday and Friday) I'll be attending and giving sessions at a Delphi conference in Poland. The conference is organized by the local Embarcadero partner, BSC Polska. You can find more information at the "Zlot Programistow Delphi" web site,

http://delphi.pl/zlot/

(Site content is in Polish language, but session descriptions are also in English and several sessions -- those by foreign speakers like myself, Stefan, Primoz -- will be in English).

If you live in Poland, this would be a rather unique opportunity to get a lot of first class Delphi content and meet a few Delphi gurus and one of the product PMs (that is, me). So don't miss the opportunity for a chat, some tech info, and even an interesting evening called "Grill - Delphi and Fun". See you.

 

PS: There are other notable Delphi conferences in Europe next week, The Lab in Netherlands on Sept 19th (https://www.barnsten.com/nl/events/details?events_id=294) and ForenTage on Sept 23rd (and previous days) in Germany (https://forentage.de/). It's the first time in a few years I miss this German user groups conference, but I had a conflicting family event. David Milligton, one of the other RAD Studio PMs, is attending both conferences!

Categories: News, Blogs, and Tips

GetIt Content Update, September 2017

Marco Cantu - Wed, 09/13/2017 - 05:39

We keep adding a lot of open source libraries, trial components, and now also demos and database connectors to the GetIt package manager. As I wrote a couple of months back, we added also a lot of new categories to simplify navigating among the 241 packages listed today.

What was added over recent months to the GetIt package manager for 10.2 Tokyo?

  • AQTime Standard Embarcadero edition
  • FaceAPI library (for Microsoft Cognitive Services)
  • Grijjy Cloud Logger
  • NexuxDB Free Embedded Version
  • RAD Server Industry Template - Hospitality Survey Application
  • JCL and JVCL updates
  • 3DElite TCP Server-Client Library
  • Additional TMS trial components
  • Many /n Software trial components
  • BrilliantCode trial
  • FmxLinux trial
  • The 80 or so trial versions of CData Enterprise Connectors

More and more components are being added continuously, and we are open to submissions from the community and from partners.

 

Categories: News, Blogs, and Tips

12 Years of Blogging

Marco Cantu - Fri, 09/08/2017 - 05:42

Today marks the 12th year of my blog, blog.marcocantu.com (now also mirrored on community.embarcadero.com). It is easy for me to remember, as I started the blog on my birthday! And this is my blog post number 1422.

Lots of things happened in this 12 years, but I'm still mostly focused on Delphi, even if in a different role. And if you read the first post (http://blog.marcocantu.com/blog/startingblog.html) you'll see the core engine was written in Kylix -- the ancestor of the newly released Delphi 10.2 Tokyo with Linux support. You can read the 1420 blog posts in between by navigating the full archive at http://blog.marcocantu.com/archives.html.

To capture at a very high level these 12 years, I grabbed all pictures I used in blog post (at least those I uploaded a copy of) and made the collage below (you can expand it for higher resolution). And thanks to those who have been following my blog for these 12 years. Let's have another great year!

Categories: News, Blogs, and Tips

Using Delphi Parse API with Any Parse Server Hosting

Marco Cantu - Wed, 09/06/2017 - 07:45

The Parse web site (owned by Facebook) was retired earlier this year. This was a fairly popular BaaS (backend as a service) provider for mobile applications, but something you could use also from desktop apps. Delphi (and also C++Builder, btw) has included ready-to-use components for interfacing Parse APIs for quite some time. It was very easy to set up an account on the system and create an app. But the hosting was discontinued, and now what?

Additional Parse Hosting and the Delphi ParseProvider Component

While stopping the Parse web site, Facebook did you positive thing: they made the entire Parse server open source. So what happened is that many cloud hosting providers took that code and created compatible hosting services. By hosting the a fully API-compatible version of the Parse server, these providers made it possible to migrate client applications that were using parse with almost no effort. 

There was one additional issue to use these additional providers from Delphi. Given Parse applications were hosted on parse.com, the main domain name was hard-coded in our component. Now in Delphi Tokyo Release 1 (or 10.2.1) we have added a class helper that lets you easily change the URL provider. As you can read at https://quality.embarcadero.com/browse/RSP-13608 all you need to do is add the line:

ParseProvider1.BaseURL := '...';

In a future release, this will become a property of the component, but to preserve compatibility it was added as a runtime only feature for Tokyo updates.

An Actual Example

To check this does really work I did the following. First I went to one of the Parse server providers that offers a limited free account, https://www.back4app.com/. By entering my credentials, in a minute I could create a test app and manually enter a user on their web console. The console configuration listed all of the parameters needed to connect.

Second I create a VCL forms application, with a ParseProvider component, a BackendUsers component, a button and a memo. In the ParseProvider I copied the various required IDs:

object ParseProvider1: TParseProvider ApplicationID = 'esSv_______Whi' RestApiKey = 'mxBY______Wl6' MasterKey = 'kxW_____DHl' end

The BackendUsers component only configuration is the connection to the provider (which should be automatic). Third step I wrote the following code to refer to the proper URL and get the list of users:

procedure TForm12.FormCreate(Sender: TObject); begin   ParseProvider1.BaseURL := 'https://parseapi.back4app.com/'; end; procedure TForm12.Button1Click(Sender: TObject); var   aJSONArray: TJSOnArray; begin   aJSONArray := TJSOnArray.Create;   try     BackendUsers1.Users.QueryUsers([''], aJSOnArray);     Memo1.Lines.Add (aJSOnArray.ToString);   finally     aJSONArray.Free;   end; end;

You can see the result in the image below (sorry for the scanty UI):

That's all it takes. So you can indeed keep using a Parse Server as a backend for your Delphi desktop and mobile applications, as long as you can find a suitable provider... or you can even self-host the open source version of Parse on your own servers.

Categories: News, Blogs, and Tips

Hotfix for 10.2.1 Inherited VCL Forms Released

Marco Cantu - Wed, 09/06/2017 - 06:23

This hotfix addresses a bug introduced in RAD Studio 10.2.1 and reported as RSP-18792 in Quality Portal. The issue causes an inherited VCL form to fail to scale on high DPI displays. Actually the fix resolves also a couple of related problems.

The download is available at https://cc.embarcadero.com/item/30798

Notice that even if the changes is for only a few lines of source code, the download is over 80 MB, as we are updating all binary files (DCU, BPL) including that code. The list of files is included in the download page.

Categories: News, Blogs, and Tips