Recent

Author Topic: Question about Design or Implentation or Both  (Read 9520 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Question about Design or Implentation or Both
« Reply #15 on: April 08, 2018, 10:24:48 pm »
seems I've bitten more than I was expecting. Oh well, I'll download the pdf and take a look after the holidays.

The PDF isn't to bad. There is a mystery to it I can't seem to get resolved.

The PDF says the 1000 record is Traffic Flow. Fair enough. So I'm looking at Apt Dot Dat file and I can see 1000 records with the following:

"1000 Generated by WorldEditor"

They are always the second record in the file. But this is definitely not a Traffic Flow record which has the following fields: Name Field pertaining to ground traffic.

Page 2 of the PDF and page 6.
 
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Question about Design or Implentation or Both
« Reply #16 on: April 11, 2018, 05:51:10 am »
seems I've bitten more than I was expecting. Oh well, I'll download the pdf and take a look after the holidays.

The PDF isn't to bad. There is a mystery to it I can't seem to get resolved.

The PDF says the 1000 record is Traffic Flow. Fair enough. So I'm looking at Apt Dot Dat file and I can see 1000 records with the following:

"1000 Generated by WorldEditor"

They are always the second record in the file. But this is definitely not a Traffic Flow record which has the following fields: Name Field pertaining to ground traffic.

Page 2 of the PDF and page 6.
 
from a quick look I had today it looks like 1000 is more of a general 3rdparty info, but I'll have more info after I had some time to study it.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Question about Design or Implentation or Both
« Reply #17 on: April 11, 2018, 08:06:06 am »
I'm trying to understand Grids, but having a really difficult time with them.

I need to resize the grid continuously and it's always out of bounds or index errors . 

Can't find out how to add a fixed row and fixed column, Thinking I would delete all the rows and columns and then add what I need for the requested record.

TstringGrid.Clear deletes the rows but not the columns, I think.

Is there an easy way to do this.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Question about Design or Implentation or Both
« Reply #18 on: April 11, 2018, 08:49:23 am »
Ok here is a quick demo.
Code: Pascal  [Select][+][-]
  1. function Min(const A,B:Integer):Integer;inline;
  2. begin
  3.   if A<B then Result := A else Result := B;
  4. end;
  5.  
  6. procedure SetupGrid(const aGrid:TStringGrid; aColumnNumber, aRowNumber:Integer;aColumnTitles:array of String);
  7. begin
  8.   aGrid.FixedCols := 1;
  9.   aGrid.FixedRows := 1;
  10.   aGrid.RowCount  := aRowNumber +1;  //one extra row for the column headers
  11.   aGrid.ColCount  := aColumnNumber+1;//one extra column for the row fixed cell
  12.   aGrid.ColWidths[0] := 10;
  13.   for vCntr := 1 to Min(High(aColumnTitles)+1,aColumnNumber) do begin // column 0 is a fixed column the gray cells you see on the left.
  14.     //row 0 = fixed row the column titles the gray cell you see on top.
  15.     aGrid.Cells[vCntr,0] := aColumnTitles[vCntr-1]; //column 1 get title at index 0, column 2 get title at index 1 .... column N gets title at index N-1
  16.   end;
  17. end;
  18.  
  19. procedure AppendRow(const aGrid:TStringGrid; const aRowData:Array of String);
  20. var
  21.   vLastRow , vCntr: Integer;
  22. begin
  23.   aGrid.RowCount := aGrid.RowCount +1 ;
  24.   vLastRow := aGrid.RowCount -1;// rows and columns are 0 based arrays so column 1 is at index 0, column 2 at index 1 .... column N at N-1.
  25.   for vCntr := 1 to Min(High(aRowData),aGrid.ColCount) do begin
  26.     aGrid.Cells[vCntr,vLastRow] := aRowData[vCntr-1];
  27.   end;
  28. end;
  29.  
  30. Procedure DemoGridSetup(const aGrid:TStringGrid);
  31. begin     // grid to set Columns Rows Titles of columns
  32.   SetupGrid(aGrid,       5,      0,   ['Airport','RunWay','Longtitude','Latitude','Elevation']);
  33.          // ['Airport', 'RunWay','Longtitude','Latitude','Elevation']
  34.   AppendRow(['NewYork', 'Bride', '1',         '2',       '0']);
  35.   AppendRow(['Manhatan','Teen',  '1.43',      '1.23',    '23']);
  36.   AppendRow(['Chicago', 'Texan', '1.53334',   '1.25456', '3']);
  37.   AppendRow(['Phoenix', 'Gates', '1.52546',   '1.278997', '1.5']);
  38. end;
  39.  
Now
1) start a new application drop a stringgrid on the form set it to StringGrid1.align := alclient;
2) Copy the code abode and paste it in the form's implementation section (just below then line {$R *.lfm}).
3) Drop a toolbar and add a button, on the tool button's click even add a call to
Code: Pascal  [Select][+][-]
  1. .......
  2.   DemoGridSetup(StringGrid1);
  3.  

