|
Translation the names and values
TComponentInspector allows to change the displayed names and values on-the-fly by OnGetName, OnGetValue and OnSetValue events. The following code changes all properties and makes them more "human" with adding the space before each upper case character, so, for instance, the "ActiveControl" property is displayed as "Active Control".
procedure TMainForm.ComponentInspectorGetName(Sender: TObject;
TheIndex: Integer; var Value: String);
var
i: Integer;
begin
i:=1;
while i<=Length(Value) do
begin
if IsCharUpper(Value[i]) then
begin
Insert(' ',Value,i);
Inc(i);
end;
Inc(i);
end;
end;
The values can be changed too, but two events must be used. The following code shows how the "True" and "False" values can be replaced by "Yes" and "No".
procedure TMainForm.ComponentInspectorGetValue(Sender: TObject;
TheIndex: Integer; var Value: String);
var
Prop: TProperty;
begin
if Sender is TComponentInspector then
with TComponentInspector(Sender) do
begin
Prop:=Properties[TheIndex];
if Assigned(Prop) and (Prop.PropType=TypeInfo(Boolean)) and
(InplaceEditorType[TheIndex]<>ieCheckBox) then
if AnsiUpperCase(Value)='TRUE' then Value:='Yes'
else Value:='No';
end;
end;
procedure TMainForm.ComponentInspectorSetValue(Sender: TObject;
TheIndex: Integer; var Value: String; var EnableDefault: Boolean);
var
Prop: TProperty;
begin
if Sender is TComponentInspector then
with TComponentInspector(Sender) do
begin
Prop:=Properties[TheIndex];
if Assigned(Prop) and (Prop.PropType=TypeInfo(Boolean)) and
(InplaceEditorType[TheIndex]<>ieCheckBox) then
if AnsiUpperCase(Value)='YES' then Value:='True'
else Value:='False';
end;
end;
As the used Boolean properties have the drop-down list with the "True" and "False" in the list, the values in the list must be changed too. It can be realized with the OnGetValuesList event.
procedure TMainForm.ComponentInspectorGetValuesList(Sender: TObject;
TheIndex: Integer; const Strings: TStrings);
var
Prop: TProperty;
begin
if Sender is TComponentInspector then
with TComponentInspector(Sender) do
begin
Prop:=Properties[TheIndex];
if Assigned(Prop) and (Prop.PropType=TypeInfo(Boolean)) and
Assigned(Strings) then Strings.Text:='No'#13'Yes';
end;
end;
|