Recent

Author Topic: Newbie: First attempt at "complete" app with a few problems  (Read 2209 times)

mijen67

  • Full Member
  • ***
  • Posts: 130
  • It's hard to beat the bandwidth of a flying DVD
Newbie: First attempt at "complete" app with a few problems
« on: April 02, 2018, 05:43:42 pm »
Attached is my first attempt at a rapidly developed "complete" application.

It has a few problems but is mostly working.

In general: In my steps toward learning better programming style with Lazarus/Object pascal please give hints on how to improve structure / design of application.

Specific problems:
Noname students ... When manually navigating the stringgrid in Class form, i.e. if I keep arrow down pressed "empty" lines are added which adds noname students. How do you propose this is solved?
SOLVED by Bart: Changed goAutoAddRowSkipContentCheck from True to False (kept goAutoAddRows or user could not add rows).

Configuration file creation issue:
SOLVED by Handoko. Issue was a missing ForceDirectories() call.

Global variables ... I know, but I wanted to develop app fast. What programming style do you suggest to avoid global variables? How to keep "communication channels" between forms?

Feel free to comment on anything that doesn't seem to follow good practice etc.
« Last Edit: April 02, 2018, 09:29:16 pm by mijen67 »

Bart

  • Hero Member
  • *****
  • Posts: 3909
    • Bart en Mariska's Webstek
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #1 on: April 02, 2018, 06:42:37 pm »
Remove goAutoAddRows from the grids options.

Bart

Handoko

  • Hero Member
  • *****
  • Posts: 3759
  • My goal: build my own game engine using Lazarus
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #2 on: April 02, 2018, 06:46:43 pm »
:'( Sad, but it is true. It cannot run on my Linux 64-bit computer.

First, I got a config file error. Then a debugger exception.

mijen67

  • Full Member
  • ***
  • Posts: 130
  • It's hard to beat the bandwidth of a flying DVD
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #3 on: April 02, 2018, 06:47:50 pm »
Remove goAutoAddRows from the grids options.

Bart

Will the user then be capable of adding new rows? I think not, unless I add a button for "Add student"?


mijen67

  • Full Member
  • ***
  • Posts: 130
  • It's hard to beat the bandwidth of a flying DVD
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #4 on: April 02, 2018, 06:59:28 pm »
:'( Sad, but it is true. It cannot run on my Linux 64-bit computer.

First, I got a config file error. Then a debugger exception.

Thanks for testing!

Didn't I use forcedirectory correct? Or is it something else? Feel free to propose robust method for generating config file (and determining its location).


Bart

  • Hero Member
  • *****
  • Posts: 3909
    • Bart en Mariska's Webstek
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #5 on: April 02, 2018, 07:00:15 pm »
It's called goAutoAddRows for a reason  >:D

IIRC it will only add 1 empty row (unless you also have goAutoAddRowsSkipContentCheck in Options).
If you press "Up" in the empty row you just added, the the row will disappear again.

Bart

Handoko

  • Hero Member
  • *****
  • Posts: 3759
  • My goal: build my own game engine using Lazarus
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #6 on: April 02, 2018, 07:03:38 pm »
Didn't I use forcedirectory correct? Or is it something else? Feel free to propose robust method for generating config file (and determining its location).

Maybe you can try:

ProgramDirectory - requires unit FileUtil
Application.Location - requires unit Forms
ExtractFilePath(ParamStr(0)) - requires unit SysUtils

I heard some say ParamStr(0) may not work correctly on Linux' link.

mijen67

  • Full Member
  • ***
  • Posts: 130
  • It's hard to beat the bandwidth of a flying DVD
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #7 on: April 02, 2018, 07:10:28 pm »
It's called goAutoAddRows for a reason  >:D

IIRC it will only add 1 empty row (unless you also have goAutoAddRowsSkipContentCheck in Options).
If you press "Up" in the empty row you just added, the the row will disappear again.

Bart

Ok, got it  :D  That part is solved then.
What is IIRC?

Did the program run on your ?windows? computer? I'm trying to see if the problem reported by Handoko is Linux-only?

Handoko

  • Hero Member
  • *****
  • Posts: 3759
  • My goal: build my own game engine using Lazarus
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #8 on: April 02, 2018, 07:12:36 pm »
IIRC = if I remember correctly.

mijen67

  • Full Member
  • ***
  • Posts: 130
  • It's hard to beat the bandwidth of a flying DVD
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #9 on: April 02, 2018, 07:14:55 pm »
IIRC = if I remember correctly.

Damn ... thought it was something related to Lazarus  :D

mijen67

  • Full Member
  • ***
  • Posts: 130
  • It's hard to beat the bandwidth of a flying DVD
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #10 on: April 02, 2018, 07:32:55 pm »
Remove goAutoAddRows from the grids options.

Bart

Thanks for the hint, it got me looking in the right direction!

I had to change from:

goAutoAddRows = true
goAutoAddRowsSkipContentCheck = true

to:

goAutoAddRows = true
goAutoAddRowsSkipContentCheck = false 

