0

I am currently trying to change properties for hug components depending on state of other component using what RTTI provide but i can't figure out how to retrieve all links between DataSource and DataAware components...

that's what i would like to achieve

  1. Get all components linked to specific DataSource something like.
  2. iterate through all those components.
  3. if the component accept ReadOnly property (by using RTTI i guess) i would like to change the property depending on the DataSet state:

    if DataSource.DataSet.state = dsbrowse then Component[i].ReadOnly := True
    if DataSource.DataSet.state = dsEdit then Component[i].ReadOnly := False

thanks in advance for help

Bruce McGee
  • 15,076
  • 6
  • 55
  • 70
S.FATEH
  • 451
  • 8
  • 16
  • What's wrong with the solution shown in your link? – Uwe Raabe Jun 29 '13 at 12:44
  • @Uwe Raabe could you provide some explanation the solution not clear enough at least for me.. – S.FATEH Jun 29 '13 at 12:51
  • what exactly is not clear for you? ask specific questions about what specific lines you do not understand. Otherwise you question means "read a textbook to me" and that is not good kind of questions. http://www.catb.org/~esr/faqs/smart-questions.html – Arioch 'The Jun 29 '13 at 14:30

1 Answers1

3

I'm not sure what problem you're trying to solve, because setting the TDataSource.AutoEdit property to False should automatically disable editing in the controls until you manually change the DataSet.State to one of the ones in dsEditModes.

With that being said, this will do what you're asking. It uses an accessor class to access the protected DataLinks list in a TDataSource, and then checks to see if it's a TFieldLink and also if it has the ReadOnly property.

// No Delphi version provided, so uses "older style" RTTI
uses
  TypInfo, DB, DBCtrls;

type
  THackDataSource=class(TDataSource);  // accessor class

procedure SetDataSetControlsReadOnly(const DataSource: TDataSource);
var
  i: Integer;
  DS: THackDataSource;
  DL: TDataLink;
  EnableIt: Boolean;
begin
  EnableIt := DataSource.State in dsEditModes;
  DS := THackDataSource(DataSource.DataSet);

  for i := 0 to DS.DataLinks.Count - 1 do
  begin
    DL := DS.DataLinks[i];
    if DL is TFieldDataLink then
    begin
      if IsPublishedProp(DL, 'ReadOnly') then
        SetOrdProp(DL, 'ReadOnly', Ord(EnableIt));
    end;
  end;
end;
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Ken White thanks in fact i wasn't aware of `TDataSource.AutoEdit` your code give me a lot of what i need about Delphi version it's D2010 i forget to mentioned it earlier... – S.FATEH Jun 29 '13 at 17:51