Recent

Author Topic: [SOLVED] Convert Delphi package  (Read 775 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 9293
Re: Convert Delphi package
« Reply #15 on: October 26, 2019, 05:40:36 pm »
Is it general problem or @Aleynikov ?
I tried to figure out what that means. I found an unjust legal case with name Aleynikov but I don't see any connection to Delphi converter. Hmmm...
Anyway, the Delphi converter fails quite often unfortunately. A dependency to a Delphi unit which is not ported for Lazarus is a common problem.
By converting unit by unit you can do the job gradually, mixing automatic and manual conversion sometimes.
Ok I can do it converting unit by unit or from underground. My question was about converting existing Delphi code.
No, converting Delphi clx code. Anyway: show us that code. Problem likely solved.
The Lazarus converter can not convert Kylix code.
Am I talking to a brick wall all day?
« Last Edit: October 26, 2019, 05:42:45 pm by Thaddy »
also related to equus asinus.

julkas

  • Sr. Member
  • ****
  • Posts: 438
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Re: [REOPENED] Convert Delphi package
« Reply #16 on: October 26, 2019, 05:58:15 pm »
Forget about my project. Give me general directions about converting Delphi package to Lazarus.
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

Thaddy

  • Hero Member
  • *****
  • Posts: 9293
Re: [REOPENED] Convert Delphi package
« Reply #17 on: October 26, 2019, 06:05:14 pm »
Forget about my project. Give me general directions about converting Delphi package to Lazarus.
If it is not a Kylix project (clx) usually the converter does a good job on Delphi packages pre D2010.
This takes minor changes in some case, but we can only help if we KNOW the the sourcecode.
In case of a  clx(Kylix) package, simple GUI things can be adapted - by hand - rather easily.

Again:  what is the package?, is it open source? Point us to it.
You are not very helpful.
« Last Edit: October 26, 2019, 06:09:30 pm by Thaddy »
also related to equus asinus.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7630
Re: [REOPENED] Convert Delphi package
« Reply #18 on: October 26, 2019, 06:12:46 pm »
Thaddy, why do you think it is CLX, I don't see any reference to clx in the screenshots ?

wp

  • Hero Member
  • *****
  • Posts: 6491
Re: [REOPENED] Convert Delphi package
« Reply #19 on: October 26, 2019, 06:13:24 pm »
Forget about my project. Give me general directions about converting Delphi package to Lazarus.
(1) Use the Delphi converter provided by Lazarus
(2) If it does not work do a manual conversion as described in https://forum.lazarus.freepascal.org/index.php/topic,46477.msg331273.html#msg331273
(3) If it does not work look at every unit of the package and fix the issues by finding the corresponding FPC/Lazarus procedures and techniques. Note that this can be a project of its own. It may be more efficient to replace the package by one which comes with Lazarus/FPC or is available as a well-tested library in the Online-Package-Manager.
« Last Edit: October 26, 2019, 06:15:21 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Thaddy

  • Hero Member
  • *****
  • Posts: 9293
Re: [REOPENED] Convert Delphi package
« Reply #20 on: October 26, 2019, 06:31:10 pm »
Thaddy, why do you think it is CLX, I don't see any reference to clx in the screenshots ?
You need glasses.... :P   :o (and a little knowledge about Delphi for Linux, a.k.a. Kylix, with an rtl called clx,  which I believe you have?)
« Last Edit: October 26, 2019, 06:34:09 pm by Thaddy »
also related to equus asinus.

Handoko

  • Hero Member
  • *****
  • Posts: 3239
  • My goal: build my own game engine using Lazarus
Re: [REOPENED] Convert Delphi package
« Reply #21 on: October 26, 2019, 07:06:09 pm »
I do not know much about Kylix nor CLX. But I really saw "FastDbDelphi-v67-Kylix-v3" in the screenshot.

wp

  • Hero Member
  • *****
  • Posts: 6491
Re: [REOPENED] Convert Delphi package
« Reply #22 on: October 26, 2019, 07:25:29 pm »
It probably means that it contains packages for Delphi 6&7 and for Kylix. This excerpt of the file list is from some Russian site which offers the units:
Quote
FastDBd6.dpk   
FastDBd7.dpk
FastDBk3.dpk
« Last Edit: October 26, 2019, 07:27:44 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wp

  • Hero Member
  • *****
  • Posts: 6491
Re: [REOPENED] Convert Delphi package
« Reply #23 on: October 26, 2019, 07:55:25 pm »
I found another page which seems to be more trustworthy than the previous one: http://www.garret.ru/fastdb.html, looks like the author's site. I downloaded the sources and was able to create a Lazarus package without any severe issues:
  • In Lazarus, go to "Package" > "New package". Give the new package the name "FastDB.lpk" and store the file in the same folder as the Delphi and Kylix packages.
  • In the package editor, "Add" the FastDB*.pas files to the package.
  • Click "Compile". Now the compiler will stop at a variety of issues, all of them (except for one) are related to the issue that the units are assumed to be for compiler mode objfcp. Therefore, whenever this happens, go to the head of each unit and add the line {$mode Delphi}.
  • There is one final issue: In unit FastDBDataset compilation stops at the identifier TArrayField which is not found. This seems to be related to some particular field type. I don't know whether the FPC implementation of TDataset supports array fields... Hoping that this is not needed you can comment this block in the "case" instruction just to continue. With this change, the package compiles successfully.
Code: Pascal  [Select]
  1. procedure TFastDbDataSet.SetFieldData(Field: TField; Buffer: Pointer);
  2. var
  3.   nCurRec : Integer;
  4.   i : Integer;
  5. begin
  6.   if Field.FieldNo >= 0 then
  7.     begin
  8.       nCurRec := PMdRecInfo(ActiveBuffer + FRecordSize)^.Bookmark;
  9.       FQuery.Skip(nCurRec - Integer(FQuery.RecNo));  // Position the record
  10.  
  11.       if Assigned (Buffer) then
  12.         with FUpdateFields[Field.FieldNo-1] do
  13.           case DsFieldTypeOfCliType[FieldType] of
  14.             ftBytes:  SetValue(Buffer, TBytesField(Field).Size);
  15.             ftString: asString := PChar(Buffer);
  16.             (*********************** NOT CONVERTED ****************
  17.             ftArray : for i:=0 to TArrayField(Field).Size-1 do
  18.                         case FieldType of
  19.                           ctArrayOfOID,
  20.                           ctArrayOfInt4,
  21.                           ctArrayOfBool,
  22.                           ctArrayOfInt1,
  23.                           ctArrayOfInt2,
  24.                           ctArrayOfInt8:
  25.                             asArrayInt8[i]   := VarAsType(TArrayField(Field).FieldValues[i], varInt64);
  26.                           ctArrayOfReal4,
  27.                           ctArrayOfReal8:
  28.                             asArrayDouble[i] := VarAsType(TArrayField(Field).FieldValues[i], varDouble);
  29.                           ctArrayOfString:
  30.                             asArrayString[i] := VarAsType(TArrayField(Field).FieldValues[i], varString);
  31.                         else
  32.                           raise EFastDbError.Create(cli_unsupported_type, Format('Field[%s] %s', [Name, GetEnumName(TypeInfo(TCliVarType), Ord(FieldType))]));
  33.                         end;
  34.             *******************************************************)
  35.           else
  36.             SetValue(Buffer, FieldSize);
  37.           end;
  38.  
  39.       DataEvent (deFieldChange, Longint(Field));
  40.     end;
  41. end;
  • Open unit "FastDBReg" and check the box "Register Unit" in the package editor
  • Install the package. Done. The two components, TFastDBSession and TFastDBQuery, are on the "Data Access" palette. All this is for Windows, I did not try Linux. And I did not test the package at runtime, try yourself...

I am attaching the modified files -- unzip to the FastDB folder (where the other pas and .dpk files are).
« Last Edit: October 26, 2019, 08:03:51 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

julkas

  • Sr. Member
  • ****
  • Posts: 438
  • KISS principle / Lazarus 2.0.0 / FPC 3.0.4
Re: [REOPENED] Convert Delphi package
« Reply #24 on: October 26, 2019, 08:13:22 pm »
@wp Thank you very much.
« Last Edit: October 27, 2019, 12:29:03 pm by julkas »
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;