Jump to content
PenelopeSkye

TBDEdit - save updates to 2 different tables.

Recommended Posts

I am responsible for updating an app written in pascal a long ago by someone else. 

 

There are  lot of TBDEdit fields. I have been requested to find out the user who is updating certain of those fields on the form.  (I have the code that gets the username).  Currently as soon as you close the form the edit box is on after updating it, not the entire app just the form, the text is saved to the database.  I have been trying to simply understand how this is happening.

 

When I click on the edit box I see that there are Live Bindings in the Properties and events, and a datasource.

 

When I check the code in the dfm file I see the code below. That is all I can find regarding this specific field.  Is there any way to update this so that besides automatically saving text to the presentation_design_links table this info is also saved to another table along with the username?

 

I seriously doubt that this is enough info for anyone to go on, would you let me know what else you need?  Thanks!

 

object tb_dm_presentation_design_links: TADOTable
    Connection = adoconn_artdesign
    AfterInsert = tb_dm_presentation_design_linksAfterInsert
    BeforePost = tb_dm_presentation_design_linksBeforePost
    BeforeDelete = tb_dm_presentation_design_linksBeforeDelete
    IndexFieldNames = 'design_id'
    MasterFields = 'design_id'
    MasterSource = ds_design_master
    TableName = 'presentation_design_links'
    Left = 252
    Top = 324

object tb_dm_presentation_design_linkscust_upc: TStringField
      DisplayWidth = 30
      FieldName = 'cust_upc'
      ProviderFlags = [pfInUpdate]
      Size = 30
    end

 

 

 

Share this post


Link to post
4 hours ago, PenelopeSkye said:

as soon as you close the form the edit box is on after updating it, not the entire app just the form, the text is saved to the database.  I have been trying to simply understand how this is happening.

Clearly, you have a Datasource component with property AutoEdit set to True. So, when you change cuurent record, close table, etc. value of TDBEdit is "saved"

4 hours ago, PenelopeSkye said:

I seriously doubt that this is enough info for anyone to go on, would you let me know what else you need?

Yes, but I have a crystal ball :classic_biggrin:

4 hours ago, PenelopeSkye said:

I have been requested to find out the user who is updating certain of those fields on the form. 

 

The BeforePost event if you want to  update the table i.e 
 

procedure tb_dm_presentation_design_linksBeforePost(DataSet: TDataSet);
begin 
tb_dm_presentation_design_links.FieldByName('LAST_UPDATE').asDateTime:=now;
tb_dm_presentation_design_links.FieldByName('LAST_USER').asString:=mygetuserfunction;
end;

The AfterPost event if you record changes in another table (using an insert Query)

procedure tb_dm_presentation_design_linksAfterPost(DataSet: TDataSet);
begin
// anAdoQuery.SQL.Text:='INSERT INTO TRACKS (USER,DATE_UPDATE) VALUES (:U,:D)';
// sorry not sure of syntax I am not fan of ADO
anAdoQuery.Params.ParambyName('U').asString:=mygetuserfunction;
anAdoQuery.Params.ParambyName('U').asDateTime:=now;
anAdoQuery.ExecSQL;
end;

Now if you want to track only a set of columns, BeforePost is the event where you can check CurValue and NewValue (well with ADO I am not sure).
 

if tb_dm_presentation_design_linkscust_upc.curvalue.asString<>tb_dm_presentation_design_linkscust_upc.Newvalue.asString then
 // insert query 

 

N.B. Know that SGBDR (good ones) triggers can track this for you without Delphi code. But this SGBD you use, my crystal ball, don't show me🔮

 

P.S. As I remember, but never in more than 20 years, there is also an OnChange event for fields (if fields are defined, and that seems to be the fact tb_dm_presentation_design_linkscust_upc)

 

Edited by Serge_G

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×