Quantcast
Channel: Tutorial - Embarcadero Community
Viewing all 503 articles
Browse latest View live

Enterprise Connectors Released Today

$
0
0

After a successful beta for the past couple of months, I am excited to announce that the CData Enterprise Connectors have been released.

The 30 day Trial versions can be downloaded via the GetIt Package Manager (Tools > GetIt Package Manager > Connectors) in RAD Studio 10.2 Pro or higher. 

Enterprise Connectors are sold in two different editions.

 

You will also see some beta versions in GetIt for new connectors that are still being worked on that you can test while they're in beta.

 

You can find detailed documentation and code snippets for each installed component by navigating to C:/Program Files/CData/Component Name/help

 

Docwiki:  http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Enterprise_Connectors

 

Enterprise Connector Subscriptions are sold in two different editions: Enterprise Connectors and Enterprise Connectors Plus. For a table of supported components by edition, click here.

For pricing information, click here.

 

 


Using Delphi Parse API with Any Parse Server Hosting

$
0
0

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.

Convert CSV file to TFDMemTable format JSON file.

$
0
0

 

Convert from CSV file to “JSON file” of “TFDMemTable format”.

This program uses C++Builder 10.2 Tokyo Release 1.

include

#include <iostream>
#include <fstream>
#include <string>
#include <codecvt>
#include <FireDAC.Comp.Client.hpp>
#include <FireDAC.Stan.StorageJSON.hpp>
#include <FireDAC.Stan.Intf.hpp>
#include <memory>
#include <vector>
#include <sstream>
#include <mutex>
#include <thread>
#include <chrono>

code

struct _Tcsv_to_memtable
{
    std::mutex mx_;
    std::vector<std::thread> vth_;
    std::unique_ptr<TFDMemTable> mem_table_{std::make_unique<TFDMemTable>(nullptr)};
    std::unique_ptr<TFDStanStorageJSONLink> jl_{std::make_unique<TFDStanStorageJSONLink>(nullptr)};
    void create_column(std::vector<String>& v)
    {
        //Field creation of "TFDMemTable"
        //The field name is the first line of CSV File
        for (auto s: v)
        {
            auto fld = mem_table_->FieldDefs->AddFieldDef();
            //Discard the "BOM (Byte Order Mark)" if present.
            fld->Name = StringReplace(s, L'\x0feff', "", TReplaceFlags());
            fld->DataType = TFieldType::ftWideString;
        }
        mem_table_->Active = true;
    }
    void create_line(std::vector<String>& v)
    {
        //Add 1 line of "CSV File" to "TFDMemTable"
        int i{0};
        mem_table_->Append();
        for (auto s: v)
        {
            //One item for one field.
            mem_table_->Fields->operator[](i)->AsWideString = s;
            ++i;
        }
        mem_table_->Post();
    }
    void create_line(std::wstring ws, int line_num)
    {
        std::lock_guard<std::mutex> lk(mx_);
        if (ws.length() > 0)
        {
            //Inserted by dividing one line of CSV File to vector<String>.
            std::vector<String> v1;
            std::wstring column_data;
            std::wistringstream line_data(ws);
            while (std::getline(line_data, column_data, L','))
            {
                v1.push_back(column_data.c_str());
            }
            switch (line_num)
            {
            case 0:
                create_column(v1);
                break;
            default:
                create_line(v1);
            }
        }

    }
    void threads_join()
    {
        //Wait for the termination of all threads.
        for (auto& th: vth_)
        {
            th.join();
        }
    }

};
int _tmain(int argc, _TCHAR* argv[])
{
    std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
    _Tcsv_to_memtable memtable_;
    UnicodeString argv_     = argv[1];  //Specify CSV Fire for input.
    UnicodeString arg_o_    = argv[2];  //JSON output destination specification made with "TFDMemTable".
    if (FileExists(argv_))
    {
        std::wfstream file_;
        file_.open(argv_.w_str(), std::ios::in);
        //The CSV file is utf8 format.
        file_.imbue(std::locale(std::locale::empty(), new std::codecvt_utf8<wchar_t>));

        std::wstring buff;
        int line_num_{0};
        while (std::getline(file_, buff))
        {
            //The append processing to "TFDMemTable" threads line by line.
            memtable_.vth_.push_back(std::thread([&memtable_, &buff, line_num_](){
                memtable_.create_line(buff, line_num_);
                }));
            //Since the command line is multibyte, AnsiString conversion is done.
            AnsiString as_ = buff.c_str();
            std::cout << as_ << std::endl;
            ++line_num_;
        }

        memtable_.threads_join();
        //Finally, save the TFDMemTable contents as a JSON file.
        memtable_.mem_table_->SaveToFile(arg_o_, TFDStorageFormat::sfJSON);

    }
    auto keika =  std::chrono::system_clock::now() - now;
    std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(keika).count();
    std::cout << " millisecond." << std::endl ;
    return 0;
}

