我写了个控件(从TPanel继承),需要在设计期根据载入的配置文件来动态生成新控件,同时可以保存本控件上的其他控件,用的是ComponentToString和StringToComponent来保存和载入。但是在设计期载入配置文件,生成的控件不能被编辑,和运行期一样。
请问如何才能在设计期动态生成可以被编辑的控件?就是说,在设计期生成设计期的控件。
谢谢 

解决方案 »

  1.   

    procedure TFrmProp.GetProp(Component: TComponent; VEdit: TValueListEditor);
    var
      Count, Size, I, J : Integer;
      PropInfo          : PPropInfo;
      PropData          : PTypeData;
      PropValue         : string;
      PropEdit          : TPropEditor;
      PropObject        : TComponent;
    begin
      Count := GetPropList(Component.ClassInfo, tkProperties, nil);
      Size := Count * SizeOf(Pointer);
      FreeMem(FPropList);
      GetMem(FPropList, Size);
      Count := GetPropList(Component.ClassInfo, tkProperties, FPropList);
      ClearPropEditors;
      for I := 0 to Count - 1 do
      begin
        PropInfo := FPropList^[I];
        PropEdit := nil;
        if IsPublishedProp(Component, PropInfo^.Name) then
        begin
          PropEdit := CreatePropEditor(Component, FOwnerComponent, PropInfo^.Name);
          if Assigned(PropEdit) then
          begin
            FPropEditorList.Add(PropEdit);
            //PropValue := GetPropValue(Component, PropInfo^.Name);
            PropValue := PropEdit.Value;
            VEdit.Strings.Add(Format(VStr, [PropInfo^.Name, PropValue]));
            SetPropEdit(PropEdit, VEdit, VEdit.Strings.Count - 1);
          end;
        end;
      end;
    end;
      

  2.   

    楼上的大哥,谢谢回复,但好象你没贴完啊~~
    比如ClearPropEditors、CreatePropEditor这些是你的自定义过程吧?
    都请贴一下啊,谢谢!
      

  3.   

    我晕~`
    CSDN怎么这样了啊~~这么多天都没人理~~~
    5555555555~~~~~~~~~~~~~~~~~