Example Lazarus - Coolprop: res file

90 views
Skip to first unread message

jonas.t...@hotmail.com

unread,
Feb 23, 2022, 8:15:58 AM2/23/22
to coolprop-users
Hello,

I succesfully used Coolprop in my Python scripts and now I try to use Coolprop in Lazarus.
Therefore I followed the instructions given on Delphi Wrapper — CoolProp 6.4.2dev documentation.

However, when running the program, following message is displayed:
Error: Can't open resource file "C:\Users\..\Desktop\LazCoolp32\CoolPropDelphiExample.res"

Help me to solve this issue is greatly appreciated!
I am not a developper, I concentrate on using tools such as Python, Coolprop and LAzarus to develop thermodynamic simulation models.

Thanks!
Jonas

jonas.t...@hotmail.com

unread,
Mar 2, 2022, 1:34:02 PM3/2/22
to coolprop-users
Hi,
I tried to make Coolprop work in Lazarus. Therefore, I downloaded the shared library files from CoolProp - Browse /CoolProp/6.4.1/shared_library/Windows at SourceForge.net
for 64 bit, 32 bit, 32 bit_cdecl and 32bit_ctdcall.
I noticed that in the 32bit folder, Coolprop.dll is missing.
My computer is 64bit, Windows 10.

I simplified the example program I got from Delphi Wrapper — CoolProp 6.4.2dev documentation and wrote it both as a simple program and as an application.
For the 64 bit trial, both give the error that PropsSI@32 can not be located in the dll, if I execute the exe files from the command prompt. For all the 32bit versions, I get the message that the application was unable to start correctly. I omitted the lines {$APPTYPE CONSOLE} and {$R *.res}. I believe the res file is only needed when using a form?

Any idea what goes wrong here?

As a simple program

program project3;

CONST
  COOL_PROP = 'CoolProp.dll';

function PropsSI(Output: PAnsichar; Name1: PAnsichar; Prop1: Double; Name2: PAnsichar; Prop2: Double; FluidName: PAnsichar): Double; stdcall; external COOL_PROP name '_PropsSI@32';

var
  p: Double;
begin
    p := PropsSI('P', 'T', 300, 'D', 1, 'Propane');
end.  

As an application:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Windows;

CONST
  COOL_PROP = 'CoolProp.dll';

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private

  public

  end;

  function PropsSI(Output: PAnsichar; Name1: PAnsichar; Prop1: Double; Name2: PAnsichar; Prop2: Double; FluidName: PAnsichar): Double; stdcall; external COOL_PROP name '_PropsSI@32';

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
p: Double;
begin
  p := PropsSI('P', 'T', 300, 'D', 1, 'Propane');
end;

end.                      

Both give the error:
Schermafbeelding 2022-03-02 191504.png

Op woensdag 23 februari 2022 om 14:15:58 UTC+1 schreef jonas.t...@hotmail.com:

jonas.t...@hotmail.com

unread,
Mar 3, 2022, 11:17:54 AM3/3/22
to coolprop-users
Hi,

The problem I encountered while trying to use Coolprop in Lazarus (www.lazarus-ide.org) has been solved:
Using the 64 bit dll you don't need the decorated function name. This means that "name '_PropsSI@32'" can be omited from the folowing:
function PropsSI(Output: PAnsichar; Name1: PAnsichar; Prop1: Double; Name2: PAnsichar; Prop2: Double; FluidName: PAnsichar): Double; stdcall; external COOL_PROP name '_PropsSI@32';

Compared to the original example (www.coolprop.org/dev/coolprop/wrappers/DelphiLazarus/index.html) I omitted {$APPTYPE CONSOLE} and {$R *.res}, and wrote it as an application with a form containing a Button and a label.

Many thanks for providing a solution to this problem Ian!

So my Lazarus application looks like this now:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Windows;

CONST
  COOL_PROP = 'CoolProp.dll';

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;

    procedure Button1Click(Sender: TObject);
  private

  public

  end;


  function PropsSI(Output: PAnsichar; Name1: PAnsichar; Prop1: Double; Name2: PAnsichar; Prop2: Double; FluidName: PAnsichar): Double; stdcall; external COOL_PROP;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
p: Double;
begin
  //p := PropsSI('P', 'T', 300, 'D', 1, 'Propane');
  //p := PropsSI('U', 'T', 0 + 273.15, 'P', 100000, 'H2');
  p := PropsSI('P', 'U', 2448120.732138102, 'D', 0.08870773197410725, 'H2');
  label1.caption := floattostr(p);
end;

end.       





Op woensdag 2 maart 2022 om 19:34:02 UTC+1 schreef jonas.t...@hotmail.com:
project1.lpi
project1.lpr
project1.lps

jonas.t...@hotmail.com

unread,
Mar 3, 2022, 12:28:00 PM3/3/22
to coolprop-users
Here are the files from  Delphi Wrapper — CoolProp 6.4.2dev documentation in a modified version for 64bit.
The dll for 64bit (CoolProp.dll) that needs to be put in the same folder can be downloaded from CoolProp - Browse /CoolProp/6.4.1/shared_library/Windows/64bit at SourceForge.net.

CoolPropDelphiExample64bit.lps
CoolPropDelphiExample64bit.lpi
CoolPropDelphiExample64bit.lpr
Reply all
Reply to author
Forward
0 new messages