Walking a Master/Detail relationship

Walking a Master/Detail relationship

Post by Simon A. Haidle » Sun, 31 Dec 1899 09:00:00



I have a Master/Detail relationship of Cheques and the Invoices that the
cheques are paying.  I want to walk the master and detail tables and for
each record in each table append a record to a history file.  The code
follows:-

THE PROBLEM:
When I put the Hist table in append mode, the order of the IPayInvs table
changes half way through the walk and so some records are missed and others
are doubled up.  If the Hist.Append block is commented out every record is
read in the correct order but if Hist.Append is attempted, the last record
is read and then the first and then each successive record however the
first record is missed.

I have tried various ways to overcome this like, no master/detail and
setting ranges based on the linking field and so forth..

Can anybody suggest where I am going wrong or perhaps a better way to
acvhieve the same result please?

Thanks Simon

procedure TForm1.UpdateMe;
var
  CredCode     : String;
  ChequeDate   : TDateTime;
  ChequeNum    : Integer;
begin

  IPay.First;
  repeat
  begin
    CredCode:=IPayCREDITOR.AsString;
    ChequeDate:=IPayCHQDATE.AsDateTime;
    ChequeNum:=IPayCHQNUM.AsInteger;

    // Post the payed Invoices to Hist
    UpdateTran(CredCode, ChequeDate, ChequeNum);

    // Post the Cheque to Hist
    Hist.Append;
    Hist['CREDITOR']:=CredCode;
    Hist['PAYDATE']:=ChequeDate;
    Hist['CHQNUM']:=ChequeNum;
    Hist['TRNTYPE']:='PAY';
    Hist['SUMMARY']:=IPay['DESCRIPT'];
    Hist['AMOUNT']:=IPay['TOTAL'];
    Hist.Post;
    IPay.Next;
  end
  until IPay.EOF;
end;

procedure TForm1.UpdateTran(CredCode: String; ChequeDate: TDateTime;
ChequeNum: Integer);
begin
// walk IPayInvs and append records to hist

  IPayInvs.First;
  repeat
  begin

    Hist.Append;
    CR.Hist['CREDITOR']:=CredCode; // Give the invoice an owner
    CR.Hist['PAYDATE']:=ChequeDate;
    CR.Hist['CHQNUM']:=ChequeNum; // Give each entry in the hist file a chq
number
    CR.Hist['TRNTYPE']:=CR.IPayInvs['TRNTYPE'];
    CR.Hist['BATCH']:=CR.IPayInvs['BATCH'];
    CR.Hist['BATCHPRINT']:=CR.IPayInvs['BATCHPRINT'];
    CR.Hist['REFERENCE']:=CR.IPayInvs['REFERENCE'];
    CR.Hist['SUMMARY']:=CR.IPayInvs['SUMMARY'];
    CR.Hist['AMOUNT']:=CR.IPayInvs['AMOUNT'];
    CR.Hist.Post;
   IPayInvs.Next;
  end
  until IPayInvs.EOF;
end;

 
 
 

1. Different detail Index order within master-detail relationship

Hi,
    I have 2 tables linked in a Master-Detail relationship using the
Mastersource/Masterfield properties of one of the table.  Whenever I try to
change the indexname property of the detail table to another index, all the
corresponding detail records disappeared. eg. I want the detail customer
table to show me a list of all customer ids for a corresponding master shop
table. The joined field in this case would be shop id.  In addition I want
the customer-ids of the particular shop id to be displayed based upon
customer-id order (but I can't seem to get it).

Thanks for any help rendered in advance!

2. QUESTION: List array, graph or network model support DB

3. Selecting from Master/Detail w/ Detail as columns of Master

4. SQL Server driver error

5. Cascading Delete Trigger in Master-Detail Relationships

6. IS IT POSSIBLE ?

7. DBGrid master/detail relationship?

8. FTP problems

9. Query on the subset in a master-detail table relationship

10. How to do a simple master-detail relationship?

11. Forms 6.0: Master-Detail Relationships

12. master-detail relationship with dBase expression index

13. Appling updates for master/detail relationship