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

📄 ipositioncomponent.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 2 页
字号:
          InvalidateChange;
          DoPositionChange;
        end;
    end;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.SetPositionMax(const Value: Double);
begin
  if FPositionMax <> Value then
    begin
      SetPositionMinMax(FPositionMin, Value);
    end;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.SetPositionMin(const Value: Double);
begin
  if FPositionMin <> Value then
    begin
      SetPositionMinMax(Value, FPositionMax);
    end;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.DoLimitBounds;
begin
  if not Loading then
    begin
      if not MinMaxFixed then
        begin
          if CurrentMin < PositionMin then CurrentMin := PositionMin;
          if CurrentMax > PositionMax then CurrentMax := PositionMax;
        end;
    end;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.DoPointerBounds;
begin
  if not Loading then
    begin
      if Position < PositionMin then Position := PositionMin;
      if Position > PositionMax then Position := PositionMax;
    end;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.SetPositionMinMax(Min, Max: Double);
begin
  if (FPositionMin <> Min) or (FPositionMax <> Max) then
    begin
      FPositionMin := Min;
      FPositionMax := Max;
      DoLimitBounds;
      DoPointerBounds;
      BackGroundChange;
    end;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.ResetMinMax;
begin
  CurrentMax := Position;
  CurrentMin := Position;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.SetCurrentMin(const Value: Double);
var
  TempValue : Double;
begin
  TempValue := Value;
  if not Loading then
    begin
      if TempValue < FPositionMin then TempValue := FPositionMin;
      if TempValue > FPositionMax then TempValue := FPositionMax;
    end;

  if FCurrentMin <> TempValue then
    begin
      FCurrentMin := TempValue;
      if FShowMinPointer then InvalidateChange;
      DoCurrentMinChange;
      if not Loading then if FPosition < CurrentMin then DoPositionUnderMin;
    end;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.SetCurrentMax(const Value: Double);
var
  TempValue : Double;
begin
  TempValue := Value;
  if not Loading then
    begin
      if TempValue < FPositionMin then TempValue := FPositionMin;
      if TempValue > FPositionMax then TempValue := FPositionMax;
    end;
    
  if FCurrentMax <> TempValue then
    begin
      FCurrentMax := TempValue;
      if FShowMaxPointer then InvalidateChange;
      DoCurrentMaxChange;
      if not Loading then if FPosition > CurrentMax then DoPositionOverMax;
    end;
end;
//****************************************************************************************************************************************************
function TiPositionComponent.ValuePercent(Value : Double): Double;
begin
  if      Value       > FPositionMax then Result := 1
   else if Value       < FPositionMin then Result := 0
    else if FPositionMax = FPositionMin then Result := 0
     else                                     Result := (Value - FPositionMin)/(FPositionMax - FPositionMin);
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.DefineProperties(Filer: TFiler);
begin
  inherited DefineProperties(Filer);
  Filer.DefineProperty('PositionMax_2', ReadPositionMax2, WritePositionMax2, True);
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.ReadPositionMax2(Reader: TReader);
begin
  FPositionMax := Reader.ReadFloat;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.WritePositionMax2(Writer: TWriter);
begin
  Writer.WriteFloat(FPositionMax);
end;
//****************************************************************************************************************************************************
function TiPositionComponent.GetPositionPercent: Double;
begin
  Result := ValuePercent(FPosition);
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.SetPositionPercent(const Value: Double);
begin
  Position := Value*(FPositionMax- FPositionMin) + FPositionMin
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.DoCurrentMaxChange;                 begin if not Loading then if Assigned(FOnCurrentMaxChange)      then FOnCurrentMaxChange      (Self);      end;
procedure TiPositionComponent.DoCurrentMinChange;                 begin if not Loading then if Assigned(FOnCurrentMinChange)      then FOnCurrentMinChange      (Self);      end;
procedure TiPositionComponent.DoPositionOverMax;                  begin if not Loading then if Assigned(FOnPositionOverMax)       then FOnPositionOverMax       (Self);      end;
procedure TiPositionComponent.DoPositionUnderMin;                 begin if not Loading then if Assigned(FOnPositionUnderMin)      then FOnPositionUnderMin      (Self);      end;
procedure TiPositionComponent.DoPositionOverLimit (Index:Integer);begin if not Loading then if Assigned(FOnPositionOverLimit)     then FOnPositionOverLimit     (Self,Index);end;
procedure TiPositionComponent.DoPositionUnderLimit(Index:Integer);begin if not Loading then if Assigned(FOnPositionUnderLimit)    then FOnPositionUnderLimit    (Self,Index);end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.DoPositionChange;
begin
  if not Loading then
    begin
      if (not FUserGenerated) then                                         DoOPCPositionChangeFinished;
      if                              Assigned(OnChangeProtected)     then OnChangeProtected    (Self, 'Position');
      if                              Assigned(FOnPositionChange)     then FOnPositionChange    (Self);
      if (FUserGenerated)     then if Assigned(FOnPositionChangeUser) then FOnPositionChangeUser(Self);
    end;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.DoPositionChangeFinished;
begin
  if not Loading then
    begin
      if PositionedChanged then
        begin
          PositionedChanged := False;
          DoOPCPositionChangeFinished;
          if Assigned(FOnPositionChangeFinished)then FOnPositionChangeFinished(Self);
        end;
    end;
