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

📄 tsdesign.pas

📁 企业进销存管理系统
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    else
    begin
        if Parent <> nil then
        begin
            ParentValue := Parent.GetPropertyValue(Component, True);
            if VarIsEmpty(ParentValue) then
            begin
                ParentValue := ParentValue;
                exit;
            end;
            Component := Pointer(integer(ParentValue));
            if Component = nil then
            begin
                ParentValue := ParentValue;
                exit;
            end;
        end;

        if PropInfo.PropType = nil then
            exit;

        case PropInfo.PropType^.Kind of
            tkChar, tkString, tkWChar, tkLString,
            {$IFDEF TSVER_V3} tkWString {$ELSE} tkLWString {$ENDIF}:
                SetStrProp(Component, PropInfo, VarToStr(Value));
            tkFloat:
                SetFloatProp(Component, PropInfo, Value);
            tkVariant:
                SetVariantProp(Component, PropInfo, Value);
            else
                SetOrdProp(Component, PropInfo, Value);
        end;
    end;
end;

function TtsPropertyElement.GetPropertyValue(Component: TPersistent; FirstFromActualValueSet: Boolean): Variant;
var
    ComponentId: string;
    ActualValueElement: TtsActualValueElement;
    ParentValue: Variant;

begin
    if FirstFromActualValueSet and (ShowPropertyValue <> pvShowAlways) then
    begin
        ComponentEditor.DoGetComponentId(Component, ComponentId);
        ActualValueElement := ComponentEditor.ActualValueSet.GetItem([ComponentId, Name]);

        if (ActualValueElement <> nil) then
        begin
            result := ConvertDesignPropertystrValueToValue(ActualValueElement.FActualstrValue);
            exit;
        end;
    end;

    if PropInfo = nil then
    begin
        if Parent = nil then
            exit;

        if Parent.PropType = nil then
            exit;

        if Parent.PropType^.Kind = tkSet then
        begin
            ParentValue := Parent.GetPropertyValue(Component, True);
            if VarIsEmpty(ParentValue) then
                result := Unassigned
            else
                result := SetElementNumber in TIntegerSet(integer(ParentValue));
        end;
    end
    else
    begin
        if Parent <> nil then
        begin
            ParentValue := Parent.GetPropertyValue(Component, True);
            if VarIsEmpty(ParentValue) then
            begin
                result := Unassigned;
                exit;
            end;
            Component := Pointer(integer(ParentValue));
            if Component = nil then
            begin
                result := Unassigned;
                exit;
            end;
        end;

        if PropInfo.PropType = nil then
            exit;

        case PropType.Kind of
            tkChar, tkString, tkWChar, tkLString,
            {$IFDEF TSVER_V3} tkWString {$ELSE} tkLWString {$ENDIF}:
                result := GetStrProp(Component, PropInfo);
            tkFloat:
                result := GetFloatProp(Component, PropInfo);
            tkVariant:
                result := GetVariantProp(Component, PropInfo);
            else
                result := GetOrdProp(Component, PropInfo);
        end;
    end;
end;

{$IFDEF TSVER_V6}
procedure TtsPropertyElement.SetPropertyEditor(const Prop: IProperty);
{$ELSE}
procedure TtsPropertyElement.SetPropertyEditor(Prop: TPropertyEditor);
{$ENDIF}
var
    Element: TtsPropertyElement;

begin
    if SubProperties = nil then
    begin
        TPropertyEditor(Prop).Free;
        exit;
    end;

    Element := SubProperties.GetItem([Prop.GetName]);

    if Element = nil then
    begin
        Element := TtsPropertyElement.Create(Prop, ComponentEditor, Self);
        SubProperties.Add(Element);
    end
    else
    begin
        Element.FEditor.Free;
        Element.Editor := TPropertyEditor(Prop);
        Element.FEditorComponent := TPropertyEditor(Prop).GetComponent(0);
    end;
end;

function TtsPropertyElement.GetPropertyNil: tsPropertyNilType;
begin
    if FPropertyNil = pnUnKnown then
    begin
        FPropertyNil := pnFalse;
        if PropInfo <> nil then
        begin
            if PropType <> nil then
            begin
                if (PropInfo.PropType^.Kind = tkClass) then
                begin
                    if GetOrdProp(FEditor.GetComponent(0), PropInfo) = 0 then
                        FPropertyNil := pnTrue
                    else if (PropInfo.PropType^.Name = 'TFont') and not (FEditor.GetComponent(0) is TtsBaseGrid) then
                        FPropertyNil := pnAuto;
                end;
            end;
        end;
    end;

    result := FPropertyNil;
end;

function TtsPropertyElement.ConvertDesignPropertystrValueToValue(const strValue: string): Variant;
var
  IntValue: Longint;
begin
    case PropInfo.PropType^.Kind of
        tkChar, tkString, tkWChar, tkLString,
        {$IFDEF TSVER_V3} tkWString {$ELSE} tkLWString {$ENDIF}:
            result := strValue;
        tkFloat:
            result := StrToFloat(strValue);
        tkVariant:
            result := strValue;
        tkEnumeration:
        begin
            result := GetEnumValue(GetPropType, strValue);
            if result = -1 then
                raise EPropertyError.Create('Invalid property value')
        end
        else
        begin
            if PropInfo.PropType^.Name = 'TColor' then
            begin
                if IdentToColor(strValue, IntValue) then
                    result := IntValue
                else
                    result := StrToInt(strValue);
            end
            else
                result := StrToInt(strValue);
        end;
    end;
