Recent

Author Topic: jSpinner functions Clear() and Add() work only in OnCreate event  (Read 325 times)

neuro

  • Jr. Member
  • **
  • Posts: 94
jSpinner functions Clear() and Add() work only in OnCreate event
« on: November 03, 2025, 03:32:17 pm »
jSpinner functions Clear() and Add() work only in OnCreate event:
Code: Pascal  [Select][+][-]
  1. TAndroidModule1.AndroidModule1Create(Sender: TObject);
  2. begin
  3.   jSpinner1.Items.Clear(); // <-- works ok
  4.   jSpinner1.Items.Add('hello');  // <-- works ok
  5.   jSpinner1.Items.Add('world');  // <-- works ok
  6. end;

jSpinner functions Clear() and Add() do not work when App is running:
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. begin
  3.   jSpinner1.Items.Clear(); // <-- does not work
  4.   jSpinner1.Items.Add('hello');  // <-- does not work
  5.   jSpinner1.Items.Add('world');  // <-- does not work
  6. end;

How to fix this problem?

LAWM program code has two files:
Quote
C:\fpcupdeluxe\ccr\lamw\android_wizard\smartdesigner\java\jSpinner.java
C:\fpcupdeluxe\ccr\lamw\android_wizard\smartdesigner\java\jSpinner_new.java
Why there are two files instead of one?
« Last Edit: November 03, 2025, 09:07:15 pm by neuro »

neuro

  • Jr. Member
  • **
  • Posts: 94
Re: jSpinner functions Clear() and Add() work only in OnCreate event
« Reply #1 on: November 04, 2025, 05:56:22 pm »
I have found out how to fix the problem.
You need to use two different program codes for 1) OnCreate event and 2) when app is already running.

In OnCreate event the program code should be like this:
Code: Pascal  [Select][+][-]
  1.   jSpinner1.Items.Clear(); // <-- works only in OnCreate event, does not work when app is already running
  2.   jSpinner1.Items.Add('hello');  // <-- works only in OnCreate event, does not work when app is already running
  3.   jSpinner1.Items.Add('world');  // <-- works only in OnCreate event, does not work when app is already running

When app is already running the program code should be without word ”Items”:
Code: Pascal  [Select][+][-]
  1.   jSpinner1.Clear(); // <-- works only when app is already running, does not work in OnCreate event
  2.   jSpinner1.Add('hello');  // <-- works only when app is already running, does not work in OnCreate event
  3.   jSpinner1.Add('world');  // <-- works only when app is already running, does not work in OnCreate event

The biggest problem with LAMW is that it uses Android components which are very different from standard Lazarus components and when you are porting program code from Windows into Android, the copy/pasted program code fails to work as expected.
Another problem with LAMW is that there are no sample projects for huge number of functions of LAMW and you need to spent massive amount of time wondering in the dark without any guidance.
« Last Edit: November 05, 2025, 03:27:53 pm by neuro »

 

TinyPortal © 2005-2018