Tag Archives: fpc

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

Basic Matrix operation in Lazarus/FreePascal

Well.. This is my first post about FreePascal (FPC)/Lazarus. I’ve been asked to create a simulation for artificial neural-network using backpropagation without using Matlab. So, I decided to use FreePascal/Lazarus to create it. Why? Because it’s challenging.. 😀

First problem that I need to overcome is how to mimic matrix arithmetic in FreePascal just like in Matlab. So, after some searching, I found satisfactory library called DynMatrix.

Download dynmatrix.zip file from here: http://paginas.fe.up.pt/~paco/pmwiki/index.php?n=DynMatrix.DynMatrix

Extract two files inside the archive, you’ll need only: dynmatrixutils.pas and dynmatrix.pas.

Use these two files in your project/form, example:

  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
  StdCtrls, Spin, math, dynmatrix, dynmatrixutils;

Now, for the example usage:
Declare a matrix variables:

  A, B: TDMatrix;

Init a matrix into all zeros with 4 rows and 3 cols:

A:=Mzeros(4, 3);

Setting a value for an element in matrix:

A.setv(row_number, col_number, the_value);  //the value is a "double" type

Getting the value of an element:

the_value:=A.getv(row_number, col_number);

Matrix addition, subtraction, multiplication and matrix power:

C:=A+1;  //add with a constant
C:=A+B;  //add with a matrix
C:=A-1;  //substraction with constant
C:=A-B;  //substract with matrix
C:=3.4 * A; //multiply with a constant
C:=A * (-4.2);  //another form of multiplication
C:=A * B;  //multiply with another matrix
C:=A**4;  //matrix power with 4
C:=A**(-1);  //can also be powered with negative number

Matrix transpose, inverse and convolution

B:=A.t;   //transpose
B:=Minv(A);  //inverse matrix
C:=Mconv(A, B); //convolution

Converting string to matrix:

A:=StringToMatrix('1 2 3; 4 5 6');  //just like Matlab, convenient isn't it?

Creating “eye” matrix:

A:=Meye(4);  //4x4 "eye" matrix

Does this library also works on Delphi? Although I have Delphi, I haven’t tried it. So, no idea, but I’ve been looking at the source code and it seems it is OK to use it on Delphi Pascal. The dependecies is only on SysUtils, math and Classes