Главная страница | назад





Article #20566: Master/Detail relationships with data-aware controls.

Question:

Why are my Master/Detail relationships not showing the correct detail in the data-aware controls when I scroll through the master?

Answer:

This is a known bug in Delphi 5 and will be fixed. It seems to only happen with queries. Using persistent fields will make it worse. Here is a good workaround which was posted on the borland newsgroup. It requires editing and recompiling the file 'dbctrls.pas' which comes with Delphi.

First find the file 'dbctrls.dcu' on your machine. If you did a default install it should be at 'C:\Program Files\Borland\Delphi5\Source\Vcl'. Rename this to something like 'dbctrls_ORIGINAL.dcu' so you can get it back later if you want. Next start a new, blank application and open the file 'C:\Program Files\Borland\Delphi5\Source\Vcl\dbctrls.pas'. Add Dbctrls to the uses clause of the blank project. Find the definition for procedure TFieldDataLink.UpdateField; and change the code to the following. You may want to just comment out the code that is there in order to save it.

  procedure TFieldDataLink.UpdateField;
  var
    TempField : TField;
  begin
    if Active and (FFieldName <> '') then
    begin
      if Assigned(FControl) then
        TempField := GetFieldProperty(DataSource.DataSet, FControl, FFieldName)
      else
        TempField := DataSource.DataSet.FieldByName(FFieldName);
      if TempField <> FField then
        SetField(TempField)
      else
        begin
          FField := NIL;
          SetField(TempField);
        end;
    end
    else
      SetField(nil);
  end;


Finally, save and Build All Projects (Projects menu). If you get an error that 'dbctrls.dcu' cannot be found then you need to go into Tools|Environment Options|Library and add the path C:\Program Files\Borland\Delphi5\Source\Vcl (or whatever your actual path to the Vcl directory is) to the Library Path.

Now you should be able to compile and create a new 'dbctrls.dcu' file, and your data-aware controls should be updating.

Last Modified: 11-OCT-00