end;
//****************************************************************************************************************************************************
function TiPositionComponent.GetLimitUpperValue       (Index:Integer):Double; begin Result:=GetLimitObject(Index).UpperValue;       end;
function TiPositionComponent.GetLimitLowerValue       (Index:Integer):Double; begin Result:=GetLimitObject(Index).LowerValue;       end;
function TiPositionComponent.GetLimitUpperPointerColor(Index:Integer):TColor; begin Result:=GetLimitObject(Index).UpperPointerColor;end;
function TiPositionComponent.GetLimitLowerPointerColor(Index:Integer):TColor; begin Result:=GetLimitObject(Index).LowerPointerColor;end;
function TiPositionComponent.GetLimitPointerMargin    (Index:Integer):Integer;begin Result:=GetLimitObject(Index).PointerMargin;    end;
function TiPositionComponent.GetLimitPointerSize      (Index:Integer):Integer;begin Result:=GetLimitObject(Index).PointerSize;      end;
function TiPositionComponent.GetLimitShowUpperPointer (Index:Integer):Boolean;begin Result:=GetLimitObject(Index).ShowUpperPointer; end;
function TiPositionComponent.GetLimitShowLowerPointer (Index:Integer):Boolean;begin Result:=GetLimitObject(Index).ShowLowerPointer; end;
function TiPositionComponent.GetLimitDrawScaleSide    (Index:Integer):Boolean;begin Result:=GetLimitObject(Index).DrawScaleSide;    end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.SetLimitUpperValue       (Index:Integer;const Value:Double); begin GetLimitObject(Index).UpperValue       := Value;BackGroundChange;end;
procedure TiPositionComponent.SetLimitLowerValue       (Index:Integer;const Value:Double); begin GetLimitObject(Index).LowerValue       := Value;BackGroundChange;end;
procedure TiPositionComponent.SetLimitPointerMargin    (Index:Integer;const Value:Integer);begin GetLimitObject(Index).PointerMargin    := Value;BackGroundChange;end;
procedure TiPositionComponent.SetLimitPointerSize      (Index:Integer;const Value:Integer);begin GetLimitObject(Index).PointerSize      := Value;BackGroundChange;end;
procedure TiPositionComponent.SetLimitUpperPointerColor(Index:Integer;const Value:TColor); begin GetLimitObject(Index).UpperPointerColor:= Value;BackGroundChange;end;
procedure TiPositionComponent.SetLimitLowerPointerColor(Index:Integer;const Value:TColor); begin GetLimitObject(Index).LowerPointerColor:= Value;BackGroundChange;end;
procedure TiPositionComponent.SetLimitShowUpperPointer (Index:Integer;const Value:Boolean);begin GetLimitObject(Index).ShowUpperPointer := Value;BackGroundChange;end;
procedure TiPositionComponent.SetLimitShowLowerPointer (Index:Integer;const Value:Boolean);begin GetLimitObject(Index).ShowLowerPointer := Value;BackGroundChange;end;
procedure TiPositionComponent.SetLimitDrawScaleSide    (Index:Integer;const Value:Boolean);begin GetLimitObject(Index).DrawScaleSide    := Value;BackGroundChange;end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.AddLimit(PointerSize, PointerMargin : Integer; DrawScaleSide : Boolean; UpperValue, LowerValue : Double; UpperPointerColor, LowerPointerColor : TColor);
var
  iLimitObject : TiLimitObject;
begin
  iLimitObject := TiLimitObject.Create;

  iLimitObject.UpperValue        := UpperValue;
  iLimitObject.LowerValue        := LowerValue;
  iLimitObject.ShowUpperPointer  := True;
  iLimitObject.ShowLowerPointer  := True;
  iLimitObject.UpperPointerColor := UpperPointerColor;
  iLimitObject.LowerPointerColor := LowerPointerColor;
  iLimitObject.PointerSize       := PointerSize;
  iLimitObject.PointerMargin     := PointerMargin;
  iLimitObject.DrawScaleSide     := DrawScaleSide;

  FLimitList.AddObject('', iLimitObject);
  BackGroundChange;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.RemoveLimit(Index: Integer);
begin
  GetLimitObject(Index).Free;
  FLimitList.Delete(Index);
  BackGroundChange;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.RemoveAllLimits;
begin
  while LimitCount > 0 do
    RemoveLimit(0);
end;
//****************************************************************************************************************************************************
function TiPositionComponent.GetLimitCount: Integer;
begin
  Result := FLimitList.Count
end;
//****************************************************************************************************************************************************
function TiPositionComponent.GetLimitObject(Index: Integer): TiLimitObject;
begin
  if (Index < 0) or (Index >(LimitCount -1)) then raise Exception.Create('Limit Index out of bounds');
  Result := FLimitList.Objects[Index] as TiLimitObject;
end;
//****************************************************************************************************************************************************
function TiPositionComponent.GetPosition: Double;
begin
  Result := FPosition;
end;
//****************************************************************************************************************************************************
procedure TiPositionComponent.DoOPCPositionChangeFinished;
begin

end;
//****************************************************************************************************************************************************
end.


⌨️ 快捷键说明

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