# Lazarus

## Free Pascal => Beginners => Topic started by: giahung1997 on June 21, 2019, 10:58:39 am

Title: pas2jni TClass error
Post by: giahung1997 on June 21, 2019, 10:58:39 am
Code: Pascal  [Select][+][-]
1. unit Unit1;
2.
3. {\$mode objfpc}{\$H+}
4.
5. interface
6.
7. uses
8.   Classes, SysUtils, math;
9.
10. function isNarcissistic(num: integer): boolean;
11. function ProperDivisors(num: integer): integer;
12. function UglyNumber(num: integer): boolean;
13.
14. implementation
15.
16. function isNarcissistic(num: integer): boolean;
17. var
18.   k, n, sum: integer;
19. begin
20.   if num <= 0 then result:= false
21.   else begin
22.     k:= trunc(log10(num)) + 1;
23.     n:= num;
24.     sum:= 0;
25.     while n > 0 do
26.       begin
27.         sum:= sum + trunc(intpower(n mod 10, k));
28.         n:= n div 10;
29.       end;
30.     result:= sum = num;
31.   end;
32. end;
33.
34. function ProperDivisors(num: integer): integer;
35. var
36.   i: integer;
37. begin
38.   result:= 0;
39.   if num <= 0 then result:= -1
40.   else if num = 1 then result:= 0
41.   else for i:= 1 to num div 2 do if num mod i = 0 then result:= result + i;
42. end;
43.
44. function UglyNumber(num: integer): boolean;
45. begin
46.   result:= true;
47.   if num <= 0 then result:= false
48.   else begin
49.     while num <> 1 do
50.     begin
51.       if num mod 2 = 0 then num:= num div 2
52.       else if num mod 3 = 0 then num:= num div 3
53.       else if num mod 5 = 0 then num:= num div 5
54.       else begin
55.         result:= false;
56.         break;
57.       end;
58.     end;
59.   end;
60. end;
61.
62. end.
63.
64.

Quote
Quote
Quote
Quote

fpc unit1jni.pas successful with no errors

Both above give the same result. Error when run javac system.java and javac unit1.java

If I use the eclipse ecj compiler which allow compilation of source files have errors and pack it using jar tool:
Quote
jar -cvf pas.jar system.class unit1.class
it will give me a pas.jar file which later I could add to my Java project and it will compile and run flawlessly.