Topic: Open form by script

Hello everyone, I would like to briefly explain my problem: in a tablegrid I display the data of a table that has not set a primary key, but in a column, the fourth, I have a unique identification code. I would like to change the record selected in the tablegrid in another mask, via script ... but how can I open the mask while maintaining the association with the record selected on the tablegrid? considering that i can't use dbitemid as a reference? Thank you.

Re: Open form by script

If by unique identification code you mean the ID of the record, then use the method ShowRecord( <table name>, <ID> ) to display the edit form:

frmEditForm.ShowRecord( 'payment', frmForm.TableGrid.cell[ 3, frmForm.TableGrid.SelectedRow ].asInteger )
Визуальное программирование: блог и телеграм-канал.

Re: Open form by script

Hi, thanks for the quick reply.
When I open the edit form, the fields are not filled in with the data of the record chosen in the tabelgrid.
I enclose a rudimentary example.
Thanks

Post's attachments

Attachment icon myvdbscript.zip 334.39 kb, 143 downloads since 2021-10-19 

Re: Open form by script

Hi Madbit71,
Try it like this

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
begin
  ShowRecord(editemployees,'employees',form1.tablegrid1.dbitemid);
end;

Derek.

Re: Open form by script

madbit71 wrote:

Hi, thanks for the quick reply.
When I open the edit form, the fields are not filled in with the data of the record chosen in the tabelgrid.
I enclose a rudimentary example.
Thanks

First, you need to determine the ID of the edited post, in your case like this:

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var
  tmpID : integer;
begin
  tmpID := SQLExecute('SELECT id FROM employees WHERE uniqueid = '+ IntToStr( form1.TableGrid1.cell[ 1, form1.TableGrid1.SelectedRow ].asInteger) );
  editemployees.ShowRecord( 'employees', tmpID );
end;

P.S. In fact, the record ID is ALWAYS present in the table, which is created through the Settings property or the "Search" button. But when the table is displayed, this field is hidden from the user and is available through the property dbItemID.  Of course, if you are using an SQL query, then the ID fields may not be in results.

Визуальное программирование: блог и телеграм-канал.

Re: Open form by script

Hello and thank you,
unfortunately I did not get what I was looking for ... I am attaching a minimal project that reflects my situation.
I hope you can try it to get my problem clear.
Thanks.

Post's attachments

Attachment icon myvdbscript1.zip 335.88 kb, 144 downloads since 2021-10-19