Jump to content


Photo

Unknown Grid Name


  • Please log in to reply
21 replies to this topic

#1 seizure

seizure
  • Members
  • 23 posts

Posted 04 May 2005 - 04:40 AM

Hi

Is it possible to determine and then reference the SelectedColumn and SelectedRow if the grid name is unknown. I have many grids that are created at runtime, named uniquely and need to extract the cell contents.

Thanks.

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 04 May 2005 - 02:32 PM

Hi,

Here is one example that may help you:

First, you need to give unique Name for each your Grid:
- MyGrid1, MyGrid2, MyGrid3.

This is very important and Delphi will show error if 2 components have same name.

Then, you can use Components array of Form and go trough this array:

CODE
var

 i: Integer;

 aGrid: TNextGrid;

begin

 for i := 0 to ComponentCount - 1 do

 begin

   if Components[i] is TNextGrid then

   beging

     aGrid = TNextGrid(Components[i]);

     // now, you are able to do with grid what you like :)

   end;

 end;

end;


best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 04 May 2005 - 02:38 PM

Hi Boki,

Shouldn't one test for the type of the component before casting it? The code otherwise gives an error when you drop any other component onto it.

Another thing to watch out for is that components dropped onto a container like a pageview's page or groupbox don't show up this way. Only components directly on the form. For the code to work you have to recurse into all components components arrays too.
G.W. van der Vegt

#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 04 May 2005 - 02:43 PM

Hello Wim

Yes, I will correct code in previous post.

thanks.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 seizure

seizure
  • Members
  • 23 posts

Posted 09 May 2005 - 01:34 AM

Thanks for the example code, it's spot on. I'm trying to re-use the code for different grids on different pages of a pagecontrol. Each time I try though, aGrid keeps referring back to the original grid on the first page...I can't get it to find the grid component on the currently active page. Any ideas?

Regards, Jason

#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 09 May 2005 - 07:16 AM

Hi Jason,

You can use Components[] array of single TabSheet in PageControl.

When you create Grid in run-time, you need to have some link to this object. When you Insert Grid into some other control (like Page Control, Panel...) reference to this Grid will jump into Components[] array and you will be able to use it smile.gif

Hope that this help, if you have some sample code or more details please tell me.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#7 seizure

seizure
  • Members
  • 23 posts

Posted 09 May 2005 - 11:44 PM

Hi

Example code as follows:

CODE
procedure TLogForm.FilterSelected1Click(Sender: TObject);

var

 aGrid, bGrid: TNextGrid;

 i, j, k, l, m, GridCol, GridRow: Integer;

 GridContent, CurrGrid: String;

begin

 for i := 0 to ComponentCount - 1 do

 begin

   if Components[i] is TNextGrid then

   begin

     aGrid := TNextGrid(Components[i]);

     GridCol := aGrid.SelectedColumn;

     GridRow := aGrid.SelectedRow;

     GridContent := aGrid.Cell[GridCol, GridRow].AsString;

     NewSheet(GridContent);

   end;

 end;

 with NxPageControl.ActivePage do

 begin

   for j := 0 to ComponentCount - 1 do

   begin

     if Components[j] is TNextGrid then

     begin

       bGrid := TNextGrid(Components[j]);

       l := 0;

       for k := 0 to aGrid.RowCount - 1 do

       begin

         if aGrid.Cell[GridCol, k].AsString = GridContent then

           begin

             bGrid.AddRow();

             bGrid.Cell[0, l].AsString := aGrid.Cell[0, k].AsString;

             bGrid.Cell[1, l].AsString := aGrid.Cell[1, k].AsString;

             bGrid.Cell[2, l].AsString := aGrid.Cell[2, k].AsString;

             bGrid.Cell[3, l].AsString := aGrid.Cell[3, k].AsString;

             l := l + 1;

           end;

         end;

       end;

     end;

   end;

 end;


First for..loop determines current grid and selected cell content, taken from your example code. NewSheet procedure creates a new grid and parented tabsheet. Second loop populates new grid with filtered content from the first.

Thanks, Jason

#8 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 09 May 2005 - 11:52 PM

Hello Jason,

Don't realy understand sad.gif

Can you please tell me what exactly you want to do and I will write complete procedure smile.gif I am sure that this will help.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#9 seizure

seizure
  • Members
  • 23 posts

Posted 10 May 2005 - 12:18 AM

Hi Boki

I want the user to select cell content from an existing grid on a tabsheet, and filter rows with that content to a new grid on a new tabsheet of the same pagecontrol. This does work with the code example above.

What doesn't work, is running this procedure against the grid that was created by the procedure.

Does that make sense?