There is a project file in github, you can try it right away.
GitHub - mojeld/csvfstream_to_TFDMemTable: Create json file of TFDMemTable format from CSV file.

f:id:mojeld:20170901174729p:plain

Delphi Blogs of the (Week) Month #55

$
0
0

This is my fairly regular (although now monthly) list of relevant links to blogs post, articles, news, and more from the Delphi community.

Embarcadero Updates

Idera has acquired Sencha to strengthen its developer tools business (aka Embarcadero). You can read the press release (http://www.businesswire.com/news/home/20170825005086/en/IDERA-Acquires-Sencha-Strengthen-Developer-Tools-Business) and articles like http://sdtimes.com/idera-sencha-acquisition-sdtimes.

Embarcadero released a hot fix for Tokyo 10.2.1 to resolve iOS AdHoc deployment: http://blog.marcocantu.com/blog/2017-august-hotfix-adhoc.html

Notable Blog Posts

Save Time With This Quick LiveBindings Trick For Delphi And C++Builder (by Eli): https://community.embarcadero.com/blogs/entry/learn-how-to-quickly-livebind-almost-any-control-with-this-tedit-trick-for-delphi-and-c-builder

Experiments in Uniform Memory Management (by Erik van Bilsen): https://blog.grijjy.com/2017/08/09/experiments-in-uniform-memory-management/

Delphi FMX Chess Game (although I'm eagerly waiting for more information) https://csvelocity.wordpress.com/2017/08/08/delphi-fmx-chess-game/

Cross-Platform Code Hooking (also by Erik van Bilsen): https://blog.grijjy.com/2017/07/26/cross-platform-code-hooking/

Windows Manifest Files (by Vincent Parrett): https://www.finalbuilder.com/resources/blogs/postid/753/windows-manifest-files

TNotifyEvent debouncing in Delphi (by Sergey Zhukov): https://www.code-partners.com/tnotifyevent-debouncing-in-delphi/ (althought it has been criticized as not really being on debouncing, it is an interesting read)

Use C++Builder to get Android current ringtone mode (by Haruyuki Mohri): https://community.embarcadero.com/blogs/entry/use-c-builder-to-get-android-current-ringtone-mode

Resizing a TViewPort3D (by Gustav Schubert): http://federgraph.blogspot.it/2017/08/resizing-t-viewport-3d.html

The Dark Side of Application.ProcessMessages in Delphi Applications (by Zarko Gajic): https://www.thoughtco.com/dark-side-of-application-processmessages-1058203 (re-opening a never ending debate on the use of Windows limited message based parallel processing vs. real threading solutions -- or maybe the debate is actually settled and threads just won?)

Cloud Based Unit Resolver For The Delphi RTL In Delphi 10.2 Tokyo (by FMX Express): http://www.fmxexpress.com/cloud-based-unit-resolver-for-the-delphi-rtl-in-delphi-10-2-tokyo/

Third Party Libraries and Components

Delphi base compatibility, Spine improvements, other stuff in Castle Game Engine (by Michalis): https://castle-engine.sourceforge.io/wp/2017/08/14/delphi-base-compatibility-spine-improvements-other-stuff/

JSKit - open-source Cross-platform JavaScript framework for Delphi and CrossVcl announcement (by Eugene) at https://plus.google.com/u/0/118397897778295642304/posts/ip2wGhNfskd?cfem=1. The library itself can be found at https://github.com/eugenekryukov/jskit

Kind of similarly, ​ScriptGate provides mutual calls between JavaScript and #Delphi and it's useful for Hybrid apps (by Hosokawa Jun): https://bitbucket.org/freeonterminate/scriptgate

GrijjyCloudLogger, remote logging for Windows, iOS, Android, macOS and Linux (by Allen Drennan) at https://blog.grijjy.com/2017/08/22/grijjycloudlogger-remote-logging-for-windows-ios-android-macos-and-linux/. The repository is at https://github.com/grijjy/GrijjyCloudLogger

​Must Have RAD Accessories – InnoSetup (by Craig Chapman): http://chapmanworld.com/2017/08/25/must-have-rad-accessories-innosetup/ (and part of a very nice series of classic Delphi components and tools)

Debugger Callstack Resolver released (by Andreas Hausladen): http://andy.jgknet.de/blog/2017/08/debugger-callstack-resolver-released/

RAD Server Solution Series: [Hospitality] Restaurant Survey Application

$
0
0

RAD Server is a turn-key application foundation for rapidly building and deploying services based applications. RAD Server enables developers to quickly build new application back-ends or migrate existing Delphi or C++ client/server business logic to a modern services based architecture that is open, stateless, secure and scalable. RAD Server is easy to develop, deploy and operate making it ideally suited for ISVs and OEMs building re-deployable solutions. RAD Server allows you to take your existing code and convert it to REST API endpoints.

 

Solution Name: RAD Server Hospitality Survey Application


Industry: Hospitality: Restaurants, Hotels etc.

 

Solution Overview: The RAD Server hospitality sample application includes a mobile client application for collecting survey data, a back-end server to store data and administer surveys and a web client for viewing survey results. The solution includes RAD Server multi-tenancy support for managing surveys from multiple restaurants.

 

 

How to download: Available through GetIt (Tools > GetIt Package Manager > Industry Templates) in RAD Studio 10.2.

 

Setup Instructions: We have a detailed document with setup instructions for the sample project. Download the PDF here.

 

Overview:

The industry template consists of four different projects that interconnect with each other. The projects are: 

  • Hospitality Survey Setup

  • Hospitality Survey EMS

  • Hospitality Survey Admin

  • Hospitality Survey Client

 

1) Hospitality Survey Setup app

This app will help you set up your database, the tables and data, and your RAD Server EMS user accounts.

 

 

 

2) Hospitality Survey EMS

