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

📄 iopcmanagercomponenteditor.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
字号:
{*******************************************************}
{                                                       }
{       TiOPCManagerComponentEditor                     }
{                                                       }
{       Copyright (c) 1997,2003 Iocomp Software         }
{                                                       }
{*******************************************************}
{$I iInclude.inc}

{$ifdef iVCL}unit  iOPCManagerComponentEditor;{$endif}
{$ifdef iCLX}unit QiOPCManagerComponentEditor;{$endif}

interface

uses
  {$I iIncludeUsesForms.inc}

  {$IFDEF iVCL} iComponentEditorForm,  iTypes,  iOPCManager,  iOPCDLLLoader,  iOPCComputerSelector,  iOPCServerSelector,{$ENDIF}
  {$IFDEF iCLX}QiComponentEditorForm, QiTypes, QiOPCManager, QiOPCDLLLoader, QiOPCComputerSelector, QiOPCServerSelector,{$ENDIF}

  {$IFDEF iVCL}  StdCtrls,  ExtCtrls,  Controls,  ComCtrls, Classes,  iComponentEditorButtonPanel,  iEditorBasicComponents,  iAboutPanel,  iComponent,  iVCLComponent,  iCustomComponent,  iCheckBox;{$ENDIF}
  {$IFDEF iCLX} QStdCtrls, QExtCtrls, QControls, QComCtrls, Classes, QiComponentEditorButtonPanel, QiEditorBasicComponents, QiAboutPanel, QiComponent, QiCLXComponent, QiCustomComponent, QiCheckBox;{$ENDIF}

type
  TiOPCManagerComponentEditorForm = class(TiComponentEditorForm)
    PageControl: TiComponentEditorPageControl;
    GeneralTabSheet: TTabSheet;
    AboutTabSheet: TTabSheet;
    iComponentEditorButtonPanel1: TiComponentEditorButtonPanel;
    iAboutPanel1: TiAboutPanel;
    Label1: TLabel;
    Label9: TLabel;
    ItemListBox: TiComponentEditorListBox;
    iGroupItemAddButton: TButton;
    GroupRemoveButton: TButton;
    ItemPropertiesGroupBox: TGroupBox;
    Label3: TLabel;
    Label2: TLabel;
    GroupNameEdit: TiComponentEditorEdit;
    GroupUpdateRateEdit: TiComponentEditorEdit;
    Label145: TLabel;
    Label146: TLabel;
    GroupComputerNameEdit: TiComponentEditorEdit;
    GroupOPCServerNameEdit: TiComponentEditorEdit;
    GroupOPCComputerNameEditButton: TiComponentEditorButton;
    GroupOPCServerNameEditButton: TiComponentEditorButton;
    procedure iComponentEditorFormDestroy(Sender: TObject);
    procedure iGroupItemAddButtonClick(Sender: TObject);
    procedure GroupRemoveButtonClick(Sender: TObject);
    procedure ItemListBoxClick(Sender: TObject);
    procedure ItemChange(Sender: TObject);
    procedure ItemListBoxGetData(const Index: Integer; var DrawColorBox: Boolean; var AColor: TColor; var AText: String);
    procedure ItemListBoxItemMove(Sender: TObject);
    procedure iComponentEditorFormCreate(Sender: TObject);
    procedure GroupOPCComputerNameEditButtonClick(Sender: TObject);
    procedure GroupOPCServerNameEditButtonClick(Sender: TObject);
  private
    FSessionHandle : Integer;
    FLastIndex     : Integer;

    procedure UpdateItemEdit;
    procedure ClearList;
  protected
    procedure CreateThemeInstance;                               override;
    procedure CopyPropertiesToForm     (Component: TWinControl); override;
    procedure CopyPropertiesToComponent(Component: TWinControl); override;
  end;

var
  iOPCManagerComponentEditorForm: TiOPCManagerComponentEditorForm;

implementation

{$R *.dfm}
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.iComponentEditorFormCreate(Sender: TObject);
begin
  FSessionHandle := OPCDLLEditorSessionStart;
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.iComponentEditorFormDestroy(Sender: TObject);
begin
  OPCDLLEditorSessionStop(FSessionHandle);
  ClearList;
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.CreateThemeInstance;
begin

end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.ClearList;
begin
  while ItemListBox.Items.Count > 0 do
    begin
      ItemListBox.Items.Objects[0].Free;
      ItemListBox.Items.Delete(0);
    end;
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.iGroupItemAddButtonClick(Sender: TObject);
var
  iOPCGroupStream : TiOPCGroupStream;
begin
  iOPCGroupStream            := TiOPCGroupStream.Create;
  iOPCGroupStream.Name       := 'Untitled';
  iOPCGroupStream.UpdateRate := 500;
  ItemListBox.ItemIndex      := ItemListBox.Items.AddObject(iOPCGroupStream.Name, iOPCGroupStream);

  UpdateItemEdit;

  Modified := True;
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.GroupRemoveButtonClick(Sender: TObject);
var
  LastIndex : Integer;
