Turn (Delphi new Cave): Use Delphi to develop multi-tier applications (17) using the RTC Web server to return JSON

Source: Internet
Author: User

RTC is the most professional Web application server of Delphi, and if the client wants to use JSON, then using RTC should also be a

Very good choice. Let's take an example of using the RTC Web server to return the database JSON.

Create a new program form, place the controls:

Where the properties of the server are

Note that this piece does not select multi-threading, because in this simple example, the database pool is not involved for the time being,

I'll do the database pool example later.

Properties of the RtcDataProvider1

Then set the UNIDAC database connection properties, I use Firebird as the database here.

and set the event to the following code:

Procedure Tform2.button1click (sender:tobject); Begin   Server. Listen ();   Button1.caption:= ' started ';   Button1.enabled:=false;end;

Procedure Tform2.rtcdataprovider1checkrequest (sender:trtcconnection); begin with     Trtcdataserver (Sender) do    if uppercase (request.filename) = '/getdata '      Then Accept;end;
Procedure tform2.rtcdataprovider1datareceived (sender:trtcconnection); var  ds:trtcdataset;   R:trtcvalue;  ss:string;  S:trtchugestring;begin with  trtcdataserver (Sender) does    if Request.complete then     begin      Ds:= Trtcdataset.create;      R:=trtcvalue.create;      S:=trtchugestring.create;    Try         CX. Sql. Clear;         CX.SQL.ADD (' select * from BMB ');         Cx. Open;      DELPHIDATASETTORTC (cx,r.newdataset);      R.to_json (s);      Ss:=s.get;      Write (ss);      Cx. Close;     Finally      DS. Free;      R.free;      S.free;     End;     End;end;

Then compile and run, note to manually add the RTCDB and rtcfaststrings two unit references.

Now we enter Http://127.0.0.1/getdata in the browser

The JSON string for the database output will be displayed

Oh, you can find that the RTC JSON pass inside the Chinese character directly into the Unicode code.

Now, you can interpret the resulting data at the client's discretion.

Turn (Delphi new Cave): Use Delphi to develop multi-tier applications (17) return JSON using the RTC Web server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.