end;

function TtsPropertyElement.ConvertDesignPropertyValueTostrValue(const Value: Variant): string;
var
    IntValue: integer;
begin
    case PropInfo.PropType^.Kind of
        tkChar, tkString, tkWChar, tkLString,
        {$IFDEF TSVER_V3} tkWString {$ELSE} tkLWString {$ENDIF}:
            result := Value;
        tkFloat:
            result := FloatToStr(Value);
        tkVariant:
            result := Value;
        tkEnumeration:
            begin
                if PropInfo.PropType^.Name = 'Boolean' then
                begin
                    if Value = 0 then
                        result := 'False'
                    else
                        result := 'True';
                end
                else
                    result := GetEnumName(GetPropType, Value);
            end;
        else
        begin
            if PropInfo.PropType^.Name = 'TColor' then
            begin
                IntValue := Value;
                result := ColorToString(TColor(IntValue));
            end
            else
                result := IntToStr(Value);
        end;
    end;
end;

{$IFDEF TSVER_V6}
constructor TtsPropertyElement.Create(Prop: IProperty; CurComponentEditor: TtsComponentEditor; ParentProperty: TtsPropertyElement);
{$ELSE}
constructor TtsPropertyElement.Create(Prop: TPropertyEditor; CurComponentEditor: TtsComponentEditor; ParentProperty: TtsPropertyElement);
{$ENDIF}
var
    i: integer;

begin
    inherited Create;

    Name := Prop.GetName;
    FEditor := TPropertyEditor(Prop);
    FEditorComponent := TPropertyEditor(Prop).GetComponent(0);
    PropInfo := GetPropInfo(FEditor.GetComponent(0).ClassInfo, Name);
    Parent := ParentProperty;
    ComponentEditor := CurComponentEditor;
    SetElementNumber := 0;
    PropertyNil := pnUnknown;

    if Parent = nil then
        PropertyLevel := 0
    else
    begin
        PropertyLevel := Parent.PropertyLevel + 1;

        if Parent.PropType <> nil then
        begin
            if Parent.PropType^.Kind = tkSet then
            begin
                {$IFDEF TSVER_V3}
                with GetTypeData(GetTypeData(Parent.PropType)^.CompType^)^ do
                {$ELSE}
                with GetTypeData(GetTypeData(Parent.PropType)^.CompType)^ do
                {$ENDIF}
                begin
                    for i := MinValue to MaxValue do
                    begin
                        {$IFDEF TSVER_V3}
                        if Name = GetEnumName(GetTypeData(Parent.PropType)^.CompType^, i) then
                        {$ELSE}
                        if Name = GetEnumName(GetTypeData(Parent.PropType)^.CompType, i) then
                        {$ENDIF}
                        begin
                            SetElementNumber := i;
                            break;
                        end;
                    end;
                end;
            end;
        end;
    end;

    SubProperties := nil;

    SubPropertiesUpdated := True;
    Mark := False;
    MultiValue := False;

    ShowPropertyValue := pvShowAlways;
    DesignstrValue := '';
    Showmessage('TtsPropertyElement.Create End');
end;

destructor TtsPropertyElement.Destroy;
begin
    FSubProperties.Free;
    FSubProperties := nil;
    FEditor.Free;
    FEditor := nil;
    inherited Destroy;
end;

function TtsPropertyElement.Compare(NodeSet: TtsCustomSet; Value : TtsSetElement) : TtsSetOrder;
begin
    Result := CompareKey(NodeSet, [TtsPropertyElement(Value).Name]);
end;

function TtsPropertyElement.CompareKey(NodeSet: TtsCustomSet; const KeyValue : array of const) : TtsSetOrder;
var
    CompareValue: integer;

begin
    CompareValue := CompareText(String(KeyValue[0].VAnsiString), Name);
    if  CompareValue > 0 then
        Result := ordLarger
    else if CompareValue < 0 then
        Result := ordSmaller
    else
        Result := ordEqual;
end;

{End TtsPropertyElement}

{TtsPropertySet}

function TtsPropertySet.GetItem(KeyValue : array of const) : TtsPropertyElement;
begin
    result := TtsPropertyElement(Get(KeyValue));
end;

procedure TtsPropertySet.MarkAll(Node : TtsSetNode);
begin
    if Node <> nil then
    begin
        MarkAll(Node.Left);

        TtsPropertyElement(Node.Value).Mark := True;

        MarkAll(Node.Right);
    end;
end;

{End TtsPropertySet}

{TtsPropertyPointerElement}

function TtsPropertyPointerElement.Compare(NodeSet: TtsCustomSet; Value : TtsSetElement) : TtsSetOrder;
begin
    Result := FElement.Compare(NodeSet, TtsPropertyPointerElement(Value).FElement);
end;

function TtsPropertyPointerElement.CompareKey(NodeSet: TtsCustomSet; const KeyValue : array of const) : TtsSetOrder;
begin
    Result := FElement.CompareKey(NodeSet, KeyValue);
end;

{End TtsPropertyPointerElement}

{TtsPropertyPointerSet}

function TtsPropertyPointerSet.GetItem(KeyValue : array of const) : TtsPropertyPointerElement;
begin
    result := TtsPropertyPointerElement(Get(KeyValue));
end;

{End TtsPropertyPointerSet}

{TtsActualValueElement}

⌨️ 快捷键说明

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