Cannot access component's object properties in design time - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Cannot access component's object properties in design time

I'm fairly [b]new[/b] to building components. I'm trying to use another custom object as a property in the component, but in design time the component's object properties which I'm trying to use are not working; that is, when I click on the [+] in the Object Inspector, nothing expands, and sometimes I get an error. I'm creating these objects on component's creation, and assigning the owner. The objects store various other properties. Everything works fine in run time, just not design time. Perhaps I'm declaring something wrong? I've also tried using TComponent as the inherited type, but still didn't work, actually got more errors.

[b]How I'm doing it:[/b]

(wrote the code here, didn't copy/paste it, so may be minor mistakes)

[code]

unit MyCustomComponent;

interface

uses
SysUtils, Classes, Controls, ComCtrls, Forms, Graphics, DB, ADODB;

type
TMyComponent = class;

TMyType = (myType1, myType2, myType3);

TMyObject = class(TObject)
Number: Integer;
Text: String;
SomeOtherObject: TObject;
MyType: TMyType;
end;

TMyComponent = class(TComponent)
private
FMyObject: TMyObject;

public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

published
property MyObject: TMyObject read FMyObject;

end;

procedure Register;

implementation

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

constructor TMyComponent.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMyObject:= TMyObject.Create;
end;

destructor TMyComponent.Destroy;
begin
if assigned(FMyObject) then FMyObject.Free;
inherited Destroy;
end;

end.

[/code]



Sign In or Register to comment.