Copy text to Clipboard in Android

Copy some text to a clipboard in Android is pretty simple. Use a code snippet below:

private void CopyNumber(String someText, Context context) {
     ClipboardManager clipMan = (ClipboardManager)context
                    .getSystemService(Context.CLIPBOARD_SERVICE);
     clipMan.setText(someText);
}

context parameter is required if you want to use the function outside Activities

Open Folder Dialog in Delphi

For as you know, Delphi does not really have a standard dialog for choosing a particular folder, like OpenFolderDialog. The function below uses ShellAPI and implements exactly the desired behaviour.

function GetFolderDialog(const ACaption: string; 
                      out ADirectory: string): boolean;
const
  BIF_NEWDIALOGSTYLE = $0040;
  BIF_NONEWFOLDERBUTTON = $0200;
 BIF_USENEWUI = BIF_NEWDIALOGSTYLE or BIF_EDITBOX;
var
  pWindowList: Pointer;
  tbsBrowseInfo: TBrowseInfo;
  pBuffer: PChar;
  iOldErrorMode: cardinal;
  pIemIDList: PItemIDList;
  pShellMalloc: IMalloc;
begin
  CoInitialize(nil);
  try
    Result := false;
    ADirectory := '''';
    FillChar(tbsBrowseInfo, sizeof(tbsBrowseInfo), 0);
    if (ShGetMalloc(pShellMalloc) = S_OK) 
                   and Assigned(pShellMalloc) then begin
      pBuffer := pShellMalloc.Alloc(MAX_PATH);
      try
        with tbsBrowseInfo do begin
          hwndOwner := Application.Handle;
          pidlRoot := nil;
         pszDisplayName := pBuffer;
          lpszTitle := PChar(ACaption);
          ulFlags := BIF_USENEWUI or 
                         BIF_RETURNONLYFSDIRS or 
                         BIF_NONEWFOLDERBUTTON;
          lParam := 0;
        end;
       pWindowList := DisableTaskWindows(0);
        iOldErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
        try
          pIemIDList := ShBrowseForFolder(tbsBrowseInfo);
        finally
          SetErrorMode(iOldErrorMode);
          EnableTaskWindows(pWindowList);
        end;
        Result := Assigned(pIemIDList);
        if Result then begin
          ShGetPathFromIDList(pIemIDList, pBuffer);
          pShellMalloc.Free(pIemIDList);
          ADirectory := pBuffer;
        end;
      finally
        pShellMalloc.Free(pBuffer);
     end;
    end;
  finally
    CoUninitialize;
  end;
end;

Dynamic Programming Languages

The topic of current post is a special class of high level languages that execute dynamic programm code not known to a compile time. The key advantage of such languages is that a program and its parts written once can be later modified without recompiling the code! When can this bahaviour be useful?
Dynamic languages are widely used in web development and in games development. When a clear seperation of the fuctionality and content management is required, dynamic lanugages are of great help. For example you wrote a game and it’s obviously that it would be more better to handle the multilingual dialogs and other text in your game in such a way, that when you make changes to the content you don’t need to recompile your game.
Let’s start with PHP. It is currently one of the most popular languages in the web development sphere. PHP interpreter is typically installed as a module into a webserver like Apache and executes scripts written by programmers. There is also a standalone version of PHP, that supports GUI development. Familiar evolution process is revealed by Perl. There also exist implementations as a module and as a standalone application. Perl was first time released in 1987. It partly borrows syntax and language constructions from a set of languages like C, shell (sh), AWK and Lisp.

Looking once for a dynamic language for PDAs I came across Tcl with graphical user interface toolkit Tk. The advantage of TCl/Tk is its platform independence. A program implemented in TCL/TC can be interpreted and executed on the most popular platforms like Linux, Macintosh, Windows, Windows CE etc. The only differece is look and feel of user interface components. The early versions of TCL didn”t support OOP but nowadays there are implementations supportig the advantages of OO concept.

Another dynamic language I’d like to introduce is Python. It’s a stable and a very popular multi-paradigm programming language. Python is used in such large projects as Youtube, Zope etc. Besides Python standalone version there exists  java implementation of Python called Jython and .NET integration of Python called IronPython. In these implementations one can execute pythons scripts within java or .Net programs. Unfortunately, I found out that IronPython doesn’t work in Compact Framework because annotations aren’t fully supported in CF and IronPython rely on these libraries very strong.

A good alternative to Python is Lua. There are also implementations of this interpreter for many popular platforms. Lua integration with Java is called LuaJava and the .NET version is called Lua.NET. Lua”s interpreter is very small and very quickly. Lua is often used for games creation. The most popular games implemented in Lua are: World of Warcraft, Monkey Island 4, Parkan 2 etc. Unfortunately, the documentation for Lua leaves much to be desired.

For more information on dynamic programming languages please refer to wiki article Dynamic Programming Languages. For more information on scripting languages supported in Java visit this page.