Halaman

Kamis, 25 Agustus 2011

Delphi : Variable Parameters, Packed Records

Variable Parameters
taken from www.chami.com
//
// FunctionWithVarArgs()
//
// skeleton for a function that
// can accept vairable number of
// multi-type variables
//
// here are some examples on how
// to call this function:
//
// FunctionWithVarArgs(
//   [ 1, True, 3, '5', '0' ] );
//
// FunctionWithVarArgs(
//   [ 'one', 5 ] );
//
// FunctionWithVarArgs( [] );
//
procedure FunctionWithVarArgs(
  const ArgsList : array of const );
var
  ArgsListTyped :
    array[0..$FFF0 div SizeOf(TVarRec)]
      of TVarRec absolute ArgsList;
  n         : integer;
begin
  for n := Low( ArgsList ) to
           High( ArgsList ) do
  begin
    with ArgsListTyped[ n ] do
    begin
      case VType of
        vtInteger   : begin
          {handle VInteger here}      end;
        vtBoolean   : begin
          {handle VBoolean here}      end;
        vtChar      : begin
          {handle VChar here}         end;
        vtExtended  : begin
          {handle VExtended here}     end;
        vtString    : begin
          {handle VString here}       end;
        vtPointer   : begin
          {handle VPointer here}      end;
        vtPChar     : begin
          {handle VPChar here}        end;
        vtObject    : begin
          {handle VObject here}       end;
        vtClass     : begin
          {handle VClass here}        end;
        vtWideChar  : begin
          {handle VWideChar here}     end;
        vtPWideChar : begin
          {handle VPWideChar here}    end;
        vtAnsiString: begin
          {handle VAnsiString here}   end;
        vtCurrency  : begin
          {handle VCurrency here}     end;
        vtVariant   : begin
          {handle VVariant here}      end;
        else          begin
          {handle unknown type here} end;
      end;
    end;
  end;
end;
Packed Records
Packed records is a way to align Delphi records. Delphi variables usually aligned at 2, 4, or 8 byte to optimize access, to make things clear, take a look at following code (taken from delphibasic.co.uk)
type
  // Declare an unpacked record
  TDefaultRecord = Record
    name1   : string[4];
    floater : single;
    name2   : char;
    int     : Integer;
  end;

  // Declare a packed record
  TPackedRecord = Packed Record
    name1   : string[4];
    floater : single;
    name2   : char;
    int     : Integer;
  end;

var
  defaultRec : TDefaultRecord;
  packedRec  : TPackedRecord;

begin
  ShowMessage('Default record size = '+IntToStr(SizeOf(defaultRec)));
  ShowMessage('Packed record size = '+IntToStr(SizeOf(packedRec)));
end;
there is more advanced usage for the record type of delphi, such as this one :
type 
   TRect = packed record
     case Integer of
       0: (Left, Top, Right, Bottom: Integer);
       1: (TopLeft, BottomRight: TPoint);
   end; 
TRect.TopLeft will map to the TRect.Left and TRect.Top, TRect.BottomRight will map to the TRect.Right and TRect.Bottom, anoher usage would be like this one :
type
   // Declare a fruit record using case to choose the
   // diameter of a round fruit, or length and height ohterwise.
   TFruit = Record
     name : string[20];
     Case isRound : Boolean of // Choose how to map the next section
       True  :
         (diameter : Single);  // Maps to same storage as length
       False :
         (length   : Single;   // Maps to same storage as diameter
          width    : Single);
   end;
when isRound is true, you could define 1 more variable, and that is the diameter:Single, and if isRound is false, you could define 2 more variable, that is length, and width

Sabtu, 20 Agustus 2011

Ubuntu : Adding new harddisk

First we need to list our hardware, is it detected yet by ubuntu? by using this command :
sudo lshw -C disk


make note of where your disk is, for example /dev/sdb


if you have gparted, then you got your self a rich partition manager, just go and choose your hardware (/dev/sdb in my example) and then new and then partition that disk

if you are using command line then there is the fdisk command

now to mount the device, simply create a new folder on your /media folder for the mount point example :
sudo mkdir /media/my_new_hd


and then to actualy mount it to the system :
sudo mount /dev/sdb /media/my_new_hd

now browse and get wild with nautilus

ah yes, to automatically mount the new HD, add the new hd to your your /etc/fstab file to something similar like this one liner :
/dev/sdb1 /media/mynewdrive ext3 defaults 0 2


**to launch editor, use sudo gedit /etc/fstab


I think i'm in love with ubuntu.. :D
unfortunately delphi is not there..
the games is not there..
but there is always lazarus ;)

ah yes, i currently running ubuntu 8.04, old i know, but that the only CD i had :D it's adequate for me to play aground with this powerful opensource OS

Have Fun everyone!

Solving Problem : using putty, connecting to Amazon EC2

There is a trick if your pem file converted to ppk (putty's private key) and the server respond is :
Server do not accept our key or something similar like that, server send public key etc..

On one blog i find that we need to open the pem file on a notepad and then add one line to the last line, so make sure you get your cursor under those texts..

One line is enough ;)

Now get to putty again, (i'm using ubuntu) so when the putty ask :"Login As" i answered Ubuntu and voila.. we get our self a great powerful cloud server

Kamis, 18 Agustus 2011

Playing with ubuntu

Playing with ubuntu fresh install, my target is to install indefero, mercurial to a vps, so i practice it using a virtual box.
the following is the commands for editing creating renaming file directory install etc, including installing the lamp and the pluf :)

  1. To rename dir or rename file using ubuntu comand line : mv
  2. To download file wget http://...
  3. To become a super user : sudo bash...
  4. To launch explorer along as super user : gksudo nautilus
  5. To restart apache : sudo /etc/init.d/apache2 restart
  6. To install sudo apt-get install package
  7. To upgrade apt : sudo apt-get upgrade
Ah yes, there are many more to explore!

Selasa, 16 Agustus 2011

Delphi : Dynamic object creation, Class Reference

A quick note for those delphi developer needs to use the dynamic object creation :
using the class reference is the good way to do it :)

a simple example :
procedure TForm1.Button1Click(Sender: TObject);
type
  CRForm = class of TForm;
var
  a: array[0..2] of CRForm;
  c: TForm;
begin
  a[0] := TForm2;
  a[1] := TForm3;
  a[2] := TForm4;

  c := TForm(a[2].Create(self));

  c.ShowModal;

  c.Free;
end;           
welcome to the power! :)
hope you could utilize this technique on your next application development adventure!

Rabu, 10 Agustus 2011

Solving : Windows Update Standalone Installer 0x80070422 The service cannot be started, either because it is disabled or because it has no enabled devices associated with it

If you stumbled that one,
you have accidentally disabled Windows Update Service, to enable the service again go to your Administrative Tools, and enables the Windows Update Service

Here is the step :
  1. Click on Windows Icon / Start Menu
  2. Administrative Tools
  3. Services
  4. Search for "Windows Update", double click on it, and then enable this service
hope this help! :)

Selasa, 09 Agustus 2011

Delphi XE : Out of memory

A great solution found by Giedrius Bauza
HKEY_CURRENT_USER – SOFTWARE – MICROSOFT – WINDOWS – INTERNET SETTINGS – ZONES
if you find Letter not Numbers, delete the Letter one.

Cheers! :)

Thank you mr. Bauza.

Rabu, 03 Agustus 2011

Delphi : Samples

Leverage your delphi skills by utilizing samples, read it, earn it, and sleep with it :D
http://www.torry.net/pages.php?id=352

regards everybody