tag:blogger.com,1999:blog-37324171129369815942023-11-15T23:22:08.732-08:00Delphi On RailsDelphi On Rails is an application/web server based on MVC and REST.Delphi On Railshttp://www.blogger.com/profile/17069615871051276306noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-3732417112936981594.post-3872130510756305622012-07-19T02:21:00.000-07:002012-07-31T02:59:41.169-07:00DOR Mobile<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgm5o35ntgKS9JpPV_BvMY748w3QUebDJyCVJRhjpcOSnznloeiJ3aNqa_t6z1V3bKw06pv3Ch_47o3wh6KQnu6ykJ-kfFE8xSg6fuiGCvN1oMz7M40w627P1gi16zq-7bIcGzfRpFZO3Rs/s1600/dor.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgm5o35ntgKS9JpPV_BvMY748w3QUebDJyCVJRhjpcOSnznloeiJ3aNqa_t6z1V3bKw06pv3Ch_47o3wh6KQnu6ykJ-kfFE8xSg6fuiGCvN1oMz7M40w627P1gi16zq-7bIcGzfRpFZO3Rs/s320/dor.png" style="cursor: move;" width="222" /></a><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Just started exploring Delphi on Rails (DOR). </span><br />
<ul>
<li><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">application/web server based on MVC and REST.</span></li>
<li><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">dorHTTPClient an easy to use http/https to replace msxml</span></li>
<li><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">dorWebsocket is a <a href="http://en.wikipedia.org/wiki/Websocket" target="_blank">websocket</a> client </span></li>
<li><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">dorXMPPClient a jabber client</span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> (you could use</span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> to connect DOR servers together )</span></li>
<li><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><a href="http://en.wikipedia.org/wiki/Lua_(programming_language)" target="_blank">LUA</a> scripting</span></li>
<li><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><a href="http://en.wikipedia.org/wiki/Redis" target="_blank">Redis</a> client</span></li>
</ul>
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span class="Apple-style-span" style="background-color: white; font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span class="Apple-style-span" style="background-color: white; font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span class="Apple-style-span" style="background-color: white; font-family: 'Courier New', Courier, monospace;">WebSocket is very HTML5 wich seems to be the new buzzword. I could think about, instead of</span><span class="Apple-style-span" style="background-color: white; font-family: 'Courier New', Courier, monospace;"> Ajax refresh hammering the server every 5 seconds, an WebSocket/message send by the server to the webpage to refresh itself. It's all available within DOR.</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">DOR Mobile is an example how to use DOR in combination with JQuery mobile. Inspired by the example <a href="http://edn.embarcadero.com/article/42016">Delphi XE2 Boilerplate DataSnap Server and jQueryMobile Client</a> by Embarcadero, I was wondering how much code was needed with DOR to create the same result. Btw </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Datasnap is not available to Delphi </span><span style="background-color: white;"><span style="font-family: 'Courier New', Courier, monospace;">Professional users.</span></span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">My conclusion: </span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">- less is more :-)</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span style="background-color: white; font-family: 'Courier New', Courier, monospace;">We first start with an basic DOR server console APP</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span><br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlfy6QdVt4Hsi7eUTSmyiW2aB2yC2usouypTh5Q6HxlzEy2n5gvUiv-oGeI4h4VDJIncczZLPllGWncfVrtZF1mWCzHO67UmnZuBwBWhHVcIgreFvn9I6iTCTDpeTPJTMt2uJTxujlhDya/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> unit WebServer;
interface
uses
dorHTTPStub, dorSocketStub;
type
THTTPConnection = class(THTTPStub)
protected
function GetPassPhrase: AnsiString; override;
procedure ProcessRequest; override;
end;
implementation
uses dorOpenSSL, WinSock;
{ THTTPConnection }
function THTTPConnection.GetPassPhrase: AnsiString;
const
PASS_PHRASE: AnsiString = 'dc62rtd6fc14ss6df464c2s3s3rt32aed4vh27d3fc321h2vfghv312';
begin
Result := PASS_PHRASE;
end;
procedure THTTPConnection.ProcessRequest;
begin
inherited;
if (ErrorCode = 404) and (Params.S['format'] = 'json') then
begin
Render(Return);
ErrorCode := 200;
end;
end;
initialization
TSocketServer.CreateServer(83, '0.0.0.0', THTTPConnection);
end.
</code></pre>
<br />
<span style="font-family: 'Courier New', Courier, monospace;">We have now completed our DOR/Rest Server, after that we have to add our controller:</span><br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlfy6QdVt4Hsi7eUTSmyiW2aB2yC2usouypTh5Q6HxlzEy2n5gvUiv-oGeI4h4VDJIncczZLPllGWncfVrtZF1mWCzHO67UmnZuBwBWhHVcIgreFvn9I6iTCTDpeTPJTMt2uJTxujlhDya/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> unit reverse_controller;
interface
uses application_controller;
type
TReverseController = class(TApplicationController)
private
public
procedure GetReverseStr_get(var value:string);
end;
implementation
uses StrUtils;
{ TReverseController }
procedure TReverseController.GetReverseStr_get(var value: string);
begin
value:=ReverseString(value);
end;
initialization
TReverseController.Register;
end.
</code></pre>
<br />
<span style="font-family: 'Courier New', Courier, monospace;">That's all fooks, the rest (what's in a name) is HTML/JAVA</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">First lets create an boilerplate for an mobile interface using: <a href="http://jquerymobile.com/">Jquery Mobile</a></span><br />
<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlfy6QdVt4Hsi7eUTSmyiW2aB2yC2usouypTh5Q6HxlzEy2n5gvUiv-oGeI4h4VDJIncczZLPllGWncfVrtZF1mWCzHO67UmnZuBwBWhHVcIgreFvn9I6iTCTDpeTPJTMt2uJTxujlhDya/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"><% function content_for_head() %>
<title><DOR Delphi On Rails></title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script>'
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
<% end %>
<% function content_for_body() %>
<div data-role="page" id="main" data-theme="a">
<div data-role="header" >
<h1>Delphi On Rails DOR</h1>
</div><!-- /header -->
<div data-role="content">
<p>Main Page</p>
<p>Click "Reverse" button to invoke DOR server method to reverse the content of the edit box</p>
<input id="valueField" type="text" value="Aa B Cc" />
<a href="#" data-role="button" id="btn_reverse">Reverse</a>
</div><!-- /content -->
</div><!-- /page -->
<% end %>
</code></pre>
<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">Now it's time to add the magic with Javascript. When the button Reverse is pressed, javascript should be called, and do an request to our DOR server.</span><br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlfy6QdVt4Hsi7eUTSmyiW2aB2yC2usouypTh5Q6HxlzEy2n5gvUiv-oGeI4h4VDJIncczZLPllGWncfVrtZF1mWCzHO67UmnZuBwBWhHVcIgreFvn9I6iTCTDpeTPJTMt2uJTxujlhDya/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <script type="text/javascript">
$(document).ready(function() {
$('#btn_reverse').click (function (){
var value = $('#valueField').val();
$.get("/reverse/getreversestr.json", {"value": value},
function (data) {$('#valueField').val(data.value)}) ;
})
});
</script>
</code></pre>
<br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>Delphi On Railshttp://www.blogger.com/profile/17069615871051276306noreply@blogger.com1