BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

dbExpress: MAster Detail

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (dbExpress)
View previous topic :: View next topic  
Author Message
Slavisa Cicovic
Guest





PostPosted: Fri Jan 30, 2004 2:40 am    Post subject: dbExpress: MAster Detail Reply with quote



I make SQLTables in m-d relationship, link master ClientDataSet to
DataSetProvider, and details to master's DataSetFields.

( For genereting AutoInc fields I'm using schema from Eric Harmon book
'Delphi/Kilyx database development'):
1.(All 3 cds have field ID)
procedure TDataModule2.ClientDataSet1NewRecord(DataSet: TDataSet);
begin
DataSet.FieldByName('ID').AsInteger :=
GetNextID(DataSet as TCustomClientDataSet, 'ID');
end;
2. sqlGuestsTable is a master and has field ID which is pk,
sqlGuestsIDsTable has field GUEST_ID which is fk,
sqlGuestsResTable has field GUEST_ID which is fk, to
FGuestID: integer is private field in DataModule2. For new record on
master cds FGuestID holds master ID, and it works fine for new master's
records, but not for details. Whats wrong?

procedure TDataModule2.pvGuestsBeforeUpdateRecord(Sender: TObject;
SourceDS: TDataSet; DeltaDS: TCustomClientDataSet;
UpdateKind: TUpdateKind; var Applied: Boolean);
begin
if UpdateKind = ukInsert then
begin
if DeltaDS.FieldByName('ID').OldValue <= 0 then
DeltaDS.FieldByName('ID').NewValue := ServerGetNextID;
if SourceDS = sqlGuestsTable then
FGuestID := DeltaDS.FieldByName('ID').NewValue;
if SourceDS = sqlGuestIDsTable then
begin
DeltaDS.FieldByName('GUEST_ID').NewValue := FGuestID;
end;
if SourceDS = sqlGuestResTable then
DeltaDS.FieldByName('GUEST_ID').NewValue := FGuestID;
end;
end;


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (dbExpress) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.