Jason

#10 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 10 May 2005 - 12:32 AM

Hi Jason,

you need first to get Active Grid:

go trough Components[] of ActivePage (TNxTabSheet). If you have only one Grid on each page, then all you need is to find first TNextGrid, set reference (aGrid) and exit from this loop:

CODE
with NxPageControl.ActivePage do

begin

 for j := 0 to ComponentCount - 1 do

 begin

   if Components[j] is TNextGrid then

   begin

     aGrid = TNextGrid(Components[J]);

   end;

 end;

end;


Now you need to create new NxTabSheet and place NextGrid inside it with desired settings and data.

I hope that this is it smile.gif I think that you have switch some parts in your code smile.gif

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#11 seizure

seizure
  • Members
  • 23 posts

Posted 10 May 2005 - 01:47 AM

ok, if I understand correctly...

Created a function with your code that tells me the current grid:

CODE
function CurrentGrid: TNextGrid;

var

 i: integer;

begin

 with LogForm.NxPageControl.ActivePage do

 begin

   for i := 0 to ComponentCount - 1 do

   begin

     if Components[i] is TNextGrid then

     begin

       Result := TNextGrid(Components[i]);

     end;

   end;

 end;

end;


Re-written the procedure code as follows:

CODE
procedure TLogForm.FilterSelected1Click(Sender: TObject);

var

 aGrid, bGrid: TNextGrid;

 i, j, GridCol, GridRow: Integer;

 GridContent: String;

begin

 // Determine Source Grid & Cell Content

 aGrid := CurrentGrid();

 GridCol := aGrid.SelectedColumn;

 GridRow := aGrid.SelectedRow;

 GridContent := aGrid.Cell[GridCol, GridRow].AsString;



 // Create new tabsheet & grid (makes new grid active)

 NewSheet(GridContent);



 // Determine Destination Grid and Populate from Source Grid

 bGrid := CurrentGrid();

 i := 0;

 for j := 0 to aGrid.RowCount - 1 do

 begin

   if aGrid.Cell[GridCol, j].AsString = GridContent then

   begin

     bGrid.AddRow();

     bGrid.Cell[0, i].AsString := aGrid.Cell[0, j].AsString;

     bGrid.Cell[1, i].AsString := aGrid.Cell[1, j].AsString;

     bGrid.Cell[2, i].AsString := aGrid.Cell[2, j].AsString;

     bGrid.Cell[3, i].AsString := aGrid.Cell[3, j].AsString;

     Inc(i);

   end;

 end;

end;


This now produces an exception. Hope that this is clearer?

Thanks, Jason
:?

#12 seizure

seizure
  • Members
  • 23 posts

Posted 11 May 2005 - 02:16 PM

Any thoughts on the above? I know it's probably down to my inexperience but any pointers in the right direction would be appreciated... Can I provide anymore information?

Thanks, Jason

#13 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 11 May 2005 - 05:34 PM

Hi Jason,

Can you please tell me where error occur and what was error smile.gif

thank you.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#14 seizure

seizure
  • Members
  • 23 posts

Posted 11 May 2005 - 05:46 PM

Hi

I've upgraded to 3.1 (latest download, clean install) and is now reporting "EReadError Property HideGlyphs does not exist" on Application.Run.

If you can get me past that, I'll get the original error details to you.

Jason

#15 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 11 May 2005 - 05:49 PM

Hi Jason,

Press Ignore button in Delphi and then save project.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#16 seizure

seizure
  • Members
  • 23 posts

Posted 11 May 2005 - 05:57 PM

Hi

It's a Debugger Exception Notification window with just an OK and Help. If I step through the code it makes reference to NxFlipPanel1.HideGlyphs but I don't use that component in the project. :?

Jason

#17 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 11 May 2005 - 06:01 PM

Hello Jason,

It must be this component inside your project NxFlipPanel1. Can you send me some screenshot on my email to see what you get

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#18 seizure

seizure
  • Members
  • 23 posts

Posted 11 May 2005 - 06:15 PM

My apologies, it was on a test form that was still in the project. Now builds ok so back to the original error.

"EExternalException with Message 'External exception C000001D'" when running the last FilterSelected1Click procedure above.

Jason

#19 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 11 May 2005 - 06:21 PM

Hello Jason,

Can you tell me where (on which line) this occur.

Or maybe will be better that you send me some small demo project to I test it by myself it will be a lot more easy.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#20 seizure

seizure
  • Members
  • 23 posts

Posted 11 May 2005 - 06:26 PM

The IDE is pointing to the "end." after Application.Run; of the main unit. I'll send you a project...

Thanks, Jason




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users