⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 se_designer.pas

📁 小区水费管理系统源代码水费收费管理系统 水费收费管理系统
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    InsertToLog(Format('Create copy of "%s" component.', [Result.Name]));
    { Set Control property }
    if AComp is TControl then
    begin
      TControl(Result).Parent := TControl(AComp).Parent;
    end;
    { Copy properties }
    InsertToLog(Format('Copy "%s"''s properties.', [Result.Name]));
    try
      CopyExistsProperties(AComp, Result);
    except
      InsertToLog('!!! Properties convertion error : '+AComp.Name);
    end;
    { Set Advanced Properties }
    SetAdvancedProp(AComp, Result);
    { Delete old }
    if AComp is TControl then
      C := THackControl(AComp).Caption;
    AComp.Free;
    { Rename }
    if Result is TControl then
    begin
      Result.Name := OldName;
      THackControl(Result).Caption := C;
    end
    else
      Result.Name := OldName;
  end;
  InsertToLog('');
end;

{ Virtual }

function TSeCustomConverter.GetClass(ClassKind: TSeClassKind): TComponentClass;
begin
  case ClassKind of
    ckButton: Result := TSeCustomButton;
    ckEdit: Result := TSeCustomEdit;
    ckGroupBox: Result := TSeCustomGroupBox;
  else
    Result := nil;
  end;
end;

procedure TSeCustomConverter.SetAdvancedProp(AOldObject, ANewObject: TObject);
var
  i: integer;
  Control: TControl;
begin
  { Set Parent on children controls }
  if (FForm <> nil) and (AOldObject is TWinControl) and (csAcceptsControls in (AOldObject as TWinControl).ControlStyle) then
  begin
    for i := 0 to FForm.ComponentCount - 1 do
      if FForm.Components[i] is TControl then
      begin
        Control := FForm.Components[i] as TControl;
        if Control.Parent = (AOldObject as TControl) then
          THackControl(Control).SetParent(ANewObject as TWinControl);
      end;
  end;

  { For Button }
  if (ANewObject is TSeCustomButton) and (AOldObject is TWinControl) then
  begin
    (ANewObject as TSeCustomButton).Caption := THackControl(AOldObject).Caption;
  end;

  { GroupBox }
  if (ANewObject is TSeCustomGroupBox) and (AOldObject is TGroupBox) then
    TSeCustomGroupBox(ANewObject).Caption := TGroupBox(AOldObject).Caption;

  { ComboBox }
  if (ANewObject is TSeCustomComboBox) and (AOldObject is TComboBox) then
  begin
    case TComboBox(AOldObject).Style of
      csDropDown: TSeCustomComboBox(ANewObject).ComboStyle := kcsDropDown;
      csDropDownList: TSeCustomComboBox(ANewObject).ComboStyle := kcsDropDownList;
    end;
  end;

  { Panel }
  if (ANewObject is TSeCustomPanel) and (AOldObject is TPanel) then
  begin
    TSeCustomPanel(ANewObject).ShowCaption := false;
  end;

  { StatusBar }
  if (ANewObject is TSeCustomStatusBar) and (AOldObject is TStatusBar) then
  begin
    if TSeCustomStatusBar(ANewObject).Panels.Count > 0 then
      TSeCustomStatusBar(ANewObject).Panels[TSeCustomStatusBar(ANewObject).Panels.Count - 1].StretchPriority := 100;
  end;

  { Header }
  if (ANewObject is TSeCustomHeaderControl) and (AOldObject is THeaderControl) then
  begin
    TControl(ANewObject).BoundsRect := TControl(AOldObject).BoundsRect;
  end;

  { ProgressBar }
  if (ANewObject is TSeCustomProgressBar) and (AOldObject is TProgressBar) then
  begin
    TSeCustomProgressBar(ANewObject).Orientation := TSeBarOrientation(TProgressBar(AOldObject).Orientation);
  end;

  { Splitter }
  if (ANewObject is TSeCustomSplitter) and (AOldObject is TSplitter) then
  begin
    if TSplitter(AOldObject).Align in [alTop, alBottom] then
      TSeCustomSplitter(ANewObject).Height := TSplitter(AOldObject).Height; 
  end;
end;

{ Internal routines }

