Recent

Author Topic: Conversion from Delphi example fails  (Read 2742 times)

Wyatt Storch

  • Newbie
  • Posts: 4
Conversion from Delphi example fails
« on: February 17, 2019, 10:12:24 am »
Hello everyone, I need help converting a Delphi example code to Lazarus, and I'm new to Lazarus.

There is a really nice free project that I'd like to use in a Lazarus project.
It is an oscilloscope dll available from http://www.vclcomponents.com/Delphi/Indicators_and_Gauges/Universal_Real_Time_Software_Oscilloscope_GUI_DLL_Library-info.html

I extracted the example provided for Delphi named Delphi_7_prof, and ran Tools>Delphi Conversion>Convert Delphi Project To Lazarus Project.

The log file reads
Quote
Ssc_DLLtst.lpi Note: Added defines -dBorland -dVer150 -dDelphi7 -dCompiler6_Up -dPUREPASCAL in custom options
 Progress: Found all unit files
Ssc_DLLtst.lpr(1,20) Note: Added MODE Delphi syntax modifier after unit name.
 :
 : *** Converting unit files belonging to project/package ***
MainUnit.pas Note: Replaced unit "Windows" with "LCLIntf, LCLType, LMessages" in uses section.
MainUnit.pas(1,15) Note: Added MODE Delphi syntax modifier after unit name.
UTstTrd.pas(1,14) Note: Added MODE Delphi syntax modifier after unit name.
 :
 : *** Fixing used units and Repairing form files ***
MainUnit.pas Note: Removed property "TextHeight".
MainUnit.pas Note: Removed property "OldCreateOrder".
 Progress: Conversion took: 00:00:41
 : Conversion Ready.

On trying to compile and run, there are multiple errors but mainly they are these three repeated for every instance where they show up in the original code:
Quote
MainUnit.pas(122,14) Error: Identifier not found "LoadLibrary"
MainUnit.pas(125,26) Error: Identifier not found "GetProcAddress"
MainUnit.pas(127,10) Error: Identifier not found "FreeLibrary"

Here are some snips from the code that seem relevant:
Code: Pascal  [Select][+][-]
  1. uses
  2.   LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  3.   Dialogs, StdCtrls, Buttons, UTstTrd, ExtCtrls;
  4.  
  5.     { Public declarations }
  6.  
  7.     DllInst     : Longint; // DLL handle.    
  8.  
  9. Const
  10.  DllName : String = 'Osc_DLL.dll' + Char(0);
  11.      
  12. procedure TMainForm.BtnLoadClick(Sender: TObject);
  13. Var
  14.  Rslt : Integer;
  15.  S, S1 : String;
  16.  
  17. begin
  18.  Scopes[2] := 0;
  19.  
  20.  If (BtnLoad.Caption = 'Load Scope') then
  21.  begin
  22.   ScopeAfterOpenLib := NIL;
  23.   DllInst := LoadLibrary(PChar(DllName));
  24.    if (DllInst = 0) then  begin ShowMessage('Error DLL loading 1'); Exit; end;
  25.    
  26.    ScopeAfterOpenLib  := GetProcAddress(DllInst, 'AtOpenLib');
  27.    if (@ScopeAfterOpenLib = Nil) then
  28.    begin FreeLibrary(DllInst); ShowMessage('Error DLL loading 2'); Exit; end;
  29.                          
  30. And more, snipped out

I did some googling and in one place or another someone suggested putting Windows back in the Uses section. I tried that, then it compiled without (that) error. But when it ran, it made it to that first 'error 1', showing it didn't load the dll. Pardon my newbishness but I'm not having any luck trying to figure out what's going on or how to fix it.

I'm using Lazarus 2.0.0 r60307 FPC 3.0.4 x86_64-win64-win32/win64
on Windows 7 64 bit Version   6.1.7601 Service Pack 1 Build 7601

Thanks for any guidance you can give.

--Wyatt--

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Conversion from Delphi example fails
« Reply #1 on: February 17, 2019, 12:24:08 pm »
At first I could not download the library from the vclcomponents.com link given. Finally I found a valid one in the wayback machine: https://web.archive.org/web/20070812012558/http://www.oscilloscope-lib.com/oscilloscope_DLL.zip (what a great site!)

