Recent

Author Topic: [SOLVED] How to add new methods to JForm.java in LAMW?  (Read 780 times)

eolandro

  • New Member
  • *
  • Posts: 18
[SOLVED] How to add new methods to JForm.java in LAMW?
« on: January 17, 2025, 05:10:38 am »
Hi!
I have written a new method for smartdesigner/java/JForm.java is something like this
Code: Java  [Select][+][-]
  1. public int SplitFileParts(Uri _toTreeUriSrc,Uri _toTreeUriDst, int _Parts) {
  2.    // Many boring code for deal with File system
  3.    return 0;
  4. }
  5.  

In android_bridges/androidwidget.pas
Code: Pascal  [Select][+][-]
  1. function jForm_SplitFileParts(env: PJNIEnv; _jform: JObject; _toTreeUriSrc: jObject; _toTreeUriDst: jObject; _Parts : integer): integer; // line code 1753
  2.  
  3. function jForm_SplitFileParts(env: PJNIEnv; _jform: JObject; _toTreeUriSrc: jObject; _toTreeUriDst: jObject; _Parts : integer): integer; // line code 5470
  4. var
  5.   jParams: array[0..2] of jValue;
  6.   jMethod: jMethodID=nil;
  7.   jCls: jClass=nil;
  8. label
  9.   _exceptionOcurred;
  10. begin
  11.   Result := -1;
  12.  
  13.   if (env = nil) or (_jform = nil) then exit;
  14.   jCls:= env^.GetObjectClass(env, _jform);
  15.   if jCls = nil then goto _exceptionOcurred;
  16.   jMethod:= env^.GetMethodID(env, jCls, 'SplitFileParts', '(Landroid/net/Uri;Landroid/net/Uri;I;)I');
  17.   if jMethod = nil then begin env^.DeleteLocalRef(env, jCls); goto _exceptionOcurred; end;
  18.  
  19.   jParams[0].l:= _toTreeUriSrc;
  20.   jParams[1].l:= _toTreeUriDst;
  21.   jParams[2].i:= _Parts;
  22.  
  23.   Result := env^.CallIntMethodA(env, _jform, jMethod, @jParams);
  24.  
  25.   env^.DeleteLocalRef(env, jCls);
  26.  
  27.   _exceptionOcurred: jni_ExceptionOccurred(env);
  28. end;                                                                                                                                    
  29.  

Also in android_bridges/androidwidget.pas  but in JForm Class
Code: Pascal  [Select][+][-]
  1. function SplitFileParts(_toTreeUriSrc: jObject; _toTreeUriDst: jObject; _Parts : integer): integer;
  2.  
  3. function jForm.SplitFileParts(_toTreeUriSrc: jObject; _toTreeUriDst: jObject; _Parts : integer): integer;
  4. begin
  5.  result := -1;
  6.   //in designing component state: result value here...
  7.   if FInitialized then
  8.    Result:= jForm_SplitFileParts(gapp.Jni.jEnv, FjObject, _toTreeUriSrc,_toTreeUriDst,_Parts);
  9. end;
  10.  

But when i execute the app in logcat a get
Code: Text  [Select][+][-]
  1. 01-16 19:43:30.592  6615  6615 W System.err: java.lang.NoSuchMethodError: no non-static method "Lorg/eospfl/appsplitfile/jForm;.SplitFileParts(Landroid/net/Uri;Landroid/net/Uri;I;)I"
  2. 01-16 19:43:30.592  6615  6615 W System.err:    at org.eospfl.appsplitfile.Controls.pOnClick(Native Method)
  3.  

if i understand this line is falling
Code: Pascal  [Select][+][-]
  1.   jMethod:= env^.GetMethodID(env, jCls, 'SplitFileParts', '(Landroid/net/Uri;Landroid/net/Uri;I;)I');
  2.  

But why?

What i'm missing?

PD: Sorry for bad english
« Last Edit: January 21, 2025, 03:37:30 am by eolandro »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2325
Re: How to add new methods to JForm.java in LAMW?
« Reply #1 on: January 18, 2025, 07:27:22 pm »
try change

Code: Pascal  [Select][+][-]
  1. (Landroid/net/Uri;Landroid/net/Uri;I;)
  2.  

to

Code: Pascal  [Select][+][-]
  1. (Landroid/net/Uri;Landroid/net/Uri;I)       //the last ";" was deleted!
  2.  
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

eolandro

  • New Member
  • *
  • Posts: 18
Re: [SOLVED] How to add new methods to JForm.java in LAMW?
« Reply #2 on: January 21, 2025, 03:39:09 am »
Yes!! thank you!!.

So Java Objects needs ";" but primitives not, Right?

 :D

jmpessoa

  • Hero Member
  • *****
  • Posts: 2325
Re: [SOLVED] How to add new methods to JForm.java in LAMW?
« Reply #3 on: February 08, 2025, 05:31:53 pm »
Quote
I have written a new method for smartdesigner/java/JForm.java is something like.....

Can you put it here?   So, I will commit it to LAMW!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018