Recent

Author Topic: Problems attempting to display data with jGridView  (Read 937 times)

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Problems attempting to display data with jGridView
« on: May 25, 2023, 10:47:06 pm »
Dear ALL,

I have been struggling to achieve in an Android app one of the most fundamental tasks in any user-oriented software (be it for mobile or desktop devices), namely, displaying data to the user in spreadsheet-like tabular form (like offered by the Delphi/Lazarus StringGrid and DBGrid controls).

I of course started from the basics: I attempted to modify the AppSqliteDemo3 included with LAMW to perform this task. I try to more or less replicate the nice (but unfortunately incomplete, because the author did not made available all the code) example here: https://forum.lazarus.freepascal.org/index.php?topic=39290.0 I added two jGridViews,

The app compiles and runs, but (as always!) there seems to be a problem with finding the correct layout of the two grids (the directions provided by the author of the linked example do not seem clear enough to me): the grid that should show the data is not displayed, and the grid which which should display the headers (column names) appears too large and the names of the columns do not appear well.

Could someone give me a hand?

I attach my tentative example (for what it is worth).

Thanks in advance!!!

PS As an aside, I have two questions:

I noticed that LAMW includes a jDBGridView which presumably should behave like Delphi/Lazarus DBGrid, but I could not run the demo; it there other (simple!) examples of this component?

Is there any limits (in performance, I mean) to the size and number of records of a SQLite database in Android? My real database has 12,000 (yes, twelve thousands) records and about 1 Mb in size. When I attempted to run the AppSqliteDemo3 with my database, instead of the small one provided with the demo, the app froze and then crashed.
« Last Edit: May 26, 2023, 12:41:39 pm by maurobio »
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: Problems attempting to data with jGridView
« Reply #1 on: May 26, 2023, 07:10:58 am »
From your project ".lfm"

Quote
object jGridView1: jGridView
    PosRelativeToAnchor = []
    PosRelativeToParent = [rpCenterInParent]
    LayoutParamWidth = lpFiveSixthOfParent
    LayoutParamHeight = lp48px
    LayoutParamHeight = lpOneEighthOfParent

Quote
object jGridView2: jGridView
    PosRelativeToAnchor = []
    PosRelativeToParent = [rpCenterInParent]
    LayoutParamWidth = lpFiveSixthOfParent
   LayoutParamHeight = lpOneEighthOfParent

What? 

Quote
object Button1: jButton
    PosRelativeToAnchor = [raBelow]         
    PosRelativeToParent = [rpBottom]
    LayoutParamWidth = lpOneThirdOfParent
    LayoutParamHeight = lpWrapContent

What?

The start is here:
https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/docs/GUIDesignWYSIWYG.md
https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/docs/AppHelloWorld.md


« Last Edit: May 26, 2023, 07:13:32 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: Problems attempting to data with jGridView
« Reply #2 on: May 26, 2023, 12:00:52 pm »
Hi, @jmpessoa!

Unfortunately, I could not understand your answer. Other than showing me what I already knew - that in my frantic attempts at achieving what my not be possible, I just messed up with the layout parameters of the grid - it has not been much useful.

What I need is just a simple - and fully working - example of a SQLite database being loaded into a jViewGrid, The AppSQLiteDemo3 which comes with LAMW would be in fact a good start, by simply substituting a grid for the display of each record using ShowMessage(). Can it be done? If so, how?

But in the specific case of my "real" app, it turns out that even the fancy details of layout may become irrelevant if there is no answer to my pressing question, namely: can a SQLite database with 12,000 records be realistically loaded and displayed in a jViewGrid, jListView, whatever? Because if this is not possible, than there is no sense in wasting time with it!

Best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

TRon

  • Hero Member
  • *****
  • Posts: 2503
Re: Problems attempting to data with jGridView
« Reply #3 on: May 26, 2023, 12:31:59 pm »
Unfortunately, I could not understand your answer.
I do not have any knowledge on the topic at hand but even I am able to see that the positioning of the controls (grids) is exactly the same. Thus it is no wonder you are only be able to see one ?

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: Problems attempting to display data with jGridView
« Reply #4 on: May 26, 2023, 12:45:15 pm »
Hi, @TRon!

As I wrote in my previous reply to @jmpessoa, I know that the layout is messy, but that is no longer my main concern! Layouts can be worked out sooner or later - but they are completely irrelevant if a large database cannot be realistically handled by jGridView!

Best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: Problems attempting to display data with jGridView
« Reply #5 on: May 26, 2023, 12:52:08 pm »
Dear ALL,

I just got the code below working:

