Jump to content
PeterPanettone

Get CLASSNAME of component

Recommended Posts

I want to either expand the functionality of the Get Component Names GExpert to somehow include the CLASSNAME of the selected component(s) or to create a similar GExpert which gets the CLASSNAME instead of the component name.

 

(The former solution could include an additional keyboard-shortcut configuration for the classname, inside the same GExpert).

 

So I looked at the GxOtaGetComponentName function:

 

function GxOtaGetComponentName(const AComponent: IOTAComponent): WideString;
var
  Component: TComponent;
begin
  Assert(Assigned(AComponent));
  Result := GxOtaGetComponentPropertyAsString(AComponent, NamePropertyName);
  if IsEmpty(Result) then
  begin
    Component := GxOtaGetNativeComponent(AComponent);
    if Assigned(Component) then
      Result := Component.Name;
  end;
end;

The parameter NamePropertyName is defined as a constant with the value 'Name'.

 

Since there is no constant NamePropertyClassName, I assume that the class name of a component can be in any case simply retrieved by Component.ClassName and has not necessarily be retrieved by GxOtaGetComponentPropertyAsString.

 

So I would naively propose this function to get the class name:

 

function GxOtaGetComponentClassName(const AComponent: IOTAComponent): WideString;
var
  Component: TComponent;
begin
  Result := '';
  Assert(Assigned(AComponent));

  Component := GxOtaGetNativeComponent(AComponent);
  if Assigned(Component) then
    Result := Component.ClassName;
end;

What do you think?

Share this post


Link to post

Now I have tried it out by replacing the old function GxOtaGetComponentName with the new function GxOtaGetComponentClassName in the unit GX_CopyComponentNames:

 

CurrentComponent := FormEditor.GetSelComponent(i);
//ComponentName := GxOtaGetComponentName(CurrentComponent);
ComponentName := GxOtaGetComponentClassName(CurrentComponent);

It works perfectly.

 

Now it's time to decide how the new functionality Get Component ClassNames should be implemented:

 

1. Combine the component name and class name in one string, e.g.: ComponentName (ComponentClassname)

 

2. Provide a second keyboard-shortcut box for the class name inside the existing GExpert, e.g. F5 for the component name and CTRL+F5 for the component class name

 

3. Create a separate GExpert for the component's class name.

 

Plus: Provide a small configuration dialog where one of the above choices could be configured.

 

image.png.8f07286b19b75006fb50be29d2c7c726.png

 

Please select your favorite choice.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×