If I just "removed" goAutoAddRows users couldn't add rows.

mijen67

  • Full Member
  • ***
  • Posts: 130
  • It's hard to beat the bandwidth of a flying DVD
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #11 on: April 02, 2018, 07:50:08 pm »
Didn't I use forcedirectory correct? Or is it something else? Feel free to propose robust method for generating config file (and determining its location).

Maybe you can try:

ProgramDirectory - requires unit FileUtil
Application.Location - requires unit Forms
ExtractFilePath(ParamStr(0)) - requires unit SysUtils

I heard some say ParamStr(0) may not work correctly on Linux' link.

So is conclusion that forcedirectories isn't cross-platform? or 64-bit ready? http://forum.lazarus-ide.org/index.php?topic=14747.0 or both?

Handoko

  • Hero Member
  • *****
  • Posts: 3759
  • My goal: build my own game engine using Lazarus
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #12 on: April 02, 2018, 08:04:33 pm »
I haven't fully tested your code, but my eye-inspection tells me there could be something wrong:

Code: Pascal  [Select][+][-]
  1.   strFolderConfigPath := GetAppConfigDir(False);
  2.   strFolderConfigPath := IncludeTrailingPathDelimiter(strFolderConfigPath);
  3.   ForceDirectories(strFolderConfigPath);
  4.   strFolderConfig := 'config';    // hardcoded.
  5.   strFileConfig := 'config.txt';  // hardcoded.

I think you (also) need to do ForceDirectory(strFolderConfigPath + strFolderConfig). Just my guess.

In my computer, I can see the folder groupgen is created but the config is not.
« Last Edit: April 02, 2018, 08:21:47 pm by Handoko »

mijen67

  • Full Member
  • ***
  • Posts: 130
  • It's hard to beat the bandwidth of a flying DVD
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #13 on: April 02, 2018, 11:47:35 pm »
I haven't fully tested your code, but my eye-inspection tells me there could be something wrong:

Code: Pascal  [Select][+][-]
  1.   strFolderConfigPath := GetAppConfigDir(False);
  2.   strFolderConfigPath := IncludeTrailingPathDelimiter(strFolderConfigPath);
  3.   ForceDirectories(strFolderConfigPath);
  4.   strFolderConfig := 'config';    // hardcoded.
  5.   strFileConfig := 'config.txt';  // hardcoded.

I think you (also) need to do ForceDirectory(strFolderConfigPath + strFolderConfig). Just my guess.

In my computer, I can see the folder groupgen is created but the config is not.


Your guess was correct, could you please retest? (file is updated).

Handoko

  • Hero Member
  • *****
  • Posts: 3759
  • My goal: build my own game engine using Lazarus
Re: Newbie: First attempt at "complete" app with a few problems
« Reply #14 on: April 03, 2018, 05:47:41 am »
Better, but still buggy.

The config folder now is really created and some of the .xml files (frmClass.xml, frmMain.xml, frmSetting.xml, frmStudent.xml). But still got the same errors.

And here is what I found:

Code: Pascal  [Select][+][-]
  1. procedure LoadSettings();
  2. var
  3.   sList: TStringList;
  4.   rcnt, i: integer;
  5.   pt: TPoint;
  6. begin
  7.  
  8.   if (not FileExists(strFileConfigFull)) then
  9.     begin
  10.       pt := Mouse.CursorPos;
  11.       ShowMessagePos('Config file does not exist' + strFileConfigFull,
  12.         pt.X, pt.Y);
  13.       RestoreDefaults();
  14.       ForceFolders();
  15.       SaveSettings();
  16.     end
  17.   else
  18.     ...

The bug is in your groupgen_settings.pas procedure LoadSettings line #126 (it is line #11 on the code above).

You should not call ShowMessage there because the handle of the form hasn't being created (my guess). Here you can see the flow on the program in groupgen.lpr:

Code: Pascal  [Select][+][-]
  1. program groupgen;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Interfaces, // this includes the LCL widgetset
  10.   SysUtils, FileUtil, Forms, groupgen_settings, groupgen_main, groupgen_class,
  11.   groupgen_choose, unit_library
  12.   { you can add units after this };
  13.  
  14. {$R *.res}
  15.  
  16. begin
  17.   RequireDerivedFormResource:=True;
  18.   Application.Initialize;
  19.   Application.CreateForm(TfrmMain, frmMain);
  20.   Application.CreateForm(TfrmClass, frmClass);
  21.   Application.CreateForm(TfrmStudent, frmStudent);
  22.   Application.CreateForm(TfrmSettings, frmSettings);
  23.   Application.Run;
  24. end.

See the code above. That procedure LoadSettings is being call in the OnCreate event of frmSetting on the line #22 above. Any call of ShowMessage before Application.Run will cause error.

Simply remove the ShowMessage solves the issue on my test. But still got these errors below, which are another story:
- EGridException
- Index Out of range Cell[Col=0 Row=2].
« Last Edit: April 03, 2018, 05:56:25 am by Handoko »

 

TinyPortal © 2005-2018