1

I have a Component inherited of the TFrame... But my published properties don't save the values in .dfm... The error occurs when closing Delphi and open again, reloading the project.

This error is: "Error reading MyComponent1.Obs: property Obs does not exists..."

TMyComponent = class(TFrame)
   FObs: string;
   procedure SetObs(const Value: string);
published
   property Obs: string read FObs write SetObs;
end;

procedure register;

implementation

procedure register;
begin
   RegisterComponents('My Components', [TMyComponent]);
end;

procedure TMyComponent .SetObs(const Value: string);
begin
  if FObs <> Value then
    FObs := Value; 
end;
Seeko
  • 75
  • 1
  • 8
  • Did you install the component package into the IDE? – LU RD May 30 '16 at 13:29
  • yes, is an installation package, however, as stated above, does not save the value of the Algarve Property in dfm... If I change the TFrame inheritance to TEdit, for example, this problem does not happen – Seeko May 30 '16 at 13:36
  • Don't you need to use a different function to register a frame – David Heffernan May 30 '16 at 13:52
  • unfortunately I do not know. Already I researched some things, did tests, but without success. – Seeko May 30 '16 at 14:02
  • http://stackoverflow.com/questions/3733216/register-custom-form-so-i-can-inherit-from-it-from-multiple-projects-without-co – David Heffernan May 30 '16 at 14:27
  • FWIW I cannot see the point of registering a frame descendent as a component – David Heffernan May 30 '16 at 14:28
  • It may prevent certain errors opening the form that uses that frame descendent maybe? I don't know. – Warren P May 30 '16 at 16:25
  • I have no other frames that inherit of TMyComponent ... – Seeko May 30 '16 at 16:40
  • 1
    I personally assemble my forms that contain frames only at runtime, in code, and I don't use TFrame designtime composition at all, because I find it easier. You might find it easier to switch your problematic forms to have the frames inserted at runtime instead of at designtime, even without changing them from TFrame to something else. – Warren P May 30 '16 at 16:56
  • I understand ... The problem is that this component would be used much ... So the preference not to use it at runtime ... – Seeko May 30 '16 at 17:04
  • Such error indicates that property was successfully stored in file, you can open dfm in notepad and see it here. So it comes to line `obs='sometext'` and begin to seek property with such name in a class which it believes to load, but there is no such property. It narrows down the problem: class name may be stored wrong. But I couldn't reproduce your error: I've created component, installed it on component palette, added this frame to form, changed property, saved project, loaded it again: everything works fine. Please add contents of dfm file to your question. – Yuriy Afanasenkov May 31 '16 at 03:28

1 Answers1

1

I've managed to reproduce the error and then fix it, but can't understand exactly why it happens so, has to do with visual inheritance which works in rather complex way (hope David or Remy could explain what happens here).

First of all, this error indicates that property actually was saved to dfm file. Point is, it's perfectly normal situation when some properties are absent in dfm, it just means that property must have default value (or value which ancestor had), so IDE never raises error because it didn't find some property in file.

Here the opposite happens: property 'obs' was found in dfm, but wasn't found in class itself. The same happened when I created new project and then added frame unit to project itself. It seems, in that case visual inheritance took place instead of normal inheritance, which is: IDE found, that class TMyComponent is described in 'visual' unit belonging to project, found that line:

TMyComponent = class (TFrame)

and made TMyComponent merely alias for TFrame. That's why error occurred: TFrame really doesn't have 'obs' property.

And here is workaround: Don't add this frame to project itself. Instead, add frame from component palette. This way it works as expected. If IDE can't find files of this component, add folder containing them to search path.

Yuriy Afanasenkov
  • 1,440
  • 8
  • 12