begin
  LastIndex := ItemListBox.ItemIndex;
  ItemListBox.Items.Objects[ItemListBox.ItemIndex].Free;
  ItemListBox.Items.Delete(ItemListBox.ItemIndex);
  if ItemListBox.Items.Count <> 0 then
    begin
      if LastIndex > (ItemListBox.Items.Count - 1) then ItemListBox.ItemIndex := LastIndex - 1
        else ItemListBox.ItemIndex := LastIndex;
    end;

  UpdateItemEdit;
  Modified := True;
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.ItemListBoxClick(Sender: TObject);
begin
  UpdateItemEdit;
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.ItemListBoxGetData(const Index: Integer; var DrawColorBox: Boolean; var AColor: TColor; var AText: String);
begin
  AText := (ItemListBox.Items.Objects[Index] as TiOPCGroupStream).Name;
  DrawColorBox := False;
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.ItemListBoxItemMove(Sender: TObject);
begin
  Modified := True;
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.UpdateItemEdit;
var
  iOPCGroupStream : TiOPCGroupStream;
begin
  if ItemListBox.ItemIndex = - 1 then DisableAllEditControlsStartingWith('Group')
    else
      begin
        EnableAllEditControlsStartingWith('Group');

        iOPCGroupStream := ItemListBox.Items.Objects[ItemListBox.ItemIndex] as TiOPCGroupStream;

        GroupNameEdit.AsString          := iOPCGroupStream.Name;
        GroupComputerNameEdit.AsString  := iOPCGroupStream.ComputerName;
        GroupOPCServerNameEdit.AsString := iOPCGroupStream.OPCServerName;
        GroupUpdateRateEdit.AsInteger   := iOPCGroupStream.UpdateRate;
      end
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.ItemChange(Sender: TObject);
var
  iOPCGroupStream : TiOPCGroupStream;
begin
  if ItemListBox.ItemIndex = -1 then Exit;

  iOPCGroupStream := ItemListBox.Items.Objects[ItemListBox.ItemIndex] as TiOPCGroupStream;

  iOPCGroupStream.Name          := GroupNameEdit.AsString;
  iOPCGroupStream.ComputerName  := GroupComputerNameEdit.AsString;
  iOPCGroupStream.OPCServerName := GroupOPCServerNameEdit.AsString;
  iOPCGroupStream.UpdateRate    := GroupUpdateRateEdit.AsInteger;

  UpdateItemEdit;
  ItemListBox.Invalidate;
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.GroupOPCComputerNameEditButtonClick(Sender: TObject);
begin
  Screen.Cursor := crHourGlass;
  try
    iOPCComputerSelectorForm := TiOPCComputerSelectorForm.Create(Application);
    try
      iOPCComputerSelectorForm.SessionHandle := FSessionHandle;
      iOPCComputerSelectorForm.Setup;
      iOPCComputerSelectorForm.ComputerName := GroupComputerNameEdit.AsString;
      if iOPCComputerSelectorForm.ShowModal = mrOK then
        begin
          GroupComputerNameEdit.SetStringWithEvent(iOPCComputerSelectorForm.ComputerName);
        end;
    finally
      iOPCComputerSelectorForm.Free;
    end;
  finally
    Screen.Cursor := crDefault;
  end;
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.GroupOPCServerNameEditButtonClick(Sender: TObject);
begin
  Screen.Cursor := crHourGlass;
  try
  iOPCServerSelectorForm := TiOPCServerSelectorForm.Create(Application);
    try
      iOPCServerSelectorForm.SessionHandle := FSessionHandle;
      iOPCServerSelectorForm.Setup(GroupComputerNameEdit.AsString);
      iOPCServerSelectorForm.ServerName := GroupOPCServerNameEdit.AsString;
      if iOPCServerSelectorForm.ShowModal = mrOK then
        begin
          GroupOPCServerNameEdit.SetStringWithEvent(iOPCServerSelectorForm.ServerName);
        end;
    finally
      iOPCServerSelectorForm.Free;
    end;
  finally
    Screen.Cursor := crDefault;
  end;
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.CopyPropertiesToForm(Component: TWinControl);
var
  x               : Integer;
  iOPCManager     : TiOPCManager;
  iOPCGroupStream : TiOPCGroupStream;
begin
  iOPCManager := Component as TiOPCManager;

  ClearList;

  for x := 0 to iOPCManager.GroupCount-1 do
    begin
      iOPCGroupStream               := TiOPCGroupStream.Create;
      iOPCGroupStream.Name          := iOPCManager.Group[x].Name;
      iOPCGroupStream.ComputerName  := iOPCManager.Group[x].ComputerName;
      iOPCGroupStream.OPCServerName := iOPCManager.Group[x].OPCServerName;
      iOPCGroupStream.UpdateRate    := iOPCManager.Group[x].UpdateRate;

      ItemListBox.Items.AddObject('', iOPCGroupStream)
    end;

  if ItemListBox.Items.Count > FLastIndex then ItemListBox.ItemIndex := FLastIndex;
  UpdateItemEdit;
end;
//****************************************************************************************************************************************************
procedure TiOPCManagerComponentEditorForm.CopyPropertiesToComponent(Component: TWinControl);
var
  x           : Integer;
  iOPCManager : TiOPCManager;
begin
  iOPCManager := Component as TiOPCManager;

  iOPCManager.GroupClear;

  for x := 0 to ItemListBox.Items.Count-1 do
    begin
      iOPCManager.GroupAdd((ItemListBox.Items.Objects[x] as TiOPCGroupStream).Name,
                           (ItemListBox.Items.Objects[x] as TiOPCGroupStream).ComputerName,
                           (ItemListBox.Items.Objects[x] as TiOPCGroupStream).OPCServerName,
                           (ItemListBox.Items.Objects[x] as TiOPCGroupStream).UpdateRate);
    end;
  FLastIndex := ItemListBox.ItemIndex;
end;
//****************************************************************************************************************************************************
end.

⌨️ 快捷键说明

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