Académique Documents
Professionnel Documents
Culture Documents
R E L A T E D L A N G U A G E S / A N D R O I D,
I O S, M A C , W I N D O W S & L I N U X
P R I N T E D, P D F, & O N L I N E V I E W
DX
C++
DELPHI BUILDER
19 SEPTEMBER 2017
EVOLUON IN EINDHOVEN
VCL FMX
RAD
UI SERVER
barnsten
BLAISE PASCAL MAGAZINE 63
D E L P H I, L A Z A R U S, S M A R T M O B I L E S T U D I O,
A N D P A S C A L R E L A T E D L A N G U A G E S
F O R A N D R O I D, I O S, M A C, W I N D O W S & L I N U X
CONTENTS
ARTICLES
Windows Management Instrumentation Page 6
By Max Kleiner
Quantum computing Page 10
Part 2 Building a quantum computer
Detlef Overbeek
Getting Framed (The Framework project) Page 16
By David Dirkse
Storing objects in the Google Firebase cloud Page 24
with TMS Cloud Pack
By Bruno Fierens
Video processing Part 2 Page 30
By Boian Mitov
Rest Easy With kbmMW Part1 Page 37
By Kim Madsen
Quantum computing
Image 1
ADVERTISERS
BARNSTEN / PASCON: THE LAB PAGE 2 / 22+23
BARNSTEN / PASCON: THE LAB PAGE 9 / 43
COMPONENTS4DEVELOPERS PAGE 44
EMBARCADERO PAGE 5
VISUINO PAGE 36
Wim Van Ingen Schenau -Editor Peter van der Sman Rik Smit
wisone @ xs4all.nl sman @ prisman.nl rik @ blaisepascal.eu
www.romplesoft.de
Editor - in - chief
Detlef D. Overbeek, Netherlands Tel.: +31 (0)30 890.66.44 / Mobile: +31 (0)6 21.23.62.68
News and Press Releases email only to editor@blaisepascal.eu
Editors
Peter Bijlsma, W. (Wim) van Ingen Schenau, Rik Smit,
Correctors
Howard Page-Clark, James D. Duff
Trademarks
All trademarks used are acknowledged as the property of their respective owners.
Caveat Whilst we endeavour to ensure that what is published in the magazine is correct, we cannot accept responsibility for any errors or omissions.
If you notice something which may be incorrect, please contact the Editor and we will publish a correction where relevant.
Subscriptions ( 2013 prices )
1: Printed version: subscription € 85.-- Incl. VAT 6 % (including code, programs and printed magazine,
10 issues per year excluding postage).
2: Electronic - non printed subscription € 50.-- Incl. VAT 21% (including code, programs and download magazine)
Subscriptions can be taken out online at www.blaisepascal.eu or by written order, or by sending an email to office@blaisepascal.eu
Subscriptions can start at any date. All issues published in the calendar year of the subscription will be sent as well.
Subscriptions run 365 days. Subscriptions will not be prolonged without notice. Receipt of payment will be sent by email.
Subscriptions can be paid by sending the payment to:
ABN AMRO Bank Account no. 44 19 60 863 or by credit card: Paypal
Name: Pro Pascal Foundation-Foundation for Supporting the Pascal Programming Language (Stichting Ondersteuning Programeertaal Pascal)
IBAN: NL82 ABNA 0441960863 BIC ABNANL2A VAT no.: 81 42 54 147 (Stichting Programmeertaal Pascal)
Subscription department Edelstenenbaan 21 / 3402 XA IJsselstein, The Netherlands / Tel.: + 31 (0) 30 890.66.44 / Mobile: + 31 (0) 6 21.23.62.68
office@blaisepascal.eu
Copyright notice
All material published in Blaise Pascal is copyright © SOPP Stichting Ondersteuning Programeertaal Pascal unless otherwise noted and may
not be copied, distributed or republished without written permission. Authors agree that code associated with their articles will be made
available to subscribers after publication by placing it on the website of the PGG for download, and that articles and code will be placed on
distributable data storage media. Use of program listings by subscribers for research and study purposes is allowed, but not for commercial
purposes. Commercial use of program listings and code is prohibited without the written permission of the author.
Common Information
CIM Object Manager (CIMOM) Model ()CIM)
WMI Service) WMI Repository
%SystemRoot%\system32\
wbem\winmgnt.exe
%SystemRoot%\system32\
WMI Provider wbem\Repository\FS\
%SystemRoot%\system32\ objects.data
wbem\*.dll
What is allowed and not allowed, along with these table definitions are in the
MSDN reference for WMI:
http://msdn.microsoft.com/en-us/library/aa394582(VS.85).aspx
Of course there's a great number of them, and you can find out just about anything regarding your
local system or any system on the network that you can connect to like the running hardware
statistic, along with memory usages, processes, and threads or a physical element like temp:
FWbemObjectSet:= FWMIService.Get('Win32_TemperatureProbe');
Beware, that selecting all the data in some of the tables will take a very large time and a huge amount
of resources, so be careful to limit your statements as you would in dealing with a regular database.
You do also have more than one root name space available, even the query language in the object set
is chose able:
const
WbemComputer ='localhost'; // wbemFlagForwardOnly= $00000020;
WbemRootNameSpace ='root\CIMV2';
Each item in a SWbemObjectSet is a SWbemObject (yet another object (Interface) in the WMI
scripting library) that represents a single instance of the requested resource. You use SWbemObject
and WMIRowFindNext to access the methods and properties defined in the managed resource's
class definition WMIClass.
So, if the scripting steps to retrieve information from WMI are identical, what are the
Win32_Process, Win32_Service, and Win32_NTLogEvent classes? Furthermore, where do
they come from, what other classes are available, and how do you use them? The answers to these
questions lie in the components that make up the WMI architecture. As I said we mapped the type
library to functions to simplify the handling in a dynamic script, let’s have a look at the interface:
// *********************************************************************//
// DispIntf: ISWbemPropertyDisp
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {1A388F98-D4BA-11D1-8B09-00600806D9B6}
// *********************************************************************//
ISWbemPropertyDisp = dispinterface
['{1A388F98-D4BA-11D1-8B09-00600806D9B6}']
function Value: OleVariant; dispid 0;
property Name: WideString readonly dispid 1;
property IsLocal: WordBool readonly dispid 2;
property Origin: WideString readonly dispid 3;
property CIMType: WbemCimtypeEnum readonly dispid 4;
property Qualifiers_: ISWbemQualifierSet readonly dispid 5;
property IsArray: WordBool readonly dispid 6;
end;
The dispinterface statement defines a set of properties and methods on which you can call.
This function value will add a value of the type OleVariant that are represented by their properties
(digits, strings and more) so we use in most cases strings as the representation of the value
(VarToStr()).
You can use WMI in maXbox by early binding (pre compiled with WbemScripting_TLB; ) or late
binding with CreateOleObject() .
wmiLocator:= CreateOleObject('WbemScripting.SWbemLocator');
As you begin to write scripts to interact with WMI managed resources, you'll often see the term
instance used to refer to a virtual representation of the managed resource in the running script.
So we check the availability of the WMI late binding:
(ClassIDToString(StringToClassID('WbemScripting.SWbemLocator'));
writeln('WMI Installed:
'+botoStr(ProgIDInstalled('WbemScripting.SWbemLocator')))
>>> {76A64158-CB41-11D1-8B02-00600806D9B6}
WMI Installed: TRUE
REFERENCES
Examples and Version of this Tutorial 52:
2017-05 Cumulative Update for Windows 10 Version 1607 for x64-based
Systems (KB4019472) – maXbox 4.2.5.10
http://www.softwareschule.ch/examples/766_wmi_management.txt
http://www.softwareschule.ch/examples/
210_public_private_cryptosystem5_ibz_herdt2.txt
DispInterface explain:
https://msdn.microsoft.com/en-us/library/ebhsdt9x.aspx
http://www.delphidabbler.com/tips/216
_od#HMM6&*MMMH::-_
_dHMMMR??MMM? ""| `"'-?Hb_
.~HMMMMMMMMHMMM#M? `*HMb.
./?HMMMMMMMMMMM"*""" &MHb.
/'|MMMMMMMMMMM' - `*MHM\
/ |MMMMMMHHM'' .MMMHb
| 9HMMP .Hq, TMMMMMH
/ |MM\,H-""&&6\__ `MMMMMMb
| `""HH#, \ - MMMMMMM|
| `HoodHMM###. `9MMMMMH
| .MMMMMMMM##\ `*"?HM
| .. ,HMMMMMMMMMMMo\. |M
| |M'MMMMMMMM'MMMMMHo |M
| ?MMM'MMMMMMM'MMMM* |H
|. `#MMMM'MM'MMMMM' .M|
\ `MMMMMMMMMMM* |P
`\ MMMMMMMMT"' ,H
`\ `MMMMMMH? ./
\. |MMMH#" ,/
`\. |MMP' ./'
`~\ `HM:.- . ,/'
„-\_ '_\ . _.-"
„-\-#odMM\_,oo==-"
THE
INTRODUCTION
This article attempts to remove some of the fog
surrounding the complex subject of quantum
computing.
I was privileged recently to talk to Koen Bertels, one
of the leaders of the quantum project at the Computer
Engineering Lab & QuTech (Delft University of
Technology) http://ce.et.tudelft.nl.
Quantum computers have this huge advantage: 2. will thus be executed by their respective
they process all the required calculations (based computing blocks.
on their setup conditions) at the same time! It is You must realize that the Quantum computer
only possible to measure one of all the possible Chip needs to be at a very low temperature.
results. Perhaps it is the one you want. You have Otherwise we would never be capable of
to check and double-check and try again if collecting any Qubits. These temperatures are
necessary. Maybe with repeated inspection and near(very near) the absolute lowest temperature
investigation of the superposition and we can achieve.
entanglement you can find an answer that has
been reached far more efficiently than by using a This is done by Laser-cooling and is primarily
classic computer alone. used to create ultracold atoms for experiments in
quantum physics. These experiments are
Even though the potential of quantum performed near absolute zero. In 2011, a team
computing is huge, its weak point is the fragility from the California Institute of Technology and
of the qubits. Qubits inevitably interact with their the University of Vienna became the first to
environment, and their information of qubits laser-cool a (10 μm x 1 μm)* mechanical object to
leaks to the environment. This is called its quantum ground state.
“decoherence” because the information you want *(micrometer 10 μm = 0,01mm).
is lost. Coping with qubit fragility is therefore
one of the main challenges involved in building QUANTUM ERROR CORRECTION
and operating a quantum As I already mentioned,
computer. Qubit fragility
CURRENT STATE-OF-THE-ART the main handicap of
causes errors during QUANTUM CHIPS CONTAIN quantum technology is its
computation. To reduce AROUND 10 QUBITS. fragility. QEC is more
errors to minimum most challenging than classical
quantum computers operate at super-cooled error correction. The basic idea of QEC techniques
temperatures close to absolute zero, and so is to use several physical imperfect qubits to
require large and sophisticated refrigeration compose more reliable units called “logical
apparatus. qubits” . Such encoding does not need to clone the
qubit state, as it is done by entangling several
Quantum Error Correction (QEC) mechanisms qubits called “data qubits” . Since quantum errors
are needed to make quantum computing fault- accumulate as time elapses, Error Syndrome
tolerant. The challenge of building fault-tolerant Measurement (ESM) has to be done repeatedly.
quantum circuits, developing a quantum QEC allows fault tolerant computation and is thus
computer called the “standard universal a fundamental part of any quantum computing
quantum computer“ are huge. The physics system. The drawback is that it dramatically
challenges include: increasing the number of increases the number of physical qubits needed
qubits per chip that can be entangled, for running any quantum algorithm.
increasing the qubits’ lifetimes, and increasing
the qubits’ operational fidelity.
Quantum engineers are currently developing
technology that they hope will provide high
speed control-logic in a scalable and flexible way.
(The work on this University of Delft quantum
computer is funded by Intel in the context of the
QuTech-Intel collaboration.)
Current state-of-the-art quantum chips contain
around 10 qubits.
Pragma Parser
Annotated
Code
Logil Q Circuit
Logical QIS
Reversible Circuit
decomposition &
Design
optimization
Logical QASM
Logical QISA
FT Implementation of Logical Circuits
Linker Loader
RELATED RESEARCH
The first quantum algorithm was proposed by David Deutsch in 1985 along with the Quantum Turing
Machine. A lot of work has been done since then and nowadays we can find more than 50 basic
quantum algorithms. The most representative example of a quantum algorithm is the famous Shor’s
Factoring algorithm that is used to factorize a very large number.
It is the first quantum algorithm that has an application to real world problems, e.g. decryption, and
shows exponential speed up over its classical counterparts. However, Shor’s algorithm requires
millions if not billions of physical qubits for factorizing big numbers.
What is Shor's factoring Quantum superposition of states Where are the limits of human Quantum Computer in a
algorithm? and decoherence technology? And can we Nutshell with the newest
somehow avoid them? technolgies of the moment:
https://www.youtube.com/ http://toutestquantique.fr/ This is where quantum computers
watch?v=hOlOY7NyMfs en/superposition/ become very interesting. https://www.youtube.com/
watch?v=0dXNmbiGPS4
https://www.youtube.com/
watch?v=JhHMJCUmq28
CONCLUSION
I have shown how the phenomena of Superposition and Entanglement form two key components in quantum
computers. I am not sure the future will give us even more strange phenomena which will make it possible to solve
one of the biggest problems: the cooling of the chips (needed for the molecules to be as steady as possible). There might be a
solution: Pressure. So the outcome for now is that we will not see in the near future a Quantum Notebook. It would
probably be a little-bit costly as well. But by creating more and more algorithms for the quantum machine we will
even be capable of creating better algorithms for classic computers we would otherwise not be able to achieve. If
you look at it, we all want to have computers that work faster and faster.
We want immediate answers instead of surfing the Internet. We want to solve problems that we just can't
do(Yet). We want more graphics and the market wants things smaller, we want it ultra fast. We can use the
quantum computer: one would be able to solve enormous problems you simply can’t solve with classical
computers: voice-activation, device technology and translations, the development of new drugs, climate
change prediction models, weather predictions on long term, optimization of traffic control, development of
robotics, machine navigation and shape recognition.
We need algorithms and software. We need them for the use of encryption.
For now we have for the first time a starting point for a real quantum computer.
It already exists and is used, - experimental still. Yet quantum computer development is still in its infancy.
However, this is not a stepwise development from classical computers, but a revolutionary jump.
15
We live in very exciting times!
GETTING FRAMED (THE FRAMEWORK PROJECT) PAGE 1/6
BY DAVID DIRKSE
If ever you wanted to create
your own storage rack, you
probably know the trouble you
will have making it stable. If
force is applied to a rectangular
box, it may become distorted
and turn into a parallellogram.
However, if a brace is attached
between opposite
joints, the rectangle
is now transformed
into two triangles and
distortion is not
possible. See Figure 1.
Figure1.
Using above boxes we may build frames of several
rows and columns.
Then the question arises which boxes should be
braced to make a rigid structure.
This framework project was built to answer this
question.
If a frame is not rigid, the distortion is showed.
Also superfluous braces may be marked and
removed to obtain a minimally braced rigid frame.
Figure3.
Below is a picture of the framework program at
work.
Per box the brace must be
recorded. bbRemoved
indicates a removed brace,
which was superfluous.
Figure2.
The frame is defined by its
Note: there is no difference in the effect of coordinates (x,y). All drawing is done in a bitmap
ascending- and descending braces. (map). The map is displayed in a paintbox when
drawing is finished. This prevents drawing actions
Distortion depends on the direction of applied to cause flickering of the screen. Figure4.
forces. I have choosen right- and down forces.
CODING THE PROBLEM
Columns and rows count 0..7 (maximum).
Boxes are coded 0..3
PAINTFRAME
Boxes are painted left to right,
top to bottom.
The box position is coded in
variable code:
0 : left top
paint all edges
1 : top row
paint top, right and bottom edges
2 : left column
paint left , bottom and right edges
3 : other
paint bottom and right edges
The dx-,dy- values are stored in a Reason is to save time by avoiding drawing of
constants array[0..3] per box type 0..3: the same lines. Part of typical source code:
const offset : array[0..3] of TOffset = case code of
((dx1: 0; dy1: 60; dx2: 100; dy2: 60; dx3: 100; dy3: 0), //0 0 : begin //l eft top
(dx1:-25; dy1: 54; dx2: 75; dy2: 54; dx3: 100; dy3: 0), //1 moveto(coords[i,j].x, coords[i,j].y);
(dx1: 0; dy1: 60; dx2: 91; dy2: 102; dx3: 91; dy3: 42), //2 lineto(coords[i+1,j].x, coords[i+1,j].y);
(dx1:-25; dy1: 54; dx2: 66; dy2: 96; dx3: 91; dy3: 42)); //3 lineto(coords[i+1,j+1].x, coords[i+1,j+1].y);
lineto(coords[i,j+1].x, coords[i,j+1].Y);
lineto(coords[i,j].x, coords[i,j].y);
end;
Above dx,dy values are calculated using basic …......................
goniometric functions. 2 : begin // left
Procedure testframe tests the frame and modifies moveto(coords[i+1,j].x, coords[i+1,j].y);
lineto(coords[i+1,j+1].x, coords[i+1,j+1].y);
the coordinates.
lineto(coords[i,j+1].x, coords[i,j+1].Y);
Procedure paintFrame paints the frame. lineto(coords[i,j].x, coords[i,j].y);
end;
….......................
end; // case
For details please refer to procedure paintframe PRACTICE OF RIGID BOX TESTING
source code. So far for the painting. Now the Function rigid(xcol,xrow : byte) : boolean;
harder part: testing the frame for rigidity. returns true if box(xcol,xrow) is rigid.
This function is the core of this project.
THEORY OF RIGID BOX TESTING These are the local variables:
A box is called rigid if it cannot be distorted. It var stepNr,n,v : byte;
keeps straight angles. box : array[1..16] of Tbox;
So these boxes are of type 0 or 3. colEnables : byte;
Of course a braced box is rigid. rowEnables : byte;
GO : boolean; // false to exit repeat loop
But look at the next picture where the left-top
box is not braced but sure is rigid:
stepNr:
counts 1,2,3... as we step from row to column.
StepNr 1 finds a brace in its row, stepNr 2 a brace in
its column ...etc.
box[1..16] :
search path of (x,y) coordinates
ColEnables, rowEnables
start at value $ff [11111111] binary, enabling all
rows/columns. If a column or row is part of the path,
the corresponding bit is set to zero to
avoid visiting this row/column again.
This avoids loops in the path.
Go:
a boolean flag for repeat loop exit control.
Other variables
defined outside this function are playing a role:
var columnvector : array [0..7 ] of byte ;
To examine box (0,0) for rigidity : rowvector : array[0..7] of byte;
look for a brace in row 0 and find one in column 2
now look for a brace in this column and find one in columnvector, rowvector:
row 2. Next look for a brace in row 2 and find one bit coded brace positions in rows 0..7, columns 0..7
in column 0 made by makeconnectionvectors from boxbrace[ ]
array;
box :
This is the column where we started, which shows
history of boxes on path, used to trace backward
that box(0,0) is rigid. If such a path from box(0,0)
on row 0 to column 0 is not found then box(0,0) is Function rigid has this little helper function:
not rigid and will be a parallellogram, type 1 in
function nextRect(var n : byte; vec : byte) : boolean;
this case. // true if brace(bit) in vector vec; n : lowest bit set in vec
begin
Why is this true? result := vec <> 0;
Looking back to previous pictures we notice that if result then
in a row all left-right edges of the boxes are begin
parallel. In a column all top-bottom edges of the n := 0;
boxes are parallel while ((1 shl n) and vec) = 0 do inc(n);
end;
Box(0,0) and box(2,0) vertical edges are parallel. end;
Box(2,0) and box(2,2) horizontal edges are parallel.
Because both boxes are braced also box(2,0) and
box(2,2) vertical edges are parallel.
Same is true for box(2,2) and box(0,2).
So, boxes(2,2) and box(0,2) have parallel edges.
So, column 0 is perpendicular to row 0 and
box(0,0) is a rectangle.
FRAME TESTING The first test is for the left-top box. If rigid, the
Testing the complete frame for rigidity is box type becomes 0, else the type is 1.
accomplished by procedure testframe. Then the next box at (1,0) is tested. This box type
It is sufficient to test only the top row boxes by depends on 1. rigidity and 2. the previous
calling function rigid. box(0,0).
This procedure also changes the frame For a rigid box, the next boxtype is precoded in
coordinates according to the box type found. contstant topcodesR[0..3]
Variables: for a non-rigid box this is topcodesNR[0..3]
var i,j : byte; // column, row Example:
bxt : byte; // box type etc. if box(0,0) is non-rigid (so type 1) and box (1,0)
topbox : array[0..7] of byte; // top row box types is rigid then box (1,0) is of type
leftbox : array[0..7] of byte; // left column box types
topcodesR[1] which is type 3.
xref,yref : smallInt; // left-top box coordinates
corr : smallInt; // correction value, shift frame
If box(0,0) is rigid and box (1,0) is non-rigid then
RFlag,CFlag : boolean; box (1,0) is of type topcodesNR[0] = 2.
The previous boxtype is the index into these
constant arrays.
So far the top boxes. The horizontal bit comes from the top box, the
At this point the bottom and top edge directions vertical bit from the left box. Afterward the frame
of all boxes are fixed. is shifted horizontally by value corr to maintain a
This means that the left- and right edges in a row left margin.
are also fixed if this row contains a braced box.
Testing continues with the left column box (0,1), SAVING AND LOADING
just below the top-left box. If this row has a braced Frames may be saved / loaded to/from disc.
box, boolean variable Cflag sets true. The data format allows for future expansion to
Source code (without code for coordinates change): frames of 32 * 32 columns/rows maximum.
Cflag := nextRect(bxt,rowvector[j]); // braced box in row? Data I/O is typed. Files have no extension.
if CFlag then The data pack consists of 37 dwords (cardinals)
begin
bxt := topbox[bxt];
bxt := ((bxt and $2) shr 1) or (leftbox[0] and $2);
end
else bxt := leftCodesNR[bxt];
POSTSCRIPT
This problem was found in the book “Graphs, an
introductory Approach” by Wilson and Watkins.
About the author
A graph in mathematics is a drawing of points David Dirkse
which may, or may be not, connected by lines. After a study of electrical engineering,
Such a drawing is abstract and may represent David joined the Control Data Corporation,
topics like: an American computer company, and worked
road maps almost 25 years installing and maintaining
networks scientific data centers in the Netherlands.
chemical molecules He has witnessed the evolution of computer
interdependent processes hardware from the first transistorized
mainframes (CDC3300) to the supercomputers
There are many varieties of graphs, one being a so of the eighties (CYBER205). During this period
called bipartite graph where lines connect he attended over 100 technical courses and
was instructor in over 30 occasions. At the
between 2 groups of points without lines between
decline of CDC around 1990, David started a
points in the same group. study of mathematics and became a math
Also graphs may have several properties one teacher in 1993. One of his hobbies is
being connected. This means that using programming, specializing in puzzle solving,
connecting lines travel from a point to any other drawing and basic algorithms.
point is possible.
When the project is created, you can find its unique ID under project settings:
1. AdvFirebaseObjectDatabase1.DatabaseName := 'TMS';
2. AdvFirebaseObjectDatabase1.TableName := 'Customers';
3. AdvFirebaseObjectDatabase1.Connect;
TFireBasePicture = class(TPicture)
2. private
3. function GetDataString: string;
4. procedure SetDataString(const Value: string);
5. published
6. property DataString: string read GetDataString write SetDataString;
7. end;
8.
9.
10. { TFireBasePicture }
11.
12. function TFireBasePicture.GetDataString: string;
13. var
14. ms: TMemoryStream;
15. begin
16. ms := TMemoryStream.Create;
17. try
18. SaveToStream(ms);
19. Result := StreamToHex(ms);
20. finally
21. ms.Free;
22. end;
23. end;
24.
25. procedure TFireBasePicture.SetDataString(const Value: string);
26. var
27. ms: TMemoryStream;
28. begin
29. ms := HexToStream(Value);
30. try
31. LoadFromStream(ms);
32. finally
33. ms.Free;
34. end;
35. end;
Inspecting this on the This performs a query on the List table for value
Google Firebase console results in: 'Bart' set in the 'Name' field. The result of the
query is a generic list (in case multiple matching
results are found).
CONCLUSION
This was a glimpse at the TAdvFirebaseObjectDataBase
component as an introduction for the new Google
Firebase access features in the TMS VCL Cloud Pack and
TMS FMX Cloud Pack.
Storing all kinds of data from desktop applications,
mobile apps or web applications in the cloud opens
numerous new possibilities for sharing data.
Explore the full set of powerful capabilities of
TAdvFirebaseObjectDataBase and the many other
components in TMS Cloud Pack and TMS FMX Cloud Pack
to make consuming cloud services in Delphi &
C++Builder a piece of cake.
1. var
2. c: TFirebaseObjectList;
3. I: Integer;
4.
5. begin
6. AdvFirebaseObjectDatabase1.TableName := 'List';
7. c:= AdvFirebaseObjectDatabase1.QueryList('Name', 'Bart');
8. if Assigned(c) then
9. begin
10. for I := 0 to c.Count - 1 do
11. begin
12. ShowMessage((c[I] as TSimpleClass).Score.ToString);
13. c[I].Free;
14. end;
15. c.Free;
16. end;
17. end;
INTRODUCTION
In the previous article I introduced you to some basic
video playback, and processing. I mainly And drop it on the form:
demonstrated geometric transformations of the Double click on the component to open the File
image.
Open Dialog. In the File Open Dialog , select a
The geometric transformations are very exciting, but
they are only one type of video filtering. VideoLab video file to play, and click the “Open” button:
contains many more filtering and transformation
components, and in this article we will continue to
explore them.
There are many different types of filters in
VideoLab, but they tend to performs one of few
typical tasks. In the previous article we used filter
performing Geometric transformations, by
changing the locations of the pixels. Another
common type of filters is to calculate the value of
each pixel based on the values of the surrounding
pixels usually in rectangular region called kernel.
Pixel
Surrounding Pixels
Rectangular Kernel
Switch to the “Open Wire” tab, and connect the Kernel filters are only one type of filters.
“Video” Output Pin of the VLAVIPlayer1 to the Sometimes we simply need to change the color of
“Video” Input Pin of the each pixel without looking at the surrounding
VLRectKernelFilter1. pixels. VideoLab contains such filters too.
Next connect the “Video” Output Pin of the The simplest one is the Gamma Correction Filter .
VLRectKernelFilter1 to the “Video” Input Switch to the Form Designer .
Pin of the VLImageDisplay2 component: Delete the VLRectKernelFilter1. Type
“gamma” in the Tool Palette search
box, then select TVLGammaFilter
from the palette, and drop it
on the form:
1
Issue Nr 5 2017 BLAISE PASCAL MAGAZINE COMPONENTS
DEVELOPERS 4 37
REST EASY WITH KBMMW PART 1 PAGE 2/7 COMPONENTS
DEVELOPERS 4
Save your project. Saving it will prompt
Delphi to update your uses section with
required units.
Double click on the form, to create a form
OnCreate event handler.
Enter two lines of code so it looks like this:
unit Unit7;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, kbmMWCustomTransport, kbmMWServer,
kbmMWTCPIPIndyServerTransport, kbmMWRESTTransStream;
type
TForm7 = class(TForm)
kbmMWServer1: TkbmMWServer;
kbmMWTCPIPIndyServerTransport1: TkbmMWTCPIPIndyServerTransport;
var
Form7: TForm7;
implementation
{$R *.dfm}
end.
38 COMPONENTS
DEVELOPERS 4 Issue Nr 5 2017 BLAISE PASCAL MAGAZINE
REST EASY WITH KBMMW PART 1 PAGE 3/7 COMPONENTS
DEVELOPERS 4
Basically we now have the foundation for a REST
capable web server.
Let’s add some functionality that can be called
from any REST client.
In Delphi, Click File – New – Other –
Components4Developers Wizards and select the
kbmMW Service Wizard . Click OK .
40 COMPONENTS
DEVELOPERS 4 Issue Nr 5 2017 BLAISE PASCAL MAGAZINE
REST EASY WITH KBMMW PART 1 PAGE 5/7 COMPONENTS
DEVELOPERS 4
Browse past the explanatory remarks at the top, until you get to the actual code.
type
[kbmMW_Service('name:MyREST, flags:[listed]')]
[kbmMW_Rest('path:/MyREST')]
// Access to the service can be limited using the [kbmMW_Auth..] attribute.
// [kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')]
TkbmMWCustomSmartService8 = class(TkbmMWCustomSmartService)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
// HelloWorld function callable from both a regular client,
// due to the optional [kbmMW_Method] attribute,
// and from a REST client due to the optional [kbmMW_Rest] attribute.
// The access path to the function from a REST client (like a browser)+
// is in this case relative to the services path.
// In this example: http://.../MyREST/helloworld
// Access to the function can be limited using the [kbmMW_Auth..] attribute.
// [kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')]
[kbmMW_Rest('method:get, path:helloworld')]
[kbmMW_Method]
function HelloWorld:string;
end;
implementation
uses kbmMWExceptions;
{$R *.dfm}
// Service definitions.
//---------------------
function TkbmMWCustomSmartService8.HelloWorld:string;
begin
Result:='Hello world';
end;
{$R *.dfm}
// Service definitions.
//---------------------
function TkbmMWCustomSmartService8.HelloWorld:string;
var
o:TkbmMWONObject;
jsonstreamer:TkbmMWJSONStreamer;
begin
o:=TkbmMWONObject.Create;
jsonstreamer:=TkbmMWJSONStreamer.Create;
o.AsString['result']:='Hello world';
Result:=jsonstreamer.SaveToUTF16String(o);
jsonstreamer.Free;
o.Free;
end;
This allows you to create complex JSON documents pretty easily. The cool part is that since we use
kbmMW’s object notation framework, we could have chosen to stream it as XML or YAML or BSON or
MessagePack instead by simply instantiating the appropriate streamer.
The automated way:
type
TMyResult = class
private
FResult:string;
public
property Result:string read FResult write FResult;
end;
[kbmMW_Service('name:MyREST, flags:[listed]')]
[kbmMW_Rest('path:/MyREST')]
// Access to the service can be limited using the [kbmMW_Auth..] attribute.
// [kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')]
TkbmMWCustomSmartService8 = class(TkbmMWCustomSmartService)
private
[kbmMW_Rest('method:get, path:helloworld, anonymousResult:true')]
[kbmMW_Method]
function HelloWorld:TMyResult;
end;
implementation
uses kbmMWExceptions;
{$R *.dfm}
// Service definitions.
//---------------------
function TkbmMWCustomSmartService8.HelloWorld:TMyResult;
begin
Result:=TMyResult.Create;
Result.Result:='Hello world';
end;
initialization
TkbmMWRTTI.EnableRTTI(TkbmMWCustomSmartService8);
kbmMWRegisterKnownClasses([TMyResult]);
end.
42 COMPONENTS
DEVELOPERS 4 Issue Nr 5 2017 BLAISE PASCAL MAGAZINE
REST EASY WITH KBMMW PART 1 PAGE 7/7 COMPONENTS
DEVELOPERS 4
The automated way simply means returning an kbmMW also understands returning
object with the desired information. TkbmMemTable instances, arrays and many other
types of information, so it is really easy to REST’
kbmMW will automatically convert the object to if your kbmMW business functionality with almost
JSON (because we are using the REST streamformat). no lines of additional code.
To make sure that kbmMW knows about the object As a final comment, since the HelloWorld
type, we register it via the method is also tagged with the attribute
kbmMWRegisterKnownClasses. [kbmMW_Method], it is also callable by native
If we didn’t, kbmMW would complain that it does kbmMW clients.
not know about the object.
Do not worry about the TMyResult instance kbmMW also understands returning
being leaked. kbmMW will automatically free it TkbmMemTable instances, arrays and many other
when it goes out of scope. If you specifically do types of information, so it is really easy to REST’
not want the returned object to be freed by if your kbmMW business functionality with almost
kbmMW, you can tell so by including no lines of additional code.
freeResult:false in the kbmMW_Rest attribute As a final comment, since the HelloWorld
for the HelloWorld method. method is also tagged with the attribute
Also notice that the kbmMW_Rest attribute now [kbmMW_Method], it is also callable by native
includes anonymousResult:true. kbmMW clients.
This tells kbmMW that we want the resulting
Because of the importance of the subject we will
JSON to be anonymous. If we didn’t include
create a series of articles that will hopefully make it
that attribute setting, the result would have clear for you how you might handle rest and what it
looked like this: really can do for you.
{"TMyResult":{"Result":"Hello world"}} Kim wrote a number of articles about this and we are
Which is not necessarily wrong, but different. publishing at least 1 or two in each issue.
There are lots of control options of how the object For now are planned:
should be streamed by setting various attributes REST easy with kbmMW #2 – Database
on it. One can for example choose that the Result REST easy with kbmMW #3 – SSL
REST easy with kbmMW #4 – Access management
property should be returned under a different
REST easy with kbmMW #5 – Logging
name etc. It might well be that new items will be published as
well.
THE
COMPONENTS
DEVELOPERS 4 DX
EESB, SOA,MoM, EAI TOOLS FOR INTELLIGENT SOLUTIONS. kbmMW IS THE PREMIERE N-TIER PRODUCT FOR DELPHI /
C++BUILDER BDS DEVELOPMENT FRAMEWORK FOR WIN 32 / 64, .NET AND LINUX WITH CLIENTS RESIDING ON WIN32 / 64, .NET, LINUX, UNIX
MAINFRAMES, MINIS, EMBEDDED DEVICES, SMART PHONES AND TABLETS.