Based only on the following portion of the first paragraph of your question
there is a procedure InitCombo that needs to be invoked in the implementation.
It appears you're confused about at least a couple of things about writing components.
First, you initialize the component properties either in its constructor to initialize things, or in an overridden Loaded
method, which is called after the component is streamed in from the .dfm file where the component was used. Note that Loaded
changes should not touch properties or events that the user can set in the Object Inspector, because doing so will prevent the user's settings from being used.
constructor TNewComponent.Create(AOwner: TComponent);
begin
inherited;
// Do your stuff here
end;
procedure TNewComponent.Loaded;
begin
// Do your stuff here
end;
Second, events that are published (that can be seen in the Events tab of the Object Inspector) belong to the programmer that is using the component, not the component author. Never do anything to those event handlers. Your component should never touch those events except to call them if the end user has assigned a handler. So the code below is absolutely incorrect, because the OnChange
event belongs to the user of your component, not your component code:
procedure TNewComponent.InitCombo; //TComboBox ancestor
begin
FStoredItems.OnChange := nil;
...
FStoredItems.OnChange := StoredItemsChange;
end;
If you absolutely must do this, you need to do it properly by saving any event handler the end user has assigned, and restore it afterward:
procedure TNewComponent.InitCombo;
var
OldOnChange: TNotifyEvent;
begin
OldOnChange := Self.OnChange;
// Do your stuff here
Self.OnChange := OldOnChange;
end;
Third, unless you're using a class procedure
or class function
, you cannot call a method on a class itself (in other words, you cannot use TNewComponent.DoSomething
). You call methods or access properties on an instance of the component itself. In your component code, that would be done by using Self
, which refers to the current implemented component, as in Self.DoSomething
.