run and press the toolbutton you should see a 6 columns and 5 rows grid the first row is gray and has the titles describing the data in its column and first column is also gray and usually is used to paint an arrow so the end user knows which records he is on. Keep in mind that grids are not designed to show multiple schemas. To put it simple in your file you have different data with different codes you can add all the lines of code X on one grid all the lines of Code Y on an other all the lines of Code Z on a third and you can have as many grids as line codes. But you do not mix multiple linecodes in one grid.

If you have any more questions.

WARNING
All code posted above was typed directly in the browser and although care was taken to avoid any obvious mistakes I have not compile it or test it so if something does not work and you can't figure it out I'll be happy to correct/explain it.

PS:
Try changing the height of the form to hide some of the rows. you will see the scrollbar appear on right and/or bottom that will allow to scroll the contents of the grid note that the fixed row and column are always visible when you scroll the data on the grid you always know what data each cell has.
« Last Edit: April 11, 2018, 08:52:58 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Question about Design or Implentation or Both
« Reply #19 on: April 11, 2018, 08:49:31 pm »
I'm about to setup your demo. I was reading the code and wondering if I have this figured out right.

procedure SetupGrid(const aGrid : TStringGrid;
                                       aColumnNumber, RowNumber : Integer;
                                       aColumnTitles  : array of String);

This is a procedure you call with your grid, number of columns, number of rows and an array of strings with the titles for the columns required.

The procedure then configures the Grid for you.

It sets 1 fixed col and 1 fixed row.

Adds 1 row and 1 column to your requested number to account for the fixed row and columns.

If that's how it works it's exactly what I need.

I load the records of an airport data file into a list box.
Each record has a unique RowCode.
I know how many fields there are in each record based on the RowCode.
DoubleClick on a record in the listbox and the program will call:

SetupGrid( DataGrid, 4, 16, Titles);
DataGrid.Visible := True;
 
 I would then have a grid with 17 rows and five columns. I can parse out the record selected and fill the grid.
 
Am I reading this right.
Wow.


FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Question about Design or Implentation or Both
« Reply #20 on: April 11, 2018, 10:30:56 pm »
I'm about to setup your demo. I was reading the code and wondering if I have this figured out right.

procedure SetupGrid(const aGrid : TStringGrid;
                                       aColumnNumber, RowNumber : Integer;
                                       aColumnTitles  : array of String);

This is a procedure you call with your grid, number of columns, number of rows and an array of strings with the titles for the columns required.

The procedure then configures the Grid for you.

It sets 1 fixed col and 1 fixed row.

Adds 1 row and 1 column to your requested number to account for the fixed row and columns.

If that's how it works it's exactly what I need.

I load the records of an airport data file into a list box.
Each record has a unique RowCode.
I know how many fields there are in each record based on the RowCode.
DoubleClick on a record in the listbox and the program will call:

SetupGrid( DataGrid, 4, 16, Titles);
DataGrid.Visible := True;
 
 I would then have a grid with 17 rows and five columns. I can parse out the record selected and fill the grid.
 
Am I reading this right.
Wow.
yes, that's about the gist of it. If you do not know the exact number of rows to start with, you simply pass 0 to the rows on the SetupGrid call and use the AppendRow for every line you want to add.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Question about Design or Implentation or Both
« Reply #21 on: April 11, 2018, 11:01:49 pm »
"PS:
Try changing the height of the form to hide some of the rows. you will see the scrollbar appear on right and/or bottom that will allow to scroll the contents of the grid note that the fixed row and column are always visible when you scroll the data on the grid you always know what data each cell has."

