Master-detail-detail-detial with Cascade delete 
Author Message
 Master-detail-detail-detial with Cascade delete

I am currently working with MASTER-DETAIL-DETAIL-DETAIL relationship
in Delphi.
        The problem I have is when I try to cascade-delete these
records in Paradox tables. If the four tables and the first master
record
has full relationship with its children (means every detail-index key
has its sub-detail records), then the cascade-deleting of the four table
is O.K. However, if the first master record DOESN'T HAVE a full
relationship with its children (means the sub-detail and sub-sub-detail
records are empty), then the current pointer of the current detial
record
doesn't want to move or point to the next record.

                                MASTER-RECORD
                                     |
                -----------------------------------------
                |                    |                  |
        DETAIL-RECORD 1        DETAIL-REC 2     DETAIL-REC 3
                                     |
                        -------------------------
                        |                       |
                SUB-DETAIL-REC 1          SUB-DETAIL-REC 2
                        |                       |
        ---------------------------             |      
        |               |         |             |
SUB-SUB-DETAIL REC1   REC2      REC3     SUB-SUB-DETAIL-REC 4            

PROBLEM--> My pointer stops at DETAIL-RECORD1 after the first          
cascade-delete.

**** Please, any body help ?????


****************** BELOW IS THE PORTION OF MY SOURCE CODE *************

procedure TForm1.Table1BeforeDelete(DataSet: TDataset);
begin
   with Table2 do begin
      Try
        Try
         REFRESH;
        { First; }
         DisableControls;
        { IF FindKey([Table1.Fields[0].AsString]) THEN }
             while {(Fields[1].Asstring = Table1.Fields[0].Asstring)
and} (not EOF) do
             begin
                Table3.FindKey([Table2.Fields[0].AsString]);
                Delete;
             end;
        Finally
         EnableControls;
        end
      except
         on E: EDataBaseError  do
         If MessageDLG(E.Message + ' Delete your next layers. Continue
?',mtInformation,[mbYes,mbNo],0)=mrYes then
             Table1.Delete
         else
           Cancel;
      end; {End Tryig}
   end; {end Table2}

end;

procedure TForm1.Table2BeforeDelete(DataSet: TDataset);
begin
    with Table3 do begin
      Try
         REFRESH;
         IF State <> dsEdit then Edit;
        { Post;}
         First;
        DisableControls;
        FindKey([Table2.Fields[0].AsString]);
           while (Fields[1].Asstring = Table2.Fields[0].Asstring) and
(not EOF) do
             Delete;
      Finally
         EnableControls;
      end;
   end;

end;

procedure TForm1.Table3BeforeDelete(DataSet: TDataset);
begin
     with Table4 do begin
       Try
         REFRESH;
         if State <> dsEdit then Edit;
        { Post;  }
         First;
         DisableControls;
      {   IF FindKey([Table3.Fields[0].AsString]) THEN  }
           while {(Fields[1].Asstring = Table3.Fields[0].Asstring) and}
(not EOF) do
             Delete;
       Finally
         EnableControls;
       end;
     end;
end;

procedure TForm1.Table1AfterDelete(DataSet: TDataset);
begin
     Table1.SetRangeStart;

end;

procedure TForm1.Table2AfterDelete(DataSet: TDataset);
begin
      Table2.Edit;
      Table2.UpdateRecord;
      Table2.Post;
      Table3.Edit;
      Table3.UpdateRecord;
      Table3.Post;

      tABLE3.nEXT;
      Table3.GotoKey;
      Table3.MoveBy(1);
      Table3.FindKey([Table2.Fields[0].AsString]);
end;

procedure TForm1.Table3AfterDelete(DataSet: TDataset);
begin
    {Table3.UpdateRecord; }
end;

--

     WwwwwwW
  g(   o 0    )g
--oOO--(_)---OOo-------------------------------------------------------
                   Jack Ratiwanich,
                   1529 Paradise Lane, Cocoa FL 32922, U.S.A
                   Telephone Home: (407) 631-8465  Fax:(407) 638-1010
                   Work: (407) 638-1511   Suncom: 8-364-1511    


----\ (---) /----------------------- -----------------------------------
     \_) (_/  "Bisous..."



Mon, 08 Mar 1999 03:00:00 GMT  
 Master-detail-detail-detial with Cascade delete

Quote:

>I am currently working with MASTER-DETAIL-DETAIL-DETAIL relationship
>in Delphi.
>    The problem I have is when I try to cascade-delete these
>records in Paradox tables. If the four tables and the first master
>record
>has full relationship with its children (means every detail-index key
>has its sub-detail records), then the cascade-deleting of the four table
>is O.K. However, if the first master record DOESN'T HAVE a full
>relationship with its children (means the sub-detail and sub-sub-detail
>records are empty), then the current pointer of the current detial
>record
>doesn't want to move or point to the next record.
>PROBLEM--> My pointer stops at DETAIL-RECORD1 after the first          
>cascade-delete.

If your tables are related via MasterSource - MasterFields, you don't have to
search for the records that are inside the branch which is to be deleted, you
just delete all visible records.

So, try writing your events like this:

procedure TForm1.Table1BeforeDelete(DataSet: TDataset);
        begin
        with Table2 do
                begin
                DisableControls;
                try
                        Refresh;
                        First;
                        while not EOF do Delete;
                finally
                        EnableControls;
                end;
        end;

procedure TForm1.Table2BeforeDelete(DataSet: TDataset);
        begin
        with Table3 do
                begin
                DisableControls;
                try
                        Refresh;
                        First;
                        while not EOF do Delete;
                finally
                        EnableControls;
                end;
        end;

procedure TForm1.Table3BeforeDelete(DataSet: TDataset);
        begin
        with Table4 do
                begin
                DisableControls;
                try
                        Refresh;
                        First;
                        while not EOF do Delete;
                finally
                        EnableControls;
                end;

You DON'T NEED the extra AfterDelete events !
In fact, the're probably the reason why your method
did not work (you moved around too much).

  Danijel Tkalcec,
  Croatia.

My point of view :)

  *************
  * " The real beauty of human being is defined
  *     in the first place by how much and in which
  *        way has it released itself from its ego. "
  ************************
      Albert Eistein,
      Mein Weltbild, Amsterdam:
      Querido Verlag, 1934.



Thu, 11 Mar 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. MASTER/DETAIL with Cascading Deletes???? Need Help

2. Master/Detail Cascading Deletes???

3. Master-Detail : Sorting Detail?

4. Master - Detail - Detail queries & DBGrids

5. Setting report variables in the detail of a ReportSmith master-detail report

6. Master/Detail lookup - losing detail field

7. Newbie - updating Detail in master-detail

8. HELP: Master-detail form: sequence of detail records

9. Sorting detail records in a master detail relation.

10. Problem when inserting records in the detail table (master/detail relation)

11. Different detail Index order within master-detail relationship

12. Master->Detail->Detail Query Too Slow

 

 
Powered by phpBB® Forum Software