Transferring data from one form to another form

I have data fields on one form that I want to show on another form, I have a TDBGrid that shows records and when I click on a cell using the OnCellClick it opens another form with the same TDBEdit and TDBMemeo fields but nothing is displayed in the second form fields.

Any help would be greatly appreciated.

Regards
Steve

Comments

  • Are those fields linked to the grid in any way?
  • This is the first time I am programming using a database so excuse my inexperience, the fields and grid are all set to the same datasource and adotable if that is what you are asking. It all seems simple but obviously not quite so.

    Steve
  • I think you need to provide more details.

    Is the 2nd form auto-created or do you create it in your code?
    How are the controls on the second form linked to the data?
    How are the controls on the first form linked to the data?
    Do you have a data module or do you have your data access components on the first form?
  • Hi SalmiSoft,

    I did send you a message earlier today replying to an earlier post asking for my code, please check your messages I have included a link to my code.

    kindest regards
    Steve
  • OK, I'll take a more detailed look at your code later, but first a quick comment:

    The fields on the second form need to be linked to the data source on your first form, so that they show the data from the same record as selected on the first form.
    A quick way to do this would be to set up the links in code, before you show the second form, like this:
    procedure TForm2.DBGrid1CellClick(Column: TColumn);
    begin
      RecordForm.Top := Top+160;
      RecordForm.Left := Left+100;
    //  PlaySound(PChar('sound1'), 0, snd_resource or snd_async);
    
    [B]  RecordForm.DBMemo1.DataSource := Self.DataSource1;  // Add these 2 lines.
      RecordForm.DBMemo1.DataField  := 'comments'; [/B]
    
    
      RecordForm.ShowModal;
    end;
    

    I have only shown how to set up one field on RecordForm. You will need to add similar code for each of the other fields.

    A better solution, but more work, would be to move the data source etc to a data module and use the object inspector to set up the fields on both forms to access the data module.
  • Once again you have come to my rescue, many thanks, that worked just fine. Give me another 50 years and I might be nearly as good as you, lol.

    kindest regards

    Steve
Sign In or Register to comment.