Have the Demo up and running.
A few coding errors which I was able to fix I think?

1. vCntr : Integer;  had to be declared in SetUpGrid.
2. Had to change: AppendRow(['NewYork', 'Bride', '1',         '2',       '0']);
                     To: AppendRow(aGrid,['NewYork', 'Bride', '1',         '2',       '0']);

Setting the grid to StringGrid1.align := alclient; the grid takes over the whole form.




Tried this in  SetUpGrid;

      aGrid.Height := 152;
      aGrid.Width  := 180;
      aGrid.Left    := 408;
      aGrid.Top    := 328;

Then in FormShow:

    StringGrid1.Height := 152;
    StringGrid1.Width  := 180;
    StringGrid1.Left    := 408;
    StringGrid1.Top    := 328; 

I can't seem to change the position or the size of the grid.


 
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Question about Design or Implentation or Both
« Reply #22 on: April 11, 2018, 11:17:08 pm »
"PS:
Try changing the height of the form to hide some of the rows. you will see the scrollbar appear on right and/or bottom that will allow to scroll the contents of the grid note that the fixed row and column are always visible when you scroll the data on the grid you always know what data each cell has."

Have the Demo up and running.
A few coding errors which I was able to fix I think?

1. vCntr : Integer;  had to be declared in SetUpGrid.
yeap, that sound about right, I'll always overlook the simplest things.
2. Had to change: AppendRow(['NewYork', 'Bride', '1',         '2',       '0']);
                     To: AppendRow(aGrid,['NewYork', 'Bride', '1',         '2',       '0']);
now I'm embarrassed  :-[ but at least I'm consistent. I spend around 15% of my time correcting those kind of errors.

Setting the grid to StringGrid1.align := alclient; the grid takes over the whole form.

yes that is the point, now everytime you change the form size the grid size changes too.



Tried this in  SetUpGrid;

      aGrid.Height := 152;
      aGrid.Width  := 180;
      aGrid.Left    := 408;
      aGrid.Top    := 328;

Then in FormShow:

    StringGrid1.Height := 152;
    StringGrid1.Width  := 180;
    StringGrid1.Left    := 408;
    StringGrid1.Top    := 328; 

I can't seem to change the position or the size of the grid.
I do not understand, the grid is different than the size you defined, or you can not change its size while resizing the form?
« Last Edit: April 11, 2018, 11:22:47 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Question about Design or Implentation or Both
« Reply #23 on: April 11, 2018, 11:29:41 pm »
"I do not understand the grid is different than the size you defined or you can not change its size while resizing the form. "

I don't allow  TForm2 to be resized. It is fixed height, width and location.

it's the grid itself I can't seem to resize or relocate on the form.

Some records have 4 fields so I need a grid with two columns and 5 total rows displayed at a location on my form.

Others I need 4 total columns with 16 rows so I have to make the grid wider and taller and position in a different position.

Oh, elevations aren't showing on the grid. I don't see anything wrong with the statement.

 AppendRow(aGrid, ['NewYork', 'Bride', '1',         '2',       '0']);

But the column is blank.
   
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Question about Design or Implentation or Both
« Reply #24 on: April 12, 2018, 04:32:01 am »
"I do not understand the grid is different than the size you defined or you can not change its size while resizing the form. "

I don't allow  TForm2 to be resized. It is fixed height, width and location.

it's the grid itself I can't seem to resize or relocate on the form.
I see nothing wrong with the code so must be something else. Let me try that with a demo my self. Are you sure that the values passed to the left,top,width,height are different than the ones you see on the object inspector?
Some records have 4 fields so I need a grid with two columns and 5 total rows displayed at a location on my form.

Others I need 4 total columns with 16 rows so I have to make the grid wider and taller and position in a different position.

Oh, elevations aren't showing on the grid. I don't see anything wrong with the statement.

 AppendRow(aGrid, ['NewYork', 'Bride', '1',         '2',       '0']);

But the column is blank.
   