This is the RAD Server side REST resource which both the Hospitality Survey Client and the Hospitality Survey Admin interface with. It should be deployable on Windows and Linux through IIS, Apache, or the standalone EMS server. 

 

 

3) Hospitality Survey Client

This is a RAD Studio client application for Android, iOS, macOS and Windows. The client application should allow you to select a tenant from your RAD Server and then log in as a user. Once logged in, it will download the survey data for your current tenant and allow the survey to be filled out. Once the survey is complete it can be submitted back to the server and a new survey can be started.

 

 

 

 

4) The Hospitality Survey Admin app

This is an AngularJS application for the web. You can log into the application with your Tenant ID and RAD Server user ID. The web app allows you to view statistics and graphs about the results of the survey questions and each individual question and answer. You can also export a list of emails collected from the surveys.

 

[DownloadButton Product='RAD' Caption='Download a RAD Studio 10.2 Trial today!']

Must Have RAD Accessories – Documentation Insight

How to control "the system audio volume" of iOS

$
0
0

Use C++Builder 10.2 to control audio volume of iOS.
I used the MPVolumeView class of iOS.
The MPVolumeView class is declared in “iOSapi.MediaPlayer.hpp”.

Include two files.

#include <iOSapi.MediaPlayer.hpp>
#include <iOSapi.UIKit.hpp>

Form design

Arrange “Up” and “Down” two TButton. Use this button to control the volume.

f:id:mojeld:20170905181055p:plain

Add MPVolumeView to the main form Class

Add “_di_MPVolumeView” and “_di_UISlider” to the form class.

class TForm1 : public TForm
{
__published:  // IDE-managed Components
    TButton *Button1;
    TLayout *Layout1;
    TButton *Button2;
    void __fastcall Button1Click(TObject *Sender);
    void __fastcall Button2Click(TObject *Sender);
private:  // User declarations
    _di_MPVolumeView    MPVolumeView1;
    _di_UISlider        slider1;
public:       // User declarations
    __fastcall TForm1(TComponent* Owner);
};

Main Form constructor

__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
    //Use "TMPVolumeView" to create "_di_MPVolumeView".
    MPVolumeView1 = TMPVolumeView::Create();
    for (int i = 0; i < MPVolumeView1->subviews()->count(); i++) {
        switch (i) {
        case 0:
            //Setting the _di_UISlider in the "MPVolumeView1".
            slider1 = TUISlider::Wrap(MPVolumeView1->subviews()->objectAtIndex(i));
            //Set the slider to 0.0.
            slider1->setValue(0.0);
        }
    }
}

Code of volume down button

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    float i = slider1->value();
    slider1->setValue(i - 0.1);
}

Code of volume up button

void __fastcall TForm1::Button2Click(TObject *Sender)
{
    float i = slider1->value();
    slider1->setValue(i + 0.1);
}

Execute the program.

Hotfix for 10.2.1 Inherited VCL Forms Released

$
0
0

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.


12 Years of Blogging

$
0
0

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!

The Panthera Project – Part 7 – Themes

Implement CreateAnonymousThread with BCC32.

$
0
0

