Topic: Transfer Data from a Grid Row when doing a FORM.SHOW

Hi everybody
I don't know if this is an SQL or a SCRIPT.

I would like the users to double click a ROW on a GRID, and based on a variable (either 'Assess' or 'Todo') different Forms will open.

I got as far as I can open the appropriate FORM but I would also like the Data from the ROW of the GRID to also transfer.

========================================================

procedure fmTimeTable_TableGrid1_OnCellDoubleClick (Sender: TObject; ACol, ARow: Integer);   
  var
        aba : string;
  begin
         aba :=SQLEXECUTE('SELECT DISTINCT ttCategory FROM dttimeTable WHERE id = ' +fmTimeTable.TableGrid1.sqlValue) ;

         showmessage(ARow); //Test to see what acol and arow does...I know the answer lies with something to do with this.

         if aba = 'Todo' then
              begin
                  fmTodo2.show;
                  // carry over information from the selected ROW of the GRID to the form Requested fmTodo2
              end
          else if aba = 'Assess' then
              Begin
                  fmTimeTableEntry.show;
                  // carry over information from the selected ROW of the GRID to the form Requested in this case fmTimeTableEntry.

              end
end;

====== I think it has something to do with an SQL but also the ARow ?==========


Thanks for any help or guidence.

Re: Transfer Data from a Grid Row when doing a FORM.SHOW

Here's the code I used in this kind of situation. I hope it gives you an idea.

Post's attachments

Attachment icon multiform.zip 495.05 kb, 390 downloads since 2021-01-22 

brian

Re: Transfer Data from a Grid Row when doing a FORM.SHOW

Hi Brian and thanks for you help.

I did exactly as you instructed and your program is exactly what I want to do however, I am getting a really strange message


Access violation at address 00E42167 in modele 'NAME OF PROGRAM',
Read of address FFFFFFFE.



Thinking it was a computer memory problem (did do I know), rebooted Windows and tried again with no luck.


HELP!!

Re: Transfer Data from a Grid Row when doing a FORM.SHOW

Good Day. If you could share your application, maybe I or someone can look what's going on with it. If not, try to lay down as much as code and/or screenshot you can so we can help. It's hard to know the problem without looking at the source.

brian

5 (edited by derek 2021-01-23 00:33:12)

Re: Transfer Data from a Grid Row when doing a FORM.SHOW

Hi Jeffmtl,  Hi Brian,
I was looking at your original post and I wonder if you're perhaps confusing 'celldoubleclick' with (the more usual) 'doubleclick;
'Celldoubleclick' tends to be used for calling different actions depending on DIFFERENT cells in a row that have been doubleclicked, not for calling different actions depending on the contents of the SAME cell (although it would still work).
Using your example, I think you'd be better using 'doubleclick' and performing a simple test in the cell that contains the value you want to check.  There's a number of ways to do this (see the attachment (stolen from Brian! - thanks Brian) for a different approach.
Regards,
Derek.

Post's attachments

Attachment icon multiform2.zip 336.49 kb, 348 downloads since 2021-01-22 

Re: Transfer Data from a Grid Row when doing a FORM.SHOW

Hi Brian

Your approach of using the "SHOW RECORD" is working well and not causing any address violation.

Such that

Upon double clicking the grid, the desired form (TODO or ASSESS) will open.

However, I am having 3 forms opening up.  2 x the one desired and one the other form, one after the other.

From various tests, it appears double clicking the grid will activate the 2 "SHOW RECORD", buttons as as well as proceed with the SCRIPT which also clicks the button.

Thus this will result in 3 FORMS opening up one after the other.
I've double checked and compared all the properties from multiform2 with my own, yet nothing seems to come up.

=====================================================
procedure fmTimeTable_TableGrid1_OnDoubleClick (Sender: TObject);
var
    rslt : string;
begin
     rslt :=SQLEXECUTE('SELECT DISTINCT ttCategory FROM dttimeTable WHERE id = ' +fmTimeTable.TableGrid1.sqlValue) ;

     if rslt = 'Todo' then
     begin
            fmTimeTable.TTTodoButton.click;
     end
     else if rslt = 'Assess' then
     begin
            fmTimeTable.TTTimeTableButton.click;
     end

end;

Re: Transfer Data from a Grid Row when doing a FORM.SHOW

Oh, I think you copy your button and paste it somewhere. Check that buttons, if its action is show record and pointing to the grid you are double clicking, then that's the reason why forms are popping. You can check on Derek's way of doing the double click for you to have other option. smile But if you want to use the ShowRecord method like I'm used to, make sure that you don't duplicate that button and put it somewhere in that form to avoid that popping forms.

brian

8 (edited by derek 2021-01-23 14:43:01)

Re: Transfer Data from a Grid Row when doing a FORM.SHOW

Hi Jeffmtl, Hi Brian,
With multiple 'show record' buttons on a form, make sure you set each of the 'show record' buttons to 'enabled = false' (see screen1 in the attachment). 
Then in your script, when you tell your program which button to click, it is only that one that fires (and not the other which remains disabled) (see screen2 in the attachment).
Derek.

Post's attachments

Attachment icon multiform2a.zip 529.16 kb, 453 downloads since 2021-01-23