Hello,
I am writing my own component that will work with the Lazarus component palette.
I need to create a component instance based on a class but something goes wrong:
function TSpaceDesingerPaletteEditorForm.GetComponentForNameRegisteredComponent(
const ComponentName: string): TRegisteredComponent;
var
i: integer;
Component: TRegisteredComponent;
begin
for i := 0 to IDEComponentPalette.Comps.Count - 1 do
begin
Component := IDEComponentPalette.Comps[i];
if (Component.OrigPageName <> '') and
(Component.ComponentClass.ClassName = ComponentName) then
begin
if Assigned(Component) and Component.Visible then
begin
Result := Component;
Break;
end;
end;
end;
end;
This function is fine returns the selected component.
And I'm trying to create a component instance like this:
procedure TSpaceDesingerPaletteEditorForm.Button1Click(Sender: TObject);
var
Component: TRegisteredComponent;
C: TComponent;
begin
with ListBoxPalette do
begin
Component := GetComponentForNameRegisteredComponent('TButton');
C := TComponent(Component.newinstance).Create(Self);
ShowMessage(C.ClassName);
end;
end;
After compiling and installing the component after opening its editor. I get an error here:
ShowMessage(C.ClassName); //this error