C++Builder 10.2 BCC32 can not write lambda. 
So write an implementation in Invoke() with TCppInterfacedObject<>.

struct T_thread_proc :  TCppInterfacedObject<TProc>{
    TNotifyEvent f_ev_;
    struct T_sync_proc :  TCppInterfacedObject<TThreadProcedure>{
        TNotifyEvent f_ev_;
        T_sync_proc(TNotifyEvent& ev2){ f_ev_ = ev2; }
        virtual void __fastcall Invoke() {
            //Inside Synchronize.
            f_ev_(NULL);  //Execute "TNotifyEvent".
        }
    };
    T_thread_proc(TNotifyEvent ev1){f_ev_ = ev1; }
    virtual void __fastcall Invoke() {
        //Write thread execution code here.
        Sleep(3000); //example
        //Finally call Synchronize.
        TThread::Synchronize(
            TThread::CurrentThread,_di_TThreadProcedure(new T_sync_proc(f_ev_)));
    }
};

Event prepared for calling with TThread::Synchronize().

void __fastcall TForm1::do_thread_event(TObject *Sender)
{
    Button1->Enabled    = true;
    ActivityIndicator1->Visible = false;
    ActivityIndicator1->Animate = false;
    Caption = "End CreateAnonymousThread";
}

Call TThread::CreateAnonymousThread() with a TButton event.

Place the TButton and TActivityIndicator

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TThread::CreateAnonymousThread(_di_TProc( new T_thread_proc(&do_thread_event)))->Start();
    Caption = "Started CreateAnonymousThread";
    ActivityIndicator1->Visible = true;
    ActivityIndicator1->Animate = true;
    Button1->Enabled    = false;
}

Build execution.

When you click the Button1, until the thread is finished "ActivityIndicator1->Animate = true";

 

GetIt Content Update, September 2017

$
0
0

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.

 

Get Started with RAD Studio 10.2.1 using Sample Projects

$
0
0

With RAD Studio 10.2.1, we provide a number of sample projects to help you get started building Windows, Mac, iOS and Android applications.

Today, I thought I would highlight some of those demos for new users trying RAD Studio 10.2.1.

How to handle data in TFunc with C++Builder(BCC32)

$
0
0

When dealing with TFunc in BCC32(C++Builder 10.2).

For example, suppose Delphi side has the following function.

type
  Tproc_func = record
    {When TFunc is an argument as shown below. }
    function func1(func: TFunc<Integer, String>):String;
  end;
implementation
function Tproc_func.func1(func: TFunc<Integer, String>): String;
begin
  Result  := func(CurrentYear);
end;

The func1 function has an argument of TFunc.
In this case, Delphi can handle it very simply.

function test_func: String;
begin
  {Anonymous Method are available.}
  Result  :=  func1(function (i: Integer): String begin end);
end;

Since bcc64 or bcc32c is based on C++11, lambda can be used.
But, when you use it from BCC32, preparation is a little needed.

You need a class that inherits from TCppInterfacedObject<TFunc__2<T1,T2> >.
And we need the Invoke() function inside the class.

#include <sstream>
template<typename T1, typename T2>
struct T_func1 : TCppInterfacedObject<TFunc__2<T1,T2> >
{
    String __fastcall to_string(int i)
    {
        std::stringstream lss;
        lss << i;
        return lss.str().c_str();
    }
    T2 __fastcall Invoke(T1 i)
    {
        //Write the code you want to pass to TFunc__2 here.
        return static_cast<T2>("Delphi was released in " + to_string(i - 22) + " for the first edition.");
    }
};

Pass the above class instance to TFunc<Integer, String>.

__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
    Tproc_func lfunc;
    Label1->Caption = lfunc.func1(new T_func1<int, String>());
}

We were able to pass the TFunc even BCC32 in the manner described above.

 

Must Have RAD Accessories – Lockbox


Visiting Delphi Conference in Poland Next Week

$
0
0

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!

Delphi and RAD Studio Roadmap Update Publsihed

Modernize your apps with new styles from DelphiStyles.com

$
0
0

KSDev, the company behind DelphiStyles.com, has released some stunning new styles for VCL and FireMonkey.  This includes a number of platform specific themes for Windows and macOS. 

Experimenting with Neural Networks – Part 1

Building a Google Drive VCL application using Enterprise Connectors

$
0
0

In today's blog post,  I am providing a simple step-by-step tutorial for creating a VCL application that connects to Google Drive using the Google Drive Enterprise Connector component.

The CData FireDAC Component for Google Drive provides an easy-to-use database-like interface for Delphi & C++Builder Apps access to live Google Drive data (Files, Changes, Apps, and more).

Viewing all 503 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>