Using Mathgl in Lazarus with free pscal compiler

126 views
Skip to first unread message

Robert Vertnik

unread,
Jul 8, 2015, 7:21:37 AM7/8/15
to mat...@googlegroups.com


Hi!

I would like to use Mathgl in Lazarus IDE with free pascal compiler. I have problems with the
following code:

procedure TForm1.Button1Click(Sender: TObject);
var
  gr: HMGL;
begin
  mgl_begin();
  gr:=mgl_create_graph(600,400);
  mgl_end();
end;

The program return an error: Project raised exception class 'External: ?'. It seems to be the problem
with the function mgl_create_graph.
I have tried the functions mgl_check_version and mgl_rnd and both works just fine.

Thanks, Robert

mathgl....@gmail.com

unread,
Jul 8, 2015, 7:25:18 AM7/8/15
to mat...@googlegroups.com

Dear Robert,
most probably you forgot to add linking of mathgl library, i.e. something like -lmgl in linking page.

8 Июл 2015 г. 14:21 пользователь "Robert Vertnik" <robert....@gmail.com> написал:
--
You received this message because you are subscribed to the Google Groups "MathGL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathgl+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Vertnik

unread,
Jul 8, 2015, 8:16:23 AM7/8/15
to mat...@googlegroups.com
In Delphi or Lazarus, we add mgl_pas.pas into the project and libmgl.dll into the project directory. So, I don't need to
put nothing in the linker settings of my project.

The project is compiled without any errors. When I am using the following functions in my code
mgl_srnd
mgl_rnd
mgl_check_version
mgl_create_parser
the programs works just fine, without any problems.

When I want to use mgl_create_graph function, the program returns an error: Project raised exception class 'External: ?'.
The interesting thing is, when I run the program outside the IDE (in explorer). Then I got the following message: Control-C hit.

Robert

Dne sreda, 08. julij 2015 13.21.37 UTC+2 je oseba Robert Vertnik napisala:

Robert Vertnik

unread,
Jul 8, 2015, 8:17:02 AM7/8/15
to mat...@googlegroups.com
In Delphi or Lazarus, we add mgl_pas.pas into the project and libmgl.dll into the project directory. So, I don't need to
put nothing in the linker settings of my project.

The project is compiled without any errors. When I am using the following functions in my code
mgl_srnd
mgl_rnd
mgl_check_version
mgl_create_parser
the programs works just fine, without any problems.

When I want to use mgl_create_graph function, the program returns an error: Project raised exception class 'External: ?'.
The interesting thing is, when I run the program outside the IDE (in explorer). Then I got the following message: Control-C hit.

Robert

Dne sreda, 08. julij 2015 13.25.18 UTC+2 je oseba Alexey Balakin napisala:
Message has been deleted

Robert Vertnik

unread,
Jul 8, 2015, 4:46:01 PM7/8/15
to mat...@googlegroups.com
I found the problem. Everything works ok with libmgl.dll for versions up to 2.3.1. For latest versions, 2.3.2 and 2.3.3, the mgl_create_graph function in Lazarus doesn't work.
I think that the same situation is in Delphi.

I hope you will check mgl_pas.pas or libmgl.dll to find the bugs.

by,

Robert

Dne sreda, 08. julij 2015 14.17.02 UTC+2 je oseba Robert Vertnik napisala:

mathgl....@gmail.com

unread,
Jul 9, 2015, 1:53:07 AM7/9/15
to mat...@googlegroups.com

Dear Robert,

Unfortunately, I'm far from computer and could check it at the end of the month only.

8 Июл 2015 г. 23:41 пользователь "Robert Vertnik" <robert....@gmail.com> написал:
I found the problem. Everything works ok with libmgl.dll for versions up to 2.3.1. For latest versions, 2.3.2 and 2.3.3, the mgl_create_graph function in Lazarus doesn't work.
I think that the same situation is in Delphi.

I hope you will check mgl_pas.pas or libmgl.dll to find the bugs.

by,

Robert 

Dne sreda, 08. julij 2015 14.17.02 UTC+2 je oseba Robert Vertnik napisala:
In Delphi or Lazarus, we add mgl_pas.pas into the project and libmgl.dll into the project directory. So, I don't need to

Arne Geppert

unread,
Jun 29, 2024, 10:34:40 AM6/29/24
to MathGL
Just an solution that might be helpful just like it was for me, when I tried to use MathGL with Lazarus 3.2/Free Pascal recently (problem was still existent with MathGL 8.0.1 under Win10 64Bit):

program DrawSinCurve;

uses
  Math,
  mgl_pas;

procedure main;
var
  gr: HMGL;
begin
  gr := mgl_create_graph(600, 400);
  mgl_fplot(gr, 'sin(pi*x)', '', '');
  mgl_write_frame(gr, 'sinus_curve.bmp', '');
  mgl_write_frame(gr, 'sinus_curve.svg', '');
  mgl_write_frame(gr, 'sinus_curve.png', '');
  mgl_delete_graph(gr);
  writeln('Sinuscurve written to "sinus_curve.png+svg+png".');
end;

begin
  // Solution from mathias at https://www.lazarusforum.de/viewtopic.php?f=9&t=15810&sid=7b02c50e031680dbbfee697907cf60ba
  SetExceptionMask([exDenormalized, exInvalidOp, exOverflow, exPrecision, exUnderflow, exZeroDivide]);
  main;
end. 
Reply all
Reply to author
Forward
0 new messages