try this one instead.
Code: Pascal  [Select][+][-]
  1. procedure AppendRow(const aGrid:TStringGrid; const aRowData:Array of String);
  2. var
  3.   vLastRow , vCntr: Integer;
  4. begin
  5.   aGrid.RowCount := aGrid.RowCount +1 ;
  6.   vLastRow := aGrid.RowCount -1;// rows and columns are 0 based arrays so column 1 is at index 0, column 2 at index 1 .... column N at N-1.
  7.   for vCntr := 1 to Min(Length(aRowData),aGrid.ColCount) do begin
  8.     aGrid.Cells[vCntr,vLastRow] := aRowData[vCntr-1];
  9.   end;
  10. end;
  11.  
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Question about Design or Implentation or Both
« Reply #25 on: April 12, 2018, 09:52:35 am »
Created a New project.

It has the following procedures and functions:

    procedure btnCloseClick(Sender: TObject);                //   Closes the program.
    procedure btnCallSetUpGridClick(Sender: TObject);    //   Calls taazz SetUpGrid procedure   
    procedure btnResetClick(Sender: TObject);               //   Sets a Grid with two columns 2 rows 
    procedure FormCreate(Sender: TObject);                 //   Sets a Grid with two columns 2 rows


    procedure btnProcedureClick(Sender: TObject);      // Calls a procedure I wrote
    procedure btnColWidthClick(Sender: TObject);      //  Trying to resize columns (Throws Error)
    procedure btnPopulateClick(Sender: TObject);     // set Grid.Cells[0,1] := '1'; Verify row and cess exist

Taazz procedures and function:

    function Min(const A,B:Integer):Integer;inline;
    procedure SetUpGrid(const aGrid:TStringGrid; aColumnNumber, aRowNumber:Integer;aColumnTitles:array of String);
    procedure AppendRow(const aGrid:TStringGrid; const aRowData:Array of String);

 I need to resize and reposition the grid, adjust the width of the columns and set right justify. It needs to do this based on what the user selects.

It won't do the column resize.
  File attached       
« Last Edit: April 12, 2018, 09:54:21 am by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Question about Design or Implentation or Both
« Reply #26 on: April 12, 2018, 10:31:52 am »
Created a New project.

It has the following procedures and functions:

    procedure btnCloseClick(Sender: TObject);                //   Closes the program.
    procedure btnCallSetUpGridClick(Sender: TObject);    //   Calls taazz SetUpGrid procedure   
    procedure btnResetClick(Sender: TObject);               //   Sets a Grid with two columns 2 rows 
    procedure FormCreate(Sender: TObject);                 //   Sets a Grid with two columns 2 rows


    procedure btnProcedureClick(Sender: TObject);      // Calls a procedure I wrote
    procedure btnColWidthClick(Sender: TObject);      //  Trying to resize columns (Throws Error)
    procedure btnPopulateClick(Sender: TObject);     // set Grid.Cells[0,1] := '1'; Verify row and cess exist

Taazz procedures and function:

    function Min(const A,B:Integer):Integer;inline;
    procedure SetUpGrid(const aGrid:TStringGrid; aColumnNumber, aRowNumber:Integer;aColumnTitles:array of String);
    procedure AppendRow(const aGrid:TStringGrid; const aRowData:Array of String);

 I need to resize and reposition the grid, adjust the width of the columns and set right justify. It needs to do this based on what the user selects.

It won't do the column resize.
  File attached       
Don't use the columns property. It is a half backed attempt to modernize the stringgrid and is not synchronized with colCount/rowcount and the rest of the methods, use colWidths instead eg
Code: Pascal  [Select][+][-]
  1. procedure TForm1.btnColWidthClick(Sender: TObject);
  2. begin
  3.     DataGrid.ColWidths[1] := 265;
  4.     DataGrid.ColWidths[2] := 165;
  5.     DataGrid.ColWidths[3] := 10;
  6.     DataGrid.ColWidths[4] := 165;
  7. end;
  8.  
The positioning and resizing of the grid works for me.
« Last Edit: April 12, 2018, 10:39:41 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Question about Design or Implentation or Both
« Reply #27 on: April 12, 2018, 05:55:43 pm »
 :) Yea, Setting Col and rows, Col widths and grid sizing works for me now.

I just need to do alignment in each col and centering of titles but I think I can do that. 

If I look at all the different records and data I think a 4 col grid and a 5 col grid will cover almost all the different data records.

Wow this is really great.

Thanks a lot.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018