From 24b1fe15875cfa5182a53da796376b06aac5871c Mon Sep 17 00:00:00 2001 From: mattias Date: Mon, 26 Sep 2005 23:29:43 +0000 Subject: [PATCH] added function to RTTI controls to easily set alias values git-svn-id: trunk@7840 - --- components/rtticontrols/rttictrls.pas | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/components/rtticontrols/rttictrls.pas b/components/rtticontrols/rttictrls.pas index d301274903..8b7d8962b0 100644 --- a/components/rtticontrols/rttictrls.pas +++ b/components/rtticontrols/rttictrls.pas @@ -82,6 +82,8 @@ Type TTestEditing = function(Sender: TObject): boolean of object; + { TCustomPropertyLink } + TCustomPropertyLink = class(TPersistent) private FAliasValues: TAliasStrings; @@ -153,6 +155,7 @@ Type IfNoValuesAvailableAddAllAlias: boolean); procedure AssignCollectedAliasValuesTo(DestList: TStrings); function HasAliasValues: boolean; + procedure BuildEnumAliasValues(AStringArray: PString); public // for Set property editors procedure AssignSetEnumsAliasTo(DestList: TStrings); @@ -1348,12 +1351,33 @@ Type function GetPropertyLinkOfComponent(AComponent: TComponent ): TCustomPropertyLink; +procedure CreateEnumAliasValues(EnumType: PTypeInfo; List: TStrings; + AStringArray: PString); procedure Register; 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 ): TCustomPropertyLink; @@ -1849,6 +1873,24 @@ begin Result:=(AliasValues<>nil) and (AliasValues.Count>0); 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); var Enums: TStringList;