Delphi Split String Utility

April 27, 2012 7 comments

There is no built-in Split function in Delphi, sometimes we need an easy way to perform string splitting just like PHP or Python does: “Hello World”.split(‘ ‘) would produce dynamic array [‘Hello’, ‘World’].

In Delphi you can perform that in different way, for example using TStringList separated text behavior but you need maintenance the TStrings instance each time performing splitting.

var
  Temp: TStrings;
begin
  Temp := TStringList.Create;
  try
    Temp.Text := StringReplace('Hello World', #32, #13#10, [rfReplaceAll]);
    // Process the list here
    // Temp[0] = 'Hello'
    // Temp[1] = 'World'
  finally
    Temp.Free;
  end;
end;

Compare in Python way:

list = 'Hello World'.split(' ')
# list[0] == 'Hello'
# list[1] == 'World'

Pretty short and comfort is it.
I try makes something easy in Delphi way, like this:

var
  List: IStrings;
begin
  List := SplitEx('Hello World', ' ');
  // List[0] = 'Hello'
  // List[1] = 'World'

Or more complex:

  with SplitEx('08:00-13:00, '-') do
  begin
    // Index 0: 08:00
    with SplitEx(Strings[0], ':') do
      // Index 0: 08
      // Index 1: 00
      dtStartTime.Time := EncodeTime(AsInt[0], AsInt[1], 0, 0);

    // Index 1: 13:00
    with SplitEx(Strings[1], ':') do
      // Index 0: 13
      // Index 1: 00
      dtEndTime.Time := EncodeTime(AsInt[0], AsInt[1], 0, 0);
end;

Read more…

Categories: Delphi, Uncategorized Tags: , ,

TSafeMe… BindMe

March 17, 2011 14 comments

Forget Try-Finally to make sure your TObject instance destroyed completely on exit block procedure. TSafeMe makes your code clean without worrying with underlaying memory leaks.

Common try-finally pattern, is this your usual code?

function TXServer.ServiceDelete(const ServiceID: string): IXResponse;
var
  Q_SERVICES: TORM_Q_SERVICES;
begin
  Result := TXResponse.NewResponse();

  Q_SERVICES := TORM_Q_SERVICES.Create; // create new instance
  try
    try
      Q_SERVICES.SERVICE_ID.WhereValue := ServiceID;
      Q_SERVICES.Controller.Delete;
    except
      on E: Exception do
      begin
        Result.RESP_CODE := RC_ERROR;
        Result.RESP_MSG := E.Message;
      end;
    end;
  finally
    Q_SERVICES.Free; // then relese it
  end;
end;

Now compare with this one, see TSafeMe in action: Read more…

Categories: Delphi Tags:

PowerLogic SDK

January 27, 2011 8 comments

PowerLogic SDK is a framework that help you develop desktop application with Delphi more robust and fast, the successor are under development. PowerLogic consists of Delphi expert and modular framework itself.

Its main feature is the use of MDI interface, integrated with SSO (Single Sign On), the database access layer (with mini & fast ORM), and controller based architecture (plugin).

Debug your code directly under Delphi environment, no need to be changes, use your programming style and habit because you’re 100% coding in Delphi. Compile (CTRL+F9) and Run+Debug (F9) like usually… Everything configured to be works by the PowerLogic SDK Delphi expert.

With Delphi RAD you can create desktop-based applications quickly, with PowerLogic SDK you will be more rapid!

No need to think about the menus, deploying to the file server, versioning (auto update), and do not have to worry about authentication. All have been handled automatically, you just think the business logic.

PowerLogic SDK snaps.

Bottle and gevent

December 14, 2010 2 comments

I’m new using Python, also Bottle. After learning some frameworks I decide give a chance to Bottle as web framework. Default WSGIRefServer (for development) give me some lack while refresh http get from Google Chrome fast.

I think I need replace the default one: gevent. Searching anywhere found nothing about integrating Bootle on gevent. So here is mind, feel free to correct.

from bottle import Bottle, run, ServerAdapter

myapp = Bottle()

@myapp.route('/')
def index():
    return "Hello World"

class GEventServer(ServerAdapter):
    """ Fast HTTP Server """
    def run(self, handler):
        from gevent import monkey; monkey.patch_all()
        from gevent.wsgi import WSGIServer
        WSGIServer((self.host, self.port), handler).serve_forever()

run(app=myapp, server=GEventServer, host='localhost', port=8080)
Categories: Bottle, gevent, Python

Komunitas Pascal Indonesia

May 20, 2010 3 comments

Indonesian Pascal Community is now available for unite.
Point your browser here: http://pascal-id.org

Happy Unite!

KSpoold Disinfector 1.0 – Freeware

July 19, 2007 6 comments

KSpoold Disinfector 1.0 – Freeware
Copyright © Indra Gunawan, indra_im [at] live.com
www.delphiexpert.wordpress.com

KSpoold Disinfector is a software that writen to restore Microsoft
Office files (Word, Excel, PPT etc.) from damaged file because of KSpoold virus.

KSpoold infect the docs files by mergeing these docs to the virus file,
original docs files will be delete & new file with the same name will be added
to cheating the users with new file extention: .EXE
So anytime you double click this infected file from explorer / open it using
shell api your computer will be infected too.

The software is provided “as-is,” without any express or implied warranty.
In no event shall the Author be held liable for any damages arising from
the use of the Software

The software is writen in Borland Delphi 7.
Full source-code also provided, any comments are noted of the following:

“The const SAMPLE_SIZE = 524; is taken from the following figure:

Microsoft Word & Excel using the same file header at the first 512,
so we get unique header at the first 12 byte after 512 offset
512 + 12 = 524 –> it’s my lucky number 😀 “

You can download sample of infected file by KSpoold here

And the complete source & compiled program:

kspoold-disinfector
kspoold-disinfecto…
Hosted by eSnips

Read more…

Categories: Freeware

Multimedia Framework – Interactive Designer

June 12, 2007 8 comments

Here is some interactive Designer’s interface…
Read more…

Categories: Current Works

TLogin 1.0 Standard Edition

June 4, 2007 34 comments

Torry's Delphi Pages

TLogin – simplify you to manage User Rights, add multiuser and user rights functionality to your application with just a few mouse clicks.

Allows to control the user access to your app. GUI components (menus, buttons, check boxes, radio, .., everything on your form) and to any non visual functionality. Just drag, drop and run.

With TLogin you can:
Read more…

Insight Report 2.0 – Delphi Report Component

March 21, 2007 35 comments

Insight Report is a report processing VCL Component for Delphi. This application was made for my bachelor degree final project.

One way to present information is by making reports based on data that has gone through the system process. Filtered data can be in the form of financial recapitulation, sales or purchase transactions by date, or other important information.

This Report Processing Program can be applied to all kinds of report and data formats. It can run on all versions of Microsoft Windows, except Windows 3.1.x, and is compatible with all printer brands with various resolutions. The UI/UX was inspired by Microsoft Visio.

Most visual controls are written using custom components/controls.

Compiler: Delphi 5, 6, 7 or later.

Insight Report 2.0 - Delphi Report Component

Read more…

Categories: Freeware