procedure TSeCustomConverter.CopyPropertyValue(Source, Dest: TObject; APropName: string);
var
  SourcePropInfo: PPropInfo;
  DestPropInfo: PPropInfo;
  SourceObjectProp, DestObjectProp: TObject;
  SetPropValue: string;
begin
  { Copy property PropName value from source to dest }
  SourcePropInfo := GetPropInfo(Source.ClassInfo, APropName);
  if SourcePropInfo = nil then Exit;

  DestPropInfo := GetPropInfo(Dest.ClassInfo, APropName);
  if DestPropInfo = nil then Exit;

  if Dest is TComponent then
    InsertToLog(Format('  Copy "%s.%s" property.', [TComponent(Dest).Name, APropName]));

  { Copy }
  if SourcePropInfo^.PropType^.Kind = DestPropInfo^.PropType^.Kind then
  begin
    case SourcePropInfo^.PropType^.Kind of
      tkInteger, tkChar: SetOrdProp(Dest, DestPropInfo, GetOrdProp(Source, SourcePropInfo));
      tkFloat: SetFloatProp(Dest, DestPropInfo, GetFloatProp(Source, SourcePropInfo));
      tkString, tkWString, tkWChar, tkLString: SetStrProp(Dest, DestPropInfo, GetStrProp(Source, SourcePropInfo));
      {$IFDEF KS_COMPILER5_UP}
      tkEnumeration: SetEnumProp(Dest, DestPropInfo, GetEnumProp(Source, SourcePropInfo));
      tkSet: begin
        SetPropValue := '['+GetSetProp(Source, SourcePropInfo)+']';
        SetSetProp(Dest, DestPropInfo, SetPropValue);
      end;
      tkClass: begin
        SourceObjectProp := GetObjectProp(Source, SourcePropInfo);
        DestObjectProp := GetObjectProp(Dest, DestPropInfo);

        if (SourceObjectProp is TPersistent) and not (SourceObjectProp is TComponent) then
          TPersistent(DestObjectProp).Assign(TPersistent(SourceObjectProp))
        else
          SetObjectProp(Dest, DestPropInfo, SourceObjectProp);
      end;
      {$ELSE}
      tkClass: begin
        SourceObjectProp := TObject(GetOrdProp(Source, SourcePropInfo));
        DestObjectProp := TObject(GetOrdProp(Dest, DestPropInfo));

        if (SourceObjectProp is TPersistent) and not (SourceObjectProp is TComponent) then
          TPersistent(DestObjectProp).Assign(TPersistent(SourceObjectProp))
        else
          SetOrdProp(Dest, DestPropInfo, Integer(SourceObjectProp));
      end;
      {$ENDIF}
      tkMethod: SetMethodProp(Dest, DestPropInfo, GetMethodProp(Source, SourcePropInfo));
    end;
  end;
end;

procedure TSeCustomConverter.CopyExistsProperties(Source, Dest: TObject);
var
  PropList: PPropList;
  ClassTypeInfo: PTypeInfo;
  ClassTypeData: PTypeData;
  i: integer;
begin
  if (Source = nil) or (Dest = nil) then Exit;

  ClassTypeInfo := Dest.ClassInfo;
  ClassTypeData := GetTypeData(ClassTypeInfo);

  if ClassTypeData.PropCount <> 0 then
  begin
    { allocate the memory needed to hold the references to the TPropInfo }
    { structures on the number of properties. }
    GetMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
    try
      { fill PropList with the pointer references to the TPropInfo structures }
      GetPropInfos(Dest.ClassInfo, PropList);
      for i := 0 to ClassTypeData.PropCount - 1 do
      begin
        if LowerCase(PropList[i]^.Name) = 'name' then Continue;
        if LowerCase(PropList[i]^.Name) = 'orientation' then Continue;
        { Copy property's value }
        CopyPropertyValue(Source, Dest, PropList[i]^.Name);
      end;
    finally
      FreeMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
    end;
  end;
end;

procedure TSeCustomConverter.SetPropertyIfExists(AComp: Tcomponent;
  APropName: string; Value: TObject);
var
  PropInfo: PPropInfo;
begin
  PropInfo := GetPropInfo(AComp.ClassInfo, APropName);
  if PropInfo = nil then Exit;

  SetOrdProp(AComp, PropInfo, Integer(Value));
end;

procedure TSeCustomConverter.InsertToLog(Line: string);
begin
  if FLog <> nil then
    FLog.Add(Line);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -