Skip to content

Commit

Permalink
Added a simple Delphi FMX example for how to create a server/client s…
Browse files Browse the repository at this point in the history
…treamed CRUD.
  • Loading branch information
silvioclecio committed May 7, 2021
1 parent e549b4e commit 67a9de3
Show file tree
Hide file tree
Showing 24 changed files with 3,234 additions and 24 deletions.
6 changes: 6 additions & 0 deletions Examples/Console/Delphi/CRUDClient/Client.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ interface
FireDAC.Comp.Client,
FireDAC.Stan.StorageBin;

function NewGuid: string;
function ListPersons(const AURL: string): TDataSet;
procedure SavePersons(const AURL: string; ADataSet: TDataSet);
function CreatePersonsDataSet: TDataSet;

implementation

function NewGuid: string;
begin
Result := TGuid.NewGuid.ToString;
end;

function CreateDataSet: TFDMemTable;
begin
Result := TFDMemTable.Create(nil);
Expand Down
7 changes: 2 additions & 5 deletions Examples/Console/Delphi/CRUDClient/crudclient.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ program crudclient;
{$ENDIF}

uses
System.SysUtils,
System.Classes,
Data.DB,
Client;

Expand Down Expand Up @@ -60,10 +58,9 @@ begin
VDataSet := CreatePersonsDataSet;
VField := VDataSet.FieldByName('name');
VDataSet.Append;
VField.AsString := 'Person ' + TThread.GetTickCount.ToString;
Sleep(100);
VField.AsString := 'Person ' + NewGuid;
VDataSet.Append;
VField.AsString := 'Person ' + TThread.GetTickCount.ToString;
VField.AsString := 'Person ' + NewGuid;
SavePersons(URL_SERVER, VDataSet);
end;

Expand Down
1 change: 1 addition & 0 deletions Examples/Console/Delphi/CRUDServer/Persistence.pas
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ procedure SavePersons(const ABytes: TBytes);
try
VQuery.LoadFromStream(VData, sfBinary);
VQuery.ApplyUpdates;
DBConnection.Commit;
finally
VQuery.Destroy;
VData.Free;
Expand Down
7 changes: 6 additions & 1 deletion Examples/Console/FPC/CRUDClient/Client.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ interface
BufDataset,
FPHTTPClient;

function NewGuid: string;
function ListPersons(const AURL: string): TDataSet;
procedure SavePersons(const AURL: string; ADataSet: TDataSet);
function CreatePersonsDataSet: TDataSet;

implementation

function NewGuid: string;
begin
Result := TGuid.NewGuid.ToString(True);
end;

function ListPersons(const AURL: string): TDataSet;
var
VData: TStream;
Expand Down Expand Up @@ -83,7 +89,6 @@ function CreatePersonsDataSet: TDataSet;
Result := TBufDataset.Create(nil);
Result.FieldDefs.Add('name', ftString, 100);
TBufDataset(Result).CreateDataSet;
Result.Open;
end;

end.
7 changes: 3 additions & 4 deletions Examples/Console/FPC/CRUDClient/crudclient.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
{$WARN 5062 OFF}

uses
SysUtils,
DB,
Client;

Expand Down Expand Up @@ -59,14 +58,14 @@ procedure AddRandomPersons;
VDataSet := CreatePersonsDataSet;
VField := VDataSet.FieldByName('name');
VDataSet.Append;
VField.AsString := 'Person ' + GetTickCount64.ToString;
Sleep(100);
VField.AsString := 'Person ' + NewGuid;
VDataSet.Append;
VField.AsString := 'Person ' + GetTickCount64.ToString;
VField.AsString := 'Person ' + NewGuid;
SavePersons(URL_SERVER, VDataSet);
end;

