Tag Archives: pascal

Fixing curlpas so it would compile and install in latest Lazarus/FreePascal

What is curlpas? (Taken from the official web)

CurlPas is a Delphi / Kylix / FreePascal binding and component wrapper for libcurl .

Curlpas had so many features that other internet LCL didn’t have. Such as: multi-platform, non-blocking, proxy support, SSL support, byte ranges, multiple asynchronous transfers. The most exiting part for me is that curlpas make it easier for me to understand internet/network programming (I use curl a lot in my PHP projects).

The problem is that curlpas is so old (dated 2005) and haven’t updated to reflect latest change in Lazarus IDE and FPC. So, when you try to compile it, you’ll get a lot of error messages mostly about PChar, AnsiString, WideString and Pointer. (I forgot the exact error messages).

In order to fix those errors, you have to:

  • edit file curl_h.pas line #29, from this
LIB_CURL = {$IFDEF LINUX} 'libcurl.so' {$ELSE} 'libcurl-3.dll' {$ENDIF};

into this

LIB_CURL = {$IFDEF LINUX} 'libcurl.so' {$ELSE} 'libcurl.dll' {$ENDIF};
  • edit file ocurluse.inc line #6 until #9 from this

into this (notice that I only move the H+ directive)

  • edit file ocurlcb2.inc on line #30 from
SetResultCode(curl_easy_setopt(fCurl, CURLOPT_PROGRESSDATA, Self), CURLOPT_PROGRESSDATA);

into this:

SetResultCode(curl_easy_setopt(fCurl, CURLOPT_PROGRESSDATA, pointer(Self)), CURLOPT_PROGRESSDATA);
  • and still in ocurlcb2.inc but on line #93 from
SetResultCode(curl_easy_setopt(fCurl, CURLOPT_DEBUGDATA, Self), CURLOPT_DEBUGDATA);

into this:

SetResultCode(curl_easy_setopt(fCurl, CURLOPT_DEBUGDATA, pointer(Self)), CURLOPT_DEBUGDATA);
  • and the last one to edit is ocurlini.inc line #125, from:
SetResultCode(curl_easy_setopt(fCurl, CURLOPT_PRIVATE, self), CURLOPT_PRIVATE);

into this:

SetResultCode(curl_easy_setopt(fCurl, CURLOPT_PRIVATE, pointer(self)), CURLOPT_PRIVATE);
  • save all, compile and install on your Lazarus IDE, cURL should be shown in Lazarus component palette named “Internet”

above steps had been tested on Lazarus 1.1, FPC 2.7.1 on Ubuntu Linux 12.04 and Windows 7

dynamic multidimensional array

Today I got a task to convert as C# desktop application into a Delphi XE application. One thing I learned is about dynamic multidimensional array. In C#, we can do this by just simply using one-liner “new” command and state the array dimension with it. As in Delphi, this is not the case, since all variables had to be declared far-before used.

Dynamic multidimensional array in Delphi can be declared using iterated “array of” keyword

   myInt: array of array of Integer;

Inside “begin“..”end” of a procedure/function that using the array, we can determine or change the array dimension like this:

SetLength(myInt, 3, 3);

That command will set myInt into 3×3 dimension array. Apparently, Delphi also allowed you to have a multidimensional array that has different number of column for each row, for example:

SetLength(myInt, 2);
SetLength(myInt[0], 3);
SetLength(myInt[1], 2);

The first row will made myInt array have 2 rows without specifying how may columns. Second line will set the first row to have 3 columns and third line will set the second row of myInt to have 2 columns.

To check how many row or column a multidimensional array had, you can use “Length” command

Length(myInt);           //this will return number of rows from a multidimensional array
Length(myInt[0]);        //how many columns does first row of myInt had

Destroying a dynamic multidimensional array can be done by assigning the array to nil


You can’t use dynamic multidimensional array as procedure/function parameter or result type directly. You’ll get error if you do this:

function foo(myInt: array of array of Integer): array of array of Integer;
  //do something

Instead of that, you had to define your own variable type and until then you can use it as function parameter or result type.


  TMyInt: array of array of Integer;

