mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-29 03:24:58 +02:00
added function to RTTI controls to easily set alias values
git-svn-id: trunk@7840 -
This commit is contained in:
parent
b0f71e6cd3
commit
24b1fe1587
@ -82,6 +82,8 @@ Type
|
|||||||
|
|
||||||
TTestEditing = function(Sender: TObject): boolean of object;
|
TTestEditing = function(Sender: TObject): boolean of object;
|
||||||
|
|
||||||
|
{ TCustomPropertyLink }
|
||||||
|
|
||||||
TCustomPropertyLink = class(TPersistent)
|
TCustomPropertyLink = class(TPersistent)
|
||||||
private
|
private
|
||||||
FAliasValues: TAliasStrings;
|
FAliasValues: TAliasStrings;
|
||||||
@ -153,6 +155,7 @@ Type
|
|||||||
IfNoValuesAvailableAddAllAlias: boolean);
|
IfNoValuesAvailableAddAllAlias: boolean);
|
||||||
procedure AssignCollectedAliasValuesTo(DestList: TStrings);
|
procedure AssignCollectedAliasValuesTo(DestList: TStrings);
|
||||||
function HasAliasValues: boolean;
|
function HasAliasValues: boolean;
|
||||||
|
procedure BuildEnumAliasValues(AStringArray: PString);
|
||||||
public
|
public
|
||||||
// for Set property editors
|
// for Set property editors
|
||||||
procedure AssignSetEnumsAliasTo(DestList: TStrings);
|
procedure AssignSetEnumsAliasTo(DestList: TStrings);
|
||||||
@ -1348,12 +1351,33 @@ Type
|
|||||||
|
|
||||||
function GetPropertyLinkOfComponent(AComponent: TComponent
|
function GetPropertyLinkOfComponent(AComponent: TComponent
|
||||||
): TCustomPropertyLink;
|
): TCustomPropertyLink;
|
||||||
|
procedure CreateEnumAliasValues(EnumType: PTypeInfo; List: TStrings;
|
||||||
|
AStringArray: PString);
|
||||||
|
|
||||||
procedure Register;
|
procedure Register;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
procedure CreateEnumAliasValues(EnumType: PTypeInfo; List: TStrings;
|
||||||
|
AStringArray: PString);
|
||||||
|
var
|
||||||
|
AName: String;
|
||||||
|
AnAliasName: String;
|
||||||
|
i: LongInt;
|
||||||
|
begin
|
||||||
|
List.BeginUpdate;
|
||||||
|
List.Clear;
|
||||||
|
//debugln('CreateEnumAliasValues ',EnumType^.Name);
|
||||||
|
with GetTypeData(EnumType)^ do
|
||||||
|
for i := MinValue to MaxValue do begin
|
||||||
|
AName := GetEnumName(EnumType, i);
|
||||||
|
AnAliasName := AStringArray[i];
|
||||||
|
//debugln('CreateEnumAliasValues ',AName+'='+AnAliasName);
|
||||||
|
List.Add(AName+'='+AnAliasName);
|
||||||
|
end;
|
||||||
|
List.EndUpdate;
|
||||||
|
end;
|
||||||
|
|
||||||
function GetPropertyLinkOfComponent(AComponent: TComponent
|
function GetPropertyLinkOfComponent(AComponent: TComponent
|
||||||
): TCustomPropertyLink;
|
): TCustomPropertyLink;
|
||||||
@ -1849,6 +1873,24 @@ begin
|
|||||||
Result:=(AliasValues<>nil) and (AliasValues.Count>0);
|
Result:=(AliasValues<>nil) and (AliasValues.Count>0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomPropertyLink.BuildEnumAliasValues(AStringArray: PString);
|
||||||
|
{ Example:
|
||||||
|
|
||||||
|
type
|
||||||
|
TMyEnum = (enum1,enum2);
|
||||||
|
const
|
||||||
|
MyEnumNamesArray: array[TMyEnum] of string = ('Enum1','Enum2');
|
||||||
|
|
||||||
|
MyTIComboBox.Link.BuildEnumAliasValues(@MyEnumNamesArray[TMyEnum(0)]);
|
||||||
|
}
|
||||||
|
begin
|
||||||
|
CreateEditor;
|
||||||
|
if (Editor=nil) or (not (Editor is TEnumPropertyEditor)) then exit;
|
||||||
|
CreateEnumAliasValues(Editor.GetPropType,AliasValues,AStringArray);
|
||||||
|
if Assigned(OnEditorChanged) then
|
||||||
|
OnEditorChanged(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomPropertyLink.AssignSetEnumsAliasTo(DestList: TStrings);
|
procedure TCustomPropertyLink.AssignSetEnumsAliasTo(DestList: TStrings);
|
||||||
var
|
var
|
||||||
Enums: TStringList;
|
Enums: TStringList;
|
||||||
|
Loading…
Reference in New Issue
Block a user