Code: Pascal  [Select][+][-]
  1. procedure SplitString(Delimiter: char; Str: string; ListOfStrings: TStrings);
  2. begin
  3.   ListOfStrings.Clear;
  4.   ListOfStrings.Delimiter := Delimiter;
  5.   ListOfStrings.StrictDelimiter := True;
  6.   ListOfStrings.DelimitedText := Str;
  7. end;
  8.  
  9. procedure TAndroidModule1.PrepareGrid1;
  10. var
  11.   rows, values: TStringList;
  12.   i, j: integer;
  13. begin
  14.   if FTableName <> '' then
  15.   begin
  16.     ShowMessage('Start loading table...');
  17.     jGridView1.Clear;
  18.     jGridView1.ColCount := 8;
  19.     rows := TStringList.Create;
  20.     values := TStringList.Create;
  21.     rows.StrictDelimiter := True;
  22.     rows.Delimiter := jSqliteDataAccess1.RowDelimiter;
  23.     rows.DelimitedText := jSqliteDataAccess1.Select('SELECT * FROM ' + FTableName);
  24.     for i := 0 to rows.Count - 1 do
  25.     begin
  26.       jGridView1.AddRow(i);
  27.       //ShowMessage(rows.Strings[i]); // This is in the original AppSqliteDemo3
  28.       SplitString('|', rows.Strings[i], values); // See the declaration of SplitString above
  29.       for j := 0 to values.Count - 1 do
  30.         jGridView1.Cells[j, i] := values[j];
  31.     end;
  32.     rows.Free;
  33.     values.Free;
  34.   end;
  35. end;

As I said, this code works - but a delay in filling the grid is perceptible even if the sample database has only four columns and seven records. I very much doubt that a twelve thousand records database can be realistically displayed in this way.

With best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

TRon

  • Hero Member
  • *****
  • Posts: 2503
Re: Problems attempting to display data with jGridView
« Reply #6 on: May 26, 2023, 01:03:28 pm »
I can not really help you there as I do not have any knowledge on the Android topic (and its used classes).

Having said that, I do notice a couple of things that are related to generic programming wrt the use of stringlists and databases.

- A grid is not really suited for storing lots of content unless there is a so called virtual mode (I do not know if jgridview has one).
- You seem to load the complete database into a stringlist in one go. Normally you would make a select statement and then use .next method to advance to the next record. That way you can access each field individually (instead of the need to abuse a stringlist and the need for a splitstring function).
- If there is a DB version/variant of the jgridview then that would be better suited to display data from a database (that is why Database components/variants exist in the first place)
- Usually a stringlist and a grid have methods to tell the OS that it begins updating and ends updating their content, so that visual updates (and or other events) are not performed when adding data. That saves a considerable amount of time.
« Last Edit: May 26, 2023, 01:09:20 pm by TRon »

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: Problems attempting to display data with jGridView
« Reply #7 on: May 26, 2023, 01:14:35 pm »
Hi, @TRon!

Many of the points you raised are not really relevant to Android development. For example, there is no TStringGrid in LAMW (jGridView is its replacement instead). There is a DB-oriented version of jGridView in LAMW, but I could not run its demo, therefore resorted to jGridView.

Other than that, I simply followed the demos provided with LAMW to do my experiments (While I have some years of experience with Delphi/Lazarus under Windows/Linux, I am just starting in Android development, and it is very different at times).

Best regards,
« Last Edit: May 26, 2023, 02:06:21 pm by maurobio »
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

TRon

  • Hero Member
  • *****
  • Posts: 2503
Re: Problems attempting to display data with jGridView
« Reply #8 on: May 26, 2023, 01:57:35 pm »
For example, there is no TStringList in LAMW
uhm ?

Code: Pascal  [Select][+][-]
  1. ...
  2. procedure TAndroidModule1.PrepareGrid1;
  3. var
  4.   rows, values: TStringList;
  5. ...
  6.  

Quote
There is a DB-oriented version of jGridView in LAMW, but I could not run its demo, therefore resorted to jGridView.
It would imho be a better option to investigate that route.

Quote
I am just starting in Android development, and it is very different at times).
I am fully aware that it is not exactly the same, and I do know nothing at all about it  :).

However, As I investigated the class (https://github.com/jmpessoa/lazandroidmodulewizard/blob/master/android_bridges/gridview.pas ) I did notice you can set a rowcount in one go instead of adding a row one by one. Have you tried that ? (and then later set the items instead).

No matter the difference, I am still convinced that you should not have to first load the data from the DB into a stringlist.

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: Problems attempting to display data with jGridView
« Reply #9 on: May 26, 2023, 02:04:55 pm »
@Hi, TRon,

Sorry, I mean "there is no TStringGrid" on LAMW, of course!
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

 

TinyPortal © 2005-2018