begin
Randomize;
ListAllPersons;
AddRandomPersons;
ListAllPersons;
Expand Down
30 changes: 27 additions & 3 deletions Examples/FMX/AllExamples.groupproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<ProjectGuid>{377E5935-27FE-4230-B355-B60A09F2042E}</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<Projects Include="CRUDClient\CRUDClient.dproj">
<Dependencies/>
</Projects>
<Projects Include="CRUDServer\CRUDServer.dproj">
<Dependencies/>
</Projects>
<Projects Include="HTTPAuth_Example.dproj">
<Dependencies/>
</Projects>
Expand Down Expand Up @@ -44,6 +50,24 @@
<Default.Personality/>
</BorlandProject>
</ProjectExtensions>
<Target Name="CRUDClient">
<MSBuild Projects="CRUDClient\CRUDClient.dproj"/>
</Target>
<Target Name="CRUDClient:Clean">
<MSBuild Projects="CRUDClient\CRUDClient.dproj" Targets="Clean"/>
</Target>
<Target Name="CRUDClient:Make">
<MSBuild Projects="CRUDClient\CRUDClient.dproj" Targets="Make"/>
</Target>
<Target Name="CRUDServer">
<MSBuild Projects="CRUDServer\CRUDServer.dproj"/>
</Target>
<Target Name="CRUDServer:Clean">
<MSBuild Projects="CRUDServer\CRUDServer.dproj" Targets="Clean"/>
</Target>
<Target Name="CRUDServer:Make">
<MSBuild Projects="CRUDServer\CRUDServer.dproj" Targets="Make"/>
</Target>
<Target Name="HTTPAuth_Example">
<MSBuild Projects="HTTPAuth_Example.dproj"/>
</Target>
Expand Down Expand Up @@ -144,13 +168,13 @@
<MSBuild Projects="URLRouter_Example.dproj" Targets="Make"/>
</Target>
<Target Name="Build">
<CallTarget Targets="HTTPAuth_Example;HTTPCookie_Example;HTTPServer_Example;HTTPServerSSE_Example;HTTPUpload_Example;Logger_Example;MathExpression_Example;MediaTypes_Example;String_Example;StringMap_Example;URLRouter_Example"/>
<CallTarget Targets="CRUDClient;CRUDServer;HTTPAuth_Example;HTTPCookie_Example;HTTPServer_Example;HTTPServerSSE_Example;HTTPUpload_Example;Logger_Example;MathExpression_Example;MediaTypes_Example;String_Example;StringMap_Example;URLRouter_Example"/>
</Target>
<Target Name="Clean">
<CallTarget Targets="HTTPAuth_Example:Clean;HTTPCookie_Example:Clean;HTTPServer_Example:Clean;HTTPServerSSE_Example:Clean;HTTPUpload_Example:Clean;Logger_Example:Clean;MathExpression_Example:Clean;MediaTypes_Example:Clean;String_Example:Clean;StringMap_Example:Clean;URLRouter_Example:Clean"/>
<CallTarget Targets="CRUDClient:Clean;CRUDServer:Clean;HTTPAuth_Example:Clean;HTTPCookie_Example:Clean;HTTPServer_Example:Clean;HTTPServerSSE_Example:Clean;HTTPUpload_Example:Clean;Logger_Example:Clean;MathExpression_Example:Clean;MediaTypes_Example:Clean;String_Example:Clean;StringMap_Example:Clean;URLRouter_Example:Clean"/>
</Target>
<Target Name="Make">
<CallTarget Targets="HTTPAuth_Example:Make;HTTPCookie_Example:Make;HTTPServer_Example:Make;HTTPServerSSE_Example:Make;HTTPUpload_Example:Make;Logger_Example:Make;MathExpression_Example:Make;MediaTypes_Example:Make;String_Example:Make;StringMap_Example:Make;URLRouter_Example:Make"/>
<CallTarget Targets="CRUDClient:Make;CRUDServer:Make;HTTPAuth_Example:Make;HTTPCookie_Example:Make;HTTPServer_Example:Make;HTTPServerSSE_Example:Make;HTTPUpload_Example:Make;Logger_Example:Make;MathExpression_Example:Make;MediaTypes_Example:Make;String_Example:Make;StringMap_Example:Make;URLRouter_Example:Make"/>
</Target>
<Import Project="$(BDS)\Bin\CodeGear.Group.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Group.Targets')"/>
</Project>
41 changes: 41 additions & 0 deletions Examples/FMX/CRUDClient/CRUDClient.dpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(* _ _
* | |__ _ __ ___ ___ | | __
* | '_ \| '__/ _ \ / _ \| |/ /
* | |_) | | | (_) | (_) | <
* |_.__/|_| \___/ \___/|_|\_\
*
* Microframework which helps to develop web Pascal applications.
*
* Copyright (c) 2012-2021 Silvio Clecio <[email protected]>
*
* Brook framework is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Brook framework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Brook framework; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*)

program CRUDClient;

uses
System.StartUpCopy,
FMX.Forms,
DMClient in 'DMClient.pas' {Client: TDataModule},
frmMain in 'frmMain.pas' {frMain};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TfrMain, frMain);
Application.CreateForm(TClient, Client);
Application.Run;
end.
Loading

0 comments on commit 67a9de3

Please sign in to comment.