The conversion to Lazarus was easy (even without the built-in Delphi-to-Lazarus converter which I normally don't use):
  • Make a backup copy of the Delphi7 example folder, only work with backup versions
  • Rename the extension of the dfm file to lfm
  • Open the corresponding pas file in an external editor, change the "{$R *.dfm}" to "{$R *.lfm}"
  • In the same file, add a "{$mode Delphi}" at the top of the unit
  • Rename the *.dpr file to *.lpr
  • Open the .lpr in Lazarus, confirm to create a project from it. Add "interfaces" as first unit to "uses".
  • Compile --> success
  • Delete the Delphi files: *.ddp, *.cfg, *.dof
I am attaching my converted project. I did not want to include the dll, therefore, it still must be copied to the project folder separately.

Another note: Since this is a Delphi project from 2007 or earlier the dll is certainly 32 Bit. Therefore it works only when you create a 32-bit application. You seem to have a 64-bit compiler - you must either cross-compile to 32 bit, or install the 32-bit Lazarus (in addition to the existing installation, as "secondary installation" which will not interfere with the 64-bit installation).
« Last Edit: February 17, 2019, 12:38:55 pm by wp »

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Conversion from Delphi example fails
« Reply #2 on: February 17, 2019, 12:30:38 pm »
Wyatt, not clear just where it did run to. Did you see one of the messages "Error DLL loading 1" (or 2)  ?

If it was first, likely it is not finding the dll. Alter the showmessage to also show you the name its looking for -

ShowMessage('Error DLL loading 1 [' + DLLName + ']');

and make sure thats the right name.

I think  (I'm not a windows person) that having the dll in same directory as your lazarus files is OK. next, is it the right dll ? I'm not sure if you can use a 32bit dll on a 64bit system for example. Maybe someone else can help there ?

EDIT : WP much more helpful than my post !

« Last Edit: February 17, 2019, 12:32:46 pm by dbannon »
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Wyatt Storch

  • Newbie
  • Posts: 4
Re: Conversion from Delphi example fails
« Reply #3 on: February 17, 2019, 04:40:17 pm »
wp and dbannon, thank you so much for your replies.

I had very carefully read the .txt file that comes with this wonderful gift to the world.
Unsurprisingly, I missed right up top where the author declares it is a win32 application.
So as usual when I'm thinking I might have to reinvent something real complicated, it's because I overlooked something stupid, and it's me that's stupid.

I'll retry it and report back. THANK YOU for pointing that out.

--Wyatt--

EDIT1:

Working down the list, everything is straightforward until I get to this:
Quote
Open the .lpr in Lazarus, confirm to create a project from it. Add "interfaces" as first unit to "uses".
So the 'create project from file' doesn't take .lpr in the dialog box, but does present Mainunit.pas as one of the choices, so I tried that.
Quote
Add "interfaces" as first unit to "uses".
I was able to do that at the top of 'MainUnit'.
Quote
  you must either cross-compile to 32 bit
Apparently I can't do that ... trying to set the target cpu and OS in the options dialog tells me I can't.
Quote
install the 32-bit Lazarus (in addition to the existing installation, as "secondary installation" which will not interfere with the 64-bit installation)
I'll try that and report back.

Edit2:
Still working on 32 bit.

Thanks,
--Wyatt--

« Last Edit: February 17, 2019, 08:21:58 pm by Wyatt Storch »

Michael_Br

  • Newbie
  • Posts: 1
Re: Conversion from Delphi example fails
« Reply #4 on: November 17, 2020, 10:06:32 pm »
64-bit version of this DLL was released Nov. 16, 2020 at www.oscilloscope-lib.com
Regards

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Conversion from Delphi example fails
« Reply #5 on: November 17, 2020, 11:07:31 pm »
you added a CHR(0) to the file name. could that be the issue ?

also is the DLL in your project path or in the system folder?

and you do need to use the Windows unit
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018