Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-03

converting TjanSQL

17 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bisma Jayadi

Hi all...

I found TjanSQL from http://jansfreeware.com. It's a small-text-based custom database component with SQL ability. The database itself is a comma separated value (csv) text file. I think this component is better than the TSDFDataSet (separated data file) or TFDFData (fixed data format) component in Lazarus LCL since TjanSQL has query ability. So, I started to convert it to FPC (Lazarus 0.9.13).

Unfortunately, I stucked at some assembler methods in janSQLStrings.pas (FPC failed to compile). :( Because I ain't an assembler nerd, I have no clues what does the methods do and what's the best way to convert it to FPC (replace it with compatible methods in FPC or rewrite object pascal version of the methods?). I want the convertion is written fully in object pascal in order the result can be used in all FPC-supported platforms, and performance (speed) is in the second cosideration.

Is there someone would like to help me here? I thank you in advance.

Regards,

-Bee-

has Bee.ography at
http://beeography.wordpress.com

Reply by email

Michael Van Canneyt
to Bisma Jayadi
Bisma Jayadi wrote 18 lines
Hi all... I found TjanSQL from http://jansfreeware.com. It's a small-text-based custom database component with SQL ability. The database itself is a comma separated value (csv) text file. I think this component is better than the TSDFDataSet (separated data file) or TFDFData (fixed data format) component in Lazarus LCL since TjanSQL has query ability. So, I started to convert it to FPC (Lazarus 0.9.13). Unfortunately, I stucked at some assembler methods in janSQLStrings.pas (FPC failed to compile). :( Because I ain't an assembler nerd, I have no clues what does the methods do and what's the best way to convert it to FPC (replace it with compatible methods in FPC or rewrite object pascal version of the methods?). I want the convertion is written fully in object pascal in order the result can be used in all FPC-supported platforms, and performance (speed) is in the second cosideration. Is there someone would like to help me here? I thank you in advance.

If you are referring to the posstr functions, try replacing them with the PosEx() function in strutils.

Don't try to fix the assembler, it's highly dependend on how Delphi generates it's assembler.

Michael.

Reply by email

Bisma Jayadi
to Michael Van Canneyt
If you are referring to the posstr functions, try replacing them with the PosEx() function in strutils.

Finally, I succeed to compile TjanSQL class on Lazarus 0.9.13 (FPC 2.1.1 2006/03/10). These are what I did:
- I've changed the PosStr() and PosText() functions in janSQLStrings unit with the PosEx() in StrUtils unit.
- I also have add '@' operator to all procedure/ function parameters in janSQLxxx units.
- And I have to add Delphi mode directive on mwStringHashList unit, because without it FPC failed to compile the unit (because some kind of pointer things related).

And I also succeed convert the demo application using Lazarus convertion tool. But, unfortunately... though the demo application is able to run, but it can't execute any given SQL commands. Even the basic "connect to" command considered as "unknown SQL command". :(

I still didn't do any comprehensive investigation yet. But I doubt the problem is in the program logics because it works very well on Delphi. I think it's because something in the convertion process, but I don't what the exactly is.

Any kind of help will be very much appreciated. Thank you.

-Bee-

has Bee.ography at
http://beeography.wordpress.com

Reply by email

Marco van de Voort
to Bisma Jayadi
Show quoted text 6 lines
> If you are referring to the posstr functions, try replacing them with > the PosEx() function in strutils. - And I have to add Delphi mode directive on mwStringHashList unit, because without it FPC failed to compile the unit (because some kind of pointer things related).

Turn on delphi mode for the package and/or add {$mode delphi} everywhere. (big chance that you have to change the @'s back).

Without it, it is possible that you now have shortstrings in a lot of places.

Reply by email

Bisma Jayadi
to Marco van de Voort
Turn on delphi mode for the package and/or add {$mode delphi} everywhere. (big chance that you have to change the @'s back).

I just did this, turn on Delphi mode on every single unit. To make sure the class is compiled correctly, though I'd change them later to FPC_OBJFPC mode for better and cleaner syntax. But I'll do it later, after this convertion is done and the code run as expected (within Delphi mode).

Without it, it is possible that you now have shortstrings in a lot of places.

I also did this, turn on LongString mode on every single unit.

And, unfortunately... I stuck at janSQL unit (main unit of TjanSQL class) at the class constructor method. assignment, for
precise. Now, FPC can't compile it because of this. Here is the code of the class' constructor:

---
constructor TjanSQL.create;
begin
   DecimalSeparator:='.';
   FQueries:=TList.create;
   gen:=TStringList.create;
   FSQL:=TStringList.create;
   FNameSpace:=TmwStringHashList.create
               (tinyhash,HashSecondaryOne,HashCompare);
   FEParser:=TjanSQLExpression2.create;
   FEParser.onGetVariable:=getvariable; // <- here the compiler stucked!
   FrecordSets:=TjanRecordSetList.Create;
end;
---

The error message is "Incompatible type for arg no.1: Got...". If I changed the line into this

;

still FPC failed to compile. And the error message is "Variable identifier expected". Now... it can't be compiled at all. :(

I think it's because the "type incompatibility" between the getvariable() procedure in TjanSQL class and TSubExpressionEvent type in janSQLTOkenizer unit, though they both are perfectly equal. I wonder why FPC considered them incompatible. I don't know how to fix this, yet. I'll search more informations on the FPC documentation.

I'll still working on this and hope it'll be solved today because I have to do something else at the next day. Any helps will be very much appreciated. Thank you.

Regards,

-Bee-

has Bee.ography at
http://beeography.wordpress.com

Reply by email

Michael Van Canneyt
to Bisma Jayadi
Bisma Jayadi wrote 30 lines
> Turn on delphi mode for the package and/or add {$mode delphi} everywhere. > (big chance that you have to change the @'s back). I just did this, turn on Delphi mode on every single unit. To make sure the class is compiled correctly, though I'd change them later to FPC_OBJFPC mode for better and cleaner syntax. But I'll do it later, after this convertion is done and the code run as expected (within Delphi mode). > Without it, it is possible that you now have shortstrings in a lot of > places. I also did this, turn on LongString mode on every single unit. And, unfortunately... I stuck at janSQL unit (main unit of TjanSQL class) at the class constructor method. assignment, for precise. Now, FPC can't compile it because of this. Here is the code of the class' constructor: --- constructor TjanSQL.create; begin DecimalSeparator:='.'; FQueries:=TList.create; gen:=TStringList.create; FSQL:=TStringList.create; FNameSpace:=TmwStringHashList.create (tinyhash,HashSecondaryOne,HashCompare); FEParser:=TjanSQLExpression2.create; FEParser.onGetVariable:=getvariable; // <- here the compiler stucked!

try this:

   FEParser.onGetVariable:=getvariable();

?

Michael.

Reply by email

Michael Van Canneyt
to Bisma Jayadi: I just did this, turn on Delphi mode on every single unit. To make sure the class is…
Bisma Jayadi wrote 37 lines
> Turn on delphi mode for the package and/or add {$mode delphi} everywhere. > (big chance that you have to change the @'s back). I just did this, turn on Delphi mode on every single unit. To make sure the class is compiled correctly, though I'd change them later to FPC_OBJFPC mode for better and cleaner syntax. But I'll do it later, after this convertion is done and the code run as expected (within Delphi mode). > Without it, it is possible that you now have shortstrings in a lot of > places. I also did this, turn on LongString mode on every single unit. And, unfortunately... I stuck at janSQL unit (main unit of TjanSQL class) at the class constructor method. assignment, for precise. Now, FPC can't compile it because of this. Here is the code of the class' constructor: --- constructor TjanSQL.create; begin DecimalSeparator:='.'; FQueries:=TList.create; gen:=TStringList.create; FSQL:=TStringList.create; FNameSpace:=TmwStringHashList.create (tinyhash,HashSecondaryOne,HashCompare); FEParser:=TjanSQLExpression2.create; FEParser.onGetVariable:=getvariable; // <- here the compiler stucked! FrecordSets:=TjanRecordSetList.Create; end; --- The error message is "Incompatible type for arg no.1: Got...". If I changed the line into this

Can you give the whole error message ?

Michael.

Reply by email

Bisma Jayadi
to Michael Van Canneyt: Can you give the whole error message ? Michael.
Can you give the whole error message ?
FEParser.onGetVariable:=getvariable;

C:\Trash\janSQL\components\janSQL.pas(462,40) Error: Incompatible type for arg no. 1: Got "TjanSQL.getvariable(TObject,const AnsiString,var Variant,var Boolean)", expected "<procedure variable type of procedure(TObject,const ShortString,var Variant,var Boolean) of object;Register>"

-Bee-

has Bee.ography at
http://beeography.wordpress.com

Reply by email

Michael Van Canneyt
to Bisma Jayadi
Bisma Jayadi wrote 8 lines
> Can you give the whole error message ? FEParser.onGetVariable:=getvariable; C:\Trash\janSQL\components\janSQL.pas(462,40) Error: Incompatible type for arg no. 1: Got "TjanSQL.getvariable(TObject,const AnsiString,var Variant,var Boolean)", expected "<procedure variable type of procedure(TObject,const ShortString,var Variant,var Boolean) of object;Register>"

You forgot the {$H+} in jansql: the strings are different.

Michael.

Reply by email

Marco van de Voort
to Bisma Jayadi: FEParser.onGetVariable:=getvariable; C:\Trash\janSQL\components\janSQL.pas(462,40) Error:…
Show quoted text 8 lines
> Can you give the whole error message ? FEParser.onGetVariable:=getvariable; C:\Trash\janSQL\components\janSQL.pas(462,40) Error: Incompatible type for arg no. 1: Got "TjanSQL.getvariable(TObject,const AnsiString,var Variant,var Boolean)", expected "<procedure variable type of procedure(TObject,const ShortString,var Variant,var Boolean) of object;Register>"

A {$mode delphi} forgotten somewhere, or the recompile after adding delphi didn't recompile all units.

Reply by email

Bisma Jayadi
to Michael Van Canneyt: You forgot the {$H+} in jansql: the strings are different. Michael.
You forgot the {$H+} in jansql: the strings are different.

Stupid me! :D I missed the '$' in janSQL unit! :p

I wrote {H+} instead of {$H+}. Never thought that kind of mistake. I've search hints from FPC docs for hours for more "intellegent" mistake. :D

Problem solved! janSQL and the demo application run smoothly on Lazarus 0.9.13 on winXP (SP2). I'll test it on Linux using the same version of Lazarus tonight, hopefully also on FreeBSD (but I can't promise the last). And I hope at the end of this week I'll be able to place this component on FPC and Lazarus contribution section (and the wiki also).

Performance and speed comparison between Delphi and Lazarus binary output will be the next things to investigate. I need this class to be able to run fast because I plan to use it as a backend database for a web-based application.

Thank you, Michael. :)

-Bee-

has Bee.ography at
http://beeography.wordpress.com

Reply by email

Florian Klaempfl
to Michael Van Canneyt: If you are referring to the posstr functions, try replacing them with the PosEx()…
Michael Van Canneyt wrote 29 lines
On Mon, 20 Mar 2006, Bisma Jayadi wrote: > Hi all... > > I found TjanSQL from http://jansfreeware.com. It's a small-text-based > custom database component with SQL ability. The database itself is a > comma separated value (csv) text file. I think this component is > better than the TSDFDataSet (separated data file) or TFDFData (fixed > data format) component in Lazarus LCL since TjanSQL has query ability. > So, I started to convert it to FPC (Lazarus 0.9.13). > > Unfortunately, I stucked at some assembler methods in > janSQLStrings.pas (FPC failed to compile). :( Because I ain't an > assembler nerd, I have no clues what does the methods do and what's > the best way to convert it to FPC (replace it with compatible methods > in FPC or rewrite object pascal version of the methods?). I want the > convertion is written fully in object pascal in order the result can > be used in all FPC-supported platforms, and performance (speed) is in > the second cosideration. > > Is there someone would like to help me here? I thank you in advance. If you are referring to the posstr functions, try replacing them with the PosEx() function in strutils. Don't try to fix the assembler, it's highly dependend on how Delphi generates it's assembler.
This is not true. FPC can usually use inline assembler written for delphi when
{$mode delphi} and {$asmmode intel} is used.

Reply by email

Bisma Jayadi
to Florian Klaempfl
This is not true. FPC can usually use inline assembler written for delphi when {$mode delphi} and {$asmmode intel} is used.

It probably is, though when I use these modes, FPC failed to compile TjanSQL class. I couldn't fix it ('cause I ain't an assembler expert). And I also don't want it's solved this way because I need this class able to run on all FPC supported platforms. I prefer platform independen solutions, because that's the power of FPC. If I want it to run only on win32 and intel, I don't need to convert it to FPC/Lazarus. :)

-Bee-

has Bee.ography at
http://beeography.wordpress.com

Reply by email

Florian Klaempfl
to Bisma Jayadi
Bisma Jayadi wrote 11 lines
> This is not true. FPC can usually use inline assembler written for > delphi when > {$mode delphi} and {$asmmode intel} is used. It probably is, though when I use these modes, FPC failed to compile TjanSQL class. I couldn't fix it ('cause I ain't an assembler expert). And I also don't want it's solved this way because I need this class able to run on all FPC supported platforms. I prefer platform independen solutions, because that's the power of FPC. If I want it to run only on win32 and intel, I don't need to convert it to FPC/Lazarus. :)

That's a good point ;) But at least for linux/i386 it should be enough.

Reply by email

Bisma Jayadi
to Florian Klaempfl
That's a good point ;) But at least for linux/i386 it should be enough.

Since I knew FPC and the good feeling of knowing that my applications are able to run on more than 9 platforms, I prefer my applications at least can be run on 3 platforms, they are: win32-i386, linux-i386 (all distros), and macOS.

But IMO if it can target linux, I hope it will also able to target other un*x like platforms such as BSDes or sunOS with or without (small) modifications. That's why since I knew FPC/Lazarus I always think multiplatform(ly) to solve any kind of problems on my development, though I still use Delphi. Because -IMO- if the solutions is not cross platforms, than Delphi alone is a lot more worth it to be used. :)

Thank you to the FPC and Lazarus development team. You've done a great piece of work and you've made me proud as a Pascal programmer. :)

-Bee-

has Bee.ography at
http://beeography.wordpress.com

Reply by email