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

📄 abtrend.pas

📁 著名的虚拟仪表控件,包含全部源码, 可以在,delphi2007 下安装运行
💻 PAS
📖 第 1 页 / 共 4 页
字号:
begin
  FChannel[4] := Value;
end;

function TAbTrend.GetChannel4: TChSettings;
begin
  result := FChannel[4];
end;


procedure TAbTrend.SetChannel5(Value: TChSettings);
begin
  FChannel[5] := Value;
end;

function TAbTrend.GetChannel5: TChSettings;
begin
  result := FChannel[5];
end;


procedure TAbTrend.SetChannel6(Value: TChSettings);
begin
  FChannel[6] := Value;
end;

function TAbTrend.GetChannel6: TChSettings;
begin
  result := FChannel[6];
end;


procedure TAbTrend.SetChannel7(Value: TChSettings);
begin
  FChannel[7] := Value;
end;

function TAbTrend.GetChannel7: TChSettings;
begin
  result := FChannel[7];
end;


procedure TAbTrend.SetChannel8(Value: TChSettings);
begin
  FChannel[8] := Value;
end;

function TAbTrend.GetChannel8: TChSettings;
begin
  result := FChannel[8];
end;

procedure TAbTrend.SetTimeFormat(Value : String);
begin
  if FTimeFormat <> Value then begin
    FTimeFormat := Value;
    Change;
  end;
end;

function TAbTrend.FindMinMax(FromRec, ToRec: Integer): Boolean;
var
  n, nn             : Integer;
  Min, Max          : array[1..8] of Smallint;
begin
  result := false;
  if (FromRec < 0) or (ToRec > RecordList.Count - 1) then Exit;

   {set minmax to first record}
  ARecord := RecordList.Items[FromRec];
  for nn := 1 to 8 do
  begin
    Min[nn] := ARecord^.Ch[nn];
    MinMax[nn].FMinDateTime := ARecord^.Time;
    Max[nn] := ARecord^.Ch[nn];
    MinMax[nn].FMaxDateTime := ARecord^.Time;
  end;

   {find minmax in digits}
  for n := FromRec + 1 to ToRec do
  begin
    ARecord := RecordList.Items[n];
    for nn := 1 to 8 do
    begin
      if ARecord^.Time <> sepTime then
      begin
            {check min}
        if Min[nn] > ARecord^.Ch[nn] then
        begin
          Min[nn] := ARecord^.Ch[nn];
          MinMax[nn].FMinDateTime := ARecord^.Time;
            {check max}
        end
        else
          if Max[nn] < ARecord^.Ch[nn] then
          begin
            Max[nn] := ARecord^.Ch[nn];
            MinMax[nn].FMaxDateTime := ARecord^.Time;
          end;
      end;                              { if ARecord^.Time <> sepTime }
    end;                                { for nn := 1 to 8 }
  end;                                  { for n := FromRec+1 to ToRec }

   { change digits to Value }
  for nn := 1 to 8 do
  begin
    MinMax[nn].FMin := DigitToValue(nn, Min[nn]);
    MinMax[nn].FMax := DigitToValue(nn, Max[nn]);
  end;
  result := true;
end;


function TAbTrend.DigitToValue(Ch: Integer; Digit: Smallint): Single;
begin
  if (Ch > 0) and (Ch <= 8) then
    result := FChannel[Ch].ValueFrom + ((Digit - FChannel[Ch].DigitalFrom) *
      FChannel[Ch].ValuePerDigit)
  else
    result := 0;
end;

function TAbTrend.ValueToDigit(Ch: Integer; Value: Single): Smallint;
begin
  if (Ch > 0) and (Ch <= 8) then
    result := Round(FChannel[Ch].DigitalFrom + ((Value - FChannel[Ch].ValueFrom)
      * FChannel[Ch].DigitPerValue))
  else
    result := 0;
end;