Using your own variable type in function:

function foo(myInt: TMyInt): TMyInt;
  //do something

Important Notes: if you work on 2 dimensional array that related to object that had table (such as stringgrid) or image/bitmap coordinate, you had to switch the term “row” and “column” I described above. Delphi use this: table_name[column, row];.

Free and lightweight hex editor for Windows 7

I’ve been looking for a free and lightweight Hex Editor in Windows for years. Many of them is not free or a shareware. Finally found one that suffice my need, it’s called XVI32 by Christian Maas.

It’s created using Delphi, super cool!!! I thought it’s created using (Visual) C++.
Moreover, it’s working on Linux flawlessly(via Wine), here’s my screenshot opening an MP4 file using XVI32 under Linux (usually I would use GHex):
XVI32 hex editor running on Linux
Although Windows 7 is not mentioned on XVI32 homepage but I assure you, it’s fully working on Windows 7 without any issue, I’m also using Windows 7 as secondary OS.

Color Cell in a stringgrid

Problem: we want to color a cell inside a TStringGrid. No easy direct way in doing this in Delphi.

Solution: we must implement stringgrid’s onDrawCell event

Create a new VCL application project. Put one TButton named btnColor and one TStringGrid named strngrd1. See the screenshot below for the placement:

delphi color cell in a stringgrid form design

This is the complete Unit1.dfm source code (so you can match the options for each components in the form):


object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 205
  ClientWidth = 280
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object strngrd1: TStringGrid
    Left = 8
    Top = 32
    Width = 257
    Height = 153
    Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing]
    TabOrder = 0
    OnDrawCell = strngrd1DrawCell
  object btnColor: TButton
    Left = 88
    Top = 1
    Width = 105
    Height = 25
    Caption = 'Color the Cell'
    TabOrder = 1
    OnClick = btnColorClick

Full form source code below (Unit1.pas):

unit Unit1;


  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;

  TForm1 = class(TForm)
    strngrd1: TStringGrid;
    btnColor: TButton;
    procedure strngrd1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure btnColorClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    { Private declarations }
    { Public declarations }
    selectedCol, selectedRow: Integer;
    colorCell: Boolean;

  Form1: TForm1;


{$R *.dfm}

procedure TForm1.btnColorClick(Sender: TObject);



procedure TForm1.FormCreate(Sender: TObject);

procedure TForm1.strngrd1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
  if colorCell then
    if ((ACol=selectedCol) and (ARow=selectedRow)) then
      strngrd1.Canvas.Brush.Color:=RGB(255,0,0); //red brush
      strngrd1.Canvas.FillRect(Rect);  //paint the backgorund red

      //draw the original text
      strngrd1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, strngrd1.Cells[ACol, ARow]);

      //draw focused rectangle if the current cell is selected by user
      if gdFocused in State then




  1. We have declared 3 public variables for this form i.e. selectedRow, selectedCol, colorCell. selectedRow and selectedCol are used for application to decide which cell that will be colored. colorCell is just a controller variable that will decide whether the stringgrid cell will be colored or not.
  2. In Form1 FormCreate event, we set colorCell to False, so, when the form is created an shown, the cell will not be colored.
  3. In btnColor onClick event, we select cell in row 1 and column 1 that will be colored. We also set the colorCell variable to True so the application know what he must done. Next we call Repaint method of strngrd1 so all cells will be re-drawn.
  4. in strngrd1 onDrawCell event, we check whether we should color the cell or not. Then check if the will-be-drawn cell is the same as stated in selectedCol and selectedRow. If True, then we defined to use red brush and then color the cell background with it using FillRect method. Then we also re-draw the text written in there (if any) using TextRect. Lastly, we draw focus rectangle (DrawFocusRect)  only if the current cell is selected by user.

This is our form result:

Our delphi color cell in stringgrid form result

That’s it. Now you know the concept behind coloring a cell in TStringGrid. If you want to color multiple cell and maintain the status (colored or not and in what color), I suggest you create some TList record variable to store this and onDrawCell will iterate through this list.