function TAbTrend.AddDigit(d1, d2, d3, d4, d5, d6, d7, d8: Smallint): Boolean;
begin
  result := false;
  if StartRecording then Exit;          {don't add when recording is running}
  New(ARecord);
  ARecord^.Time := Now;
  ARecord^.Ch[1] := ABS(FChannel[1].DigitalFrom) + d1;
  ARecord^.Ch[2] := ABS(FChannel[2].DigitalFrom) + d2;
  ARecord^.Ch[3] := ABS(FChannel[3].DigitalFrom) + d3;
  ARecord^.Ch[4] := ABS(FChannel[4].DigitalFrom) + d4;
  ARecord^.Ch[5] := ABS(FChannel[5].DigitalFrom) + d5;
  ARecord^.Ch[6] := ABS(FChannel[6].DigitalFrom) + d6;
  ARecord^.Ch[7] := ABS(FChannel[7].DigitalFrom) + d7;
  ARecord^.Ch[8] := ABS(FChannel[8].DigitalFrom) + d8;
  RecordList.Add(ARecord);
  result := true;
end;

function TAbTrend.AddValue(v1, v2, v3, v4, v5, v6, v7, v8: Single): Boolean;
begin
  result := false;
  if StartRecording then Exit;          {don't add when recording is running}
  New(ARecord);
  ARecord^.Time := Now;
  ARecord^.Ch[1] := ValueToDigit(1, ABS(FChannel[1].ValueFrom) + v1);
  ARecord^.Ch[2] := ValueToDigit(2, ABS(FChannel[2].ValueFrom) + v2);
  ARecord^.Ch[3] := ValueToDigit(3, ABS(FChannel[3].ValueFrom) + v3);
  ARecord^.Ch[4] := ValueToDigit(4, ABS(FChannel[4].ValueFrom) + v4);
  ARecord^.Ch[5] := ValueToDigit(5, ABS(FChannel[5].ValueFrom) + v5);
  ARecord^.Ch[6] := ValueToDigit(6, ABS(FChannel[6].ValueFrom) + v6);
  ARecord^.Ch[7] := ValueToDigit(7, ABS(FChannel[7].ValueFrom) + v7);
  ARecord^.Ch[8] := ValueToDigit(8, ABS(FChannel[8].ValueFrom) + v8);
  RecordList.Add(ARecord);
  result := true;
end;

procedure TAbTrend.PaintRecords(RecordFrom, RecordTo: Integer);
begin
  if not (Visible or (csDesigning in Componentstate)) then Exit;
  if RecordFrom < 0 then RecordFrom := 0;
  if RecordTo > RecordList.Count - 1 then RecordTo := RecordList.Count - 1;
  PointPos := 0;
  TrendOffset := RecordFrom;
  DrawGrid(rTrend, true);
  DrawCurves(RecordFrom, RecordTo);
  Canvas.Draw(rTrend.Left, rTrend.Top, BmpTrend);
end;

function TAbTrend.ReadRecTime(RecNo: Integer; var t: TDateTime): Boolean;
begin
  result := false;
  if (RecNo < 0) or (RecNo > RecordList.Count - 1) then Exit;
  ARecord := RecordList.Items[RecNo];
  t := ARecord^.Time;
  result := true;
end;

function TAbTrend.ReadDigit(RecNo: Integer; var t: TDateTime; var d1, d2, d3,
  d4, d5, d6, d7, d8: Smallint): Boolean;
begin
  result := false;
  if (RecNo < 0) or (RecNo > RecordList.Count - 1) then Exit;
  ARecord := RecordList.Items[RecNo];
  t := ARecord^.Time;
  d1 := ARecord^.Ch[1];
  d2 := ARecord^.Ch[2];
  d3 := ARecord^.Ch[3];
  d4 := ARecord^.Ch[4];
  d5 := ARecord^.Ch[5];
  d6 := ARecord^.Ch[6];
  d7 := ARecord^.Ch[7];
  d8 := ARecord^.Ch[8];
  result := true;
end;

function TAbTrend.ReadValue(RecNo: Integer; var t: TDateTime; var v1, v2, v3,
  v4, v5, v6, v7, v8: Single): Boolean;
begin
  result := false;
  if (RecNo < 0) or (RecNo > RecordList.Count - 1) then Exit;
  ARecord := RecordList.Items[RecNo];
  t := ARecord^.Time;
  v1 := DigitToValue(1, ARecord^.Ch[1]);
  v2 := DigitToValue(2, ARecord^.Ch[2]);
  v3 := DigitToValue(3, ARecord^.Ch[3]);
  v4 := DigitToValue(4, ARecord^.Ch[4]);
  v5 := DigitToValue(5, ARecord^.Ch[5]);
  v6 := DigitToValue(6, ARecord^.Ch[6]);
  v7 := DigitToValue(7, ARecord^.Ch[7]);
  v8 := DigitToValue(8, ARecord^.Ch[8]);
  result := true;
end;

procedure TAbTrend.RecordNoChanged;
begin
  if RecordList.Count - 1 > 0 then
  begin
    RecordInfo.FTotalRecords := RecordList.Count ;
    ARecord := RecordList.Items[0];
    RecordInfo.FFirstRecord := ARecord^.Time;
    ARecord := RecordList.Items[RecordList.Count - 1];
    RecordInfo.FLastRecord := ARecord^.Time;
  end
  else
  begin                                 {if emty...}
    RecordInfo.FTotalRecords := 0;
    RecordInfo.FFirstRecord := 0;
    RecordInfo.FLastRecord := 0;
  end;
  if Assigned(FOnRecNoChanged) then FOnRecNoChanged(self);
end;

procedure TAbTrend.ZoomYOut;
var
  dZoom             : Single;
begin
  dZoom := FZoomV;

  dZoom := dZoom + 0.1;

   {limits}
  if dZoom > 10 then
    dZoom := 10
  else
    if dZoom < 0.1 then dZoom := 0.1;

   {changed ?}
  if dZoom <> FZoomV then
  begin
    FZoomV := dZoom;
    Change;
  end;

end;

procedure TAbTrend.ZoomYIn;
var
  dZoom             : Single;
begin
  dZoom := FZoomV;

  dZoom := dZoom - 0.1;

   {limits}
  if dZoom > 10 then
    dZoom := 10
  else
    if dZoom < 0.1 then dZoom := 0.1;

   {changed ?}
  if dZoom <> FZoomV then
  begin
    FZoomV := dZoom;
    Change;
  end;
end;

procedure TAbTrend.ZoomY(Value: Single);
{ vertical zoom in/out,
  Value 1..10 = ZoomOut
  Value 0.1..1 = ZoomIn
  Value 1 = default
}
begin
  if (Value < 0.1) or (Value > 10) then Exit;
  FZoomV := Value;
  Change;
end;

procedure TAbTrend.CMTextChanged(var msg: TMessage);
begin
  Change;
end;

procedure TAbTrend.CMMouseLeave(var msg: TMessage);
begin
  //inTrend := false;
end;

procedure TAbTrend.SetMaxRecords(Value: Integer);
begin
  if (Value <> FMaxRecords) and (Value >= 100) then
    FMaxRecords := Value;
end;

procedure TAbTrend.SetFillChannelNo(Value: Integer);
begin
  if Value <> FFillChannelNo then
  begin
    if (Value >= 0) and (Value < 9) then
      FFillChannelNo := Value;
    Change;
  end;
end;

procedure TAbTrend.DeleteRecords(no: Integer);
{deletes no of records from begin of list}
var
  n                 : Integer;
begin
  if (no > RecordList.Count - 1) then Exit;

  for n := 0 to no - 1 do
  begin
    ARecord := RecordList.Items[n];
    RecordList.Items[n] := nil;
    Dispose(ARecord);
  end;
  RecordList.Pack;
  RecordNoChanged;
end;

procedure TAbTrend.ClearRecords;
var
  n                 : Integer;
  RecFlag           : Boolean;
begin
  RecFlag := FStartRecording;
  StartRecording := false;              {Stop recording}
  PointPos := 0;
  TrendOffset := 0;

  for n := 0 to (RecordList.Count - 1) do
  begin
    ARecord := RecordList.Items[n];
    RecordList.Items[n] := nil;
    if ARecord <> nil then Dispose(ARecord);
  end;
  RecordList.Pack;
  if not AbDestroy then PaintRecords(0,RecordList.Count-1);
  //if not AbDestroy then Paint;

  StartRecording := RecFlag;
  FRecordInfo.FFirstDisplayedRec := 0;
  FRecordInfo.FLastDisplayedRec := 0;

  RecordNoChanged;
end;

procedure TAbTrend.AddSeparator(Pos: Integer);
var
  n, nn             : Integer;
  Signal            : PSignRec;
begin
  if (Pos > RecordList.Count - 1) or not (opSeparator in FOptions) then Exit;

  Signal := RecordList.Items[Pos - 1];

  for nn := 1 to 5 do
  begin
    New(ARecord);
    ARecord^.Time := sepTime;
    for n := 1 to 8 do
      ARecord^.Ch[n] := Signal^.Ch[n];
    RecordList.Insert(Pos, ARecord);
  end;

end;

procedure TAbTrend.RunInterval2(NoOffRecords: Integer);

begin
  if not StartRecording then Exit;
  Int2Count := NoOffRecords;
  Int2Running := true;
  AddControl(self, FInterval2);
  AddSeparator(RecordList.Count - 1);
end;


function TAbTrend.LoadFromFile(FileName: string): Integer;
begin
  result := LoadFromFileEx(FileName, false);
end;

function TAbTrend.LoadFromFileEx(FileName: string; ClearList: Boolean): Integer;
var
  f                 : file of SignRec;
  n, Anzahl         : Integer;
begin
  StartRecording := false;              {Stop recording}

  if ClearList then begin
    PointPos := 0;
    TrendOffset := 0;

    for n := 0 to (RecordList.Count - 1) do
    begin
      ARecord := RecordList.Items[n];
      RecordList.Items[n] := nil;
      if ARecord <> nil then Dispose(ARecord);
    end;
    RecordList.Pack;

  end; // ClearList

   {add separator if recordlist is not emty}
  if RecordList.Count - 1 > 0 then AddSeparator(RecordList.Count - 1);

  AssignFile(f, FileName);
  {$I-}
    reset(f);
  {$I+}

  result := IOResult;                   {returns the error-code or 0 if ok}
  if result = 0 then
  begin
    Anzahl := FileSize(f);
    for n := 0 to Anzahl - 1 do
    begin
      New(ARecord);
      Read(f, ARecord^);
      RecordList.Add(ARecord);
    end;
    CloseFile(f);
  end;
  RecordNoChanged;
  if not (Visible or (csDesigning in Componentstate)) then Exit;
  //Paint;
  if (opShowLast in Options) then
    PaintRecords(RecordList.Count-1-MaxVisRecords,RecordList.Count-1)
  else
    PaintRecords(0,RecordList.Count-1);
end;

function TAbTrend.SavePartToFile(FileName: string; FromRecord, ToRecord:
  Integer): Integer;
var
  f                 : file of SignRec;
  n                 : Integer;
begin
   {check range before save}
  result := -1;
  if (FromRecord < 0) then FromRecord := 0;
  if (ToRecord > RecordList.Count - 1) then ToRecord := RecordList.Count - 1;
  if (ToRecord - FromRecord <= 0) then Exit;

  AssignFile(f, FileName);
{$I-}
  if FileExists(FileName) then begin
    reset(f);
    //Seek(f,Eof(f));
  end else
    rewrite(f);
{$I+}

  result := IOResult;                   {returns the error-code or 0 if ok}
  if result = 0 then
  begin
    Seek(f, FileSize(f));
    for n := FromRecord to ToRecord do
    begin
      ARecord := RecordList.Items[n];
      Write(f, ARecord^);
    end;
    CloseFile(f);
  end;

end;


function TAbTrend.SaveToFile(FileName: string): Integer;
var
  f                 : file of SignRec;
  n                 : Integer;
begin

  AssignFile(f, FileName);
{$I-}
  rewrite(f);
{$I+}

  result := IOResult;                   {returns the error-code or 0 if ok}
  if result = 0 then
  begin
    for n := 0 to RecordList.Count - 1 do
    begin
      ARecord := RecordList.Items[n];
      Write(f, ARecord^);
    end;
    CloseFile(f);
  end;

end;

procedure TAbTrend.MoveX(NoOffRecords: Integer);
begin
  if not (Visible or (csDesigning in Componentstate)) then Exit;
  Flow := false;
  TrendOffset := TrendOffset + NoOffRecords;
  if TrendOffset > RecordList.Count then
    TrendOffset := RecordList.Count - 1 - GridXPixel;
  if TrendOffset < 0 then TrendOffset := 0;

  DrawGrid(rTrend, true);
  DrawCurves(TrendOffset, RecordList.Count - 1);

⌨️ 快捷键说明

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