📄 iopcbrowserpanel.pas
字号:
{*******************************************************}
{ }
{ TiOPCBrowserPanel Component }
{ }
{ Copyright (c) 1997,2003 Iocomp Software }
{ }
{*******************************************************}
{$I iInclude.inc}
{$ifdef iVCL}unit iOPCBrowserPanel;{$endif}
{$ifdef iCLX}unit QiOPCBrowserPanel;{$endif}
interface
uses
{$I iIncludeUses.inc}
{$IFDEF iVCL} ShellAPI, ShlObj, Registry, {$ENDIF}
{$IFDEF iVCL} iTypes, iGPFunctions, iEditorBasicComponents, iOPCDLLLoader, iOPCItem;{$ENDIF}
{$IFDEF iCLX}QiTypes, QiGPFunctions, QiEditorBasicComponents, QiOPCDLLLoader, QiOPCItem;{$ENDIF}
type
TiOPCBrowserPanel = class(TCustomControl)
private
FOPCItemList : TiComponentEditorListBox;
FAddItemButton : TiComponentEditorButton;
FRemoveItemButton : TiComponentEditorButton;
FPropertyNameEdit : TiComponentEditorEdit;
FGroupNameEdit : TiComponentEditorEdit;
FComputerNameEdit : TiComponentEditorEdit;
FOPCServerNameEdit : TiComponentEditorEdit;
FItemNameEdit : TiComponentEditorEdit;
FAutoConnectCheckBox : TiComponentEditorCheckBox;
FAutoErrorCheckBox : TiComponentEditorCheckBox;
FPropertyNameEditButton : TiComponentEditorButton;
FGroupNameEditButton : TiComponentEditorButton;
FComputerNameEditButton : TiComponentEditorButton;
FOPCServerNameEditButton : TiComponentEditorButton;
FItemNameEditButton : TiComponentEditorButton;
FUpdateRateEdit : TiComponentEditorEdit;
FPropertyLabel : TLabel;
FGroupLabel : TLabel;
FComputerLabel : TLabel;
FOPCServerLabel : TLabel;
FItemLabel : TLabel;
FUpdateRateLabel : TLabel;
FErrorLabel : TLabel;
FEvaluationLabel : TLabel;
FOnChange : TNotifyEvent;
FPersistent : TPersistent;
FSessionHandle : Integer;
FShowProperty : Boolean;
FShowAutoError: Boolean;
procedure SetShowAutoError(const Value: Boolean);
protected
procedure SetShowProperty(const Value: Boolean);
procedure AddButtonClick (Sender: TObject);
procedure RemoveButtonClick (Sender: TObject);
procedure PropertyNameChange(Sender: TObject);
procedure GroupNameChange (Sender: TObject);
procedure ComputerNameChange(Sender: TObject);
procedure OPCSeverNameChange(Sender: TObject);
procedure ItemNameChange (Sender: TObject);
procedure UpdateRateChange (Sender: TObject);
procedure AutoConnectChange (Sender: TObject);
procedure AutoErrorChange (Sender: TObject);
procedure ItemMoveEvent (Sender: TObject);
procedure OPCItemListClick (Sender: TObject);
procedure PropertyNameEditButtonClick(Sender: TObject);
procedure GroupNameEditButtonClick (Sender: TObject);
procedure ComputerNameEditButtonClick(Sender: TObject);
procedure OPCSeverNameEditButtonClick(Sender: TObject);
procedure ItemNameEditButtonClick (Sender: TObject);
procedure GetDefaults(OPCItem: TiOPCItem);
procedure SetDefaults(PropertyName, PropertyData: String);
procedure Resize; override;
procedure DoEnter; override;
procedure AdjustLayout;
procedure Loaded; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure UpdateItemEdit;
procedure ItemChange;
function AddItem : Integer;
function ItemCount : Integer;
procedure RemoveAllItems;
function GetPropertyName(Index: Integer):String;
function GetGroupName (Index: Integer):String;
function GetComputerName(Index: Integer):String;
function GetServerName (Index: Integer):String;
function GetItemName (Index: Integer):String;
function GetUpdateRate (Index: Integer):Integer;
function GetAutoConnect (Index: Integer):Boolean;
function GetAutoError (Index: Integer):Boolean;
procedure SetPropertyName(Index: Integer; Value: String);
procedure SetGroupName (Index: Integer; Value: String);
procedure SetComputerName(Index: Integer; Value: String);
procedure SetServerName (Index: Integer; Value: String);
procedure SetItemName (Index: Integer; Value: String);
procedure SetUpdateRate (Index: Integer; Value: Integer);
procedure SetAutoConnect (Index: Integer; Value: Boolean);
procedure SetAutoError (Index: Integer; Value: Boolean);
property APersistent : TPersistent read FPersistent write FPersistent;
published
property OnChange : TNotifyEvent read FOnChange write FOnChange;
property ShowProperty : Boolean read FShowProperty write SetShowProperty default True;
property ShowAutoError : Boolean read FShowAutoError write SetShowAutoError default True;
property Align;
end;
implementation
{$IFDEF iVCL} uses iOPCPropertySelector, iOPCComputerSelector, iOPCServerSelector, iOPCItemSelector, iOPCGroupSelector;{$ENDIF}
{$IFDEF iCLX} uses QiOPCPropertySelector, QiOPCComputerSelector, QiOPCServerSelector, QiOPCItemSelector, QiOPCGroupSelector;{$ENDIF}
//****************************************************************************************************************************************************
constructor TiOPCBrowserPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FShowProperty := True;
FShowAutoError := True;
{$IFDEF iCLX}
HandleNeeded;
{$ENDIF};
ControlStyle := [csCaptureMouse, csClickEvents, csDoubleClicks, csReplicatable, csOpaque];
Width := 280;
Height := 165;
FOPCItemList := TiComponentEditorListBox.Create(Self);
with FOPCItemList do
begin
Parent := Self;
Style := lbStandard;
DragMode := dmAutomatic;
OnClick := OPCItemListClick;
OnItemMove := ItemMoveEvent;
end;
FAddItemButton :=TiComponentEditorButton.Create(Self);with FAddItemButton do begin Parent:=Self;Caption:='Add'; OnClick:=AddButtonClick; end;
FRemoveItemButton:=TiComponentEditorButton.Create(Self);with FRemoveItemButton do begin Parent:=Self;Caption:='Remove';OnClick:=RemoveButtonClick;end;
FPropertyNameEdit :=TiComponentEditorEdit.Create(Self);with FPropertyNameEdit do begin Parent:=Self;OnUpdate:=PropertyNameChange;end;
FGroupNameEdit :=TiComponentEditorEdit.Create(Self);with FGroupNameEdit do begin Parent:=Self;OnUpdate:=GroupNameChange; end;
FComputerNameEdit :=TiComponentEditorEdit.Create(Self);with FComputerNameEdit do begin Parent:=Self;OnUpdate:=ComputerNameChange;end;
FOPCServerNameEdit:=TiComponentEditorEdit.Create(Self);with FOPCServerNameEdit do begin Parent:=Self;OnUpdate:=OPCSeverNameChange;end;
FItemNameEdit :=TiComponentEditorEdit.Create(Self);with FItemNameEdit do begin Parent:=Self;OnUpdate:=ItemNameChange; end;
FUpdateRateEdit :=TiComponentEditorEdit.Create(Self);with FUpdateRateEdit do begin Parent:=Self;OnUpdate:=UpdateRateChange; end;
FAutoConnectCheckBox := TiComponentEditorCheckBox.Create(Self);
with FAutoConnectCheckBox do
begin
Caption := 'Auto Connect';
Parent := Self;
OnClick := AutoConnectChange;
end;
FAutoErrorCheckBox := TiComponentEditorCheckBox.Create(Self);
with FAutoErrorCheckBox do
begin
Caption := 'Auto Error';
Parent := Self;
OnClick := AutoErrorChange;
end;
FPropertyNameEditButton :=TiComponentEditorButton.Create(Self);with FPropertyNameEditButton do begin Parent:=Self;Caption:='...';OnClick:=PropertyNameEditButtonClick;end;
FGroupNameEditButton :=TiComponentEditorButton.Create(Self);with FGroupNameEditButton do begin Parent:=Self;Caption:='...';OnClick:=GroupNameEditButtonClick;end;
FComputerNameEditButton :=TiComponentEditorButton.Create(Self);with FComputerNameEditButton do begin Parent:=Self;Caption:='...';OnClick:=ComputerNameEditButtonClick;end;
FOPCServerNameEditButton:=TiComponentEditorButton.Create(Self);with FOPCServerNameEditButton do begin Parent:=Self;Caption:='...';OnClick:=OPCSeverNameEditButtonClick;end;
FItemNameEditButton :=TiComponentEditorButton.Create(Self);with FItemNameEditButton do begin Parent:=Self;Caption:='...';OnClick:=ItemNameEditButtonClick; end;
FPropertyLabel :=TLabel.Create(Self);with FPropertyLabel do begin Parent:=Self;Caption:='Property'; AutoSize:=False;Alignment:=taRightJustify;end;
FGroupLabel :=TLabel.Create(Self);with FGroupLabel do begin Parent:=Self;Caption:='Group'; AutoSize:=False;Alignment:=taRightJustify;end;
FComputerLabel :=TLabel.Create(Self);with FComputerLabel do begin Parent:=Self;Caption:='Computer'; AutoSize:=False;Alignment:=taRightJustify;end;
FOPCServerLabel :=TLabel.Create(Self);with FOPCServerLabel do begin Parent:=Self;Caption:='OPC Server'; AutoSize:=False;Alignment:=taRightJustify;end;
FItemLabel :=TLabel.Create(Self);with FItemLabel do begin Parent:=Self;Caption:='Item'; AutoSize:=False;Alignment:=taRightJustify;end;
FUpdateRateLabel:=TLabel.Create(Self);with FUpdateRateLabel do begin Parent:=Self;Caption:='Update Rate';AutoSize:=False;Alignment:=taRightJustify;end;
FErrorLabel :=TLabel.Create(Self);with FErrorLabel do begin Parent:=Self;Caption:=''; AutoSize:=False;Alignment:=taCenter; Font.Color:=clRed; Font.Style:= [fsbold];end;
FEvaluationLabel:=TLabel.Create(Self);with FEvaluationLabel do begin Parent:=Self;Caption:=''; AutoSize:=False;Alignment:=taCenter; Font.Color:=clBlue;Font.Style:= [fsbold];end;
FSessionHandle := OPCDLLEditorSessionStart;
end;
//****************************************************************************************************************************************************
destructor TiOPCBrowserPanel.Destroy;
begin
OPCDLLEditorSessionStop(FSessionHandle);
inherited;
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.Loaded;
begin
inherited;
AdjustLayout;
UpdateItemEdit;
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.AdjustLayout;
var
LabelMaxWidth : Integer;
LabelLeftRef : Integer;
EditLeftRef : Integer;
EditWidth : Integer;
begin
FOPCItemList.Top := 8;
FOPCItemList.Left := 8;
FOPCItemList.Height := Height - 8 - FAddItemButton.Height - 10;
FAddItemButton.Left := FOPCItemList.Left;
FRemoveItemButton.Left := FOPCItemList.Left + FOPCItemList.Width - FRemoveItemButton.Width;
FAddItemButton.Top := FOPCItemList.Top + FOPCItemList.Height + 5;
FRemoveItemButton.Top := FAddItemButton.Top;
if FShowProperty then
begin
FOPCItemList.Width := Width div 3;
FAddItemButton.Width := (FOPCItemList.Width div 11)*5;
FRemoveItemButton.Width := FAddItemButton.Width;
FPropertyNameEdit.Width := FGroupNameEdit.Height;
end
else
begin
FOPCItemList.Width := 0;
FAddItemButton.Width := 0;
FRemoveItemButton.Width := 0;
FPropertyNameEdit.Width := 0;
FPropertyLabel.Width := 0;
FPropertyNameEditButton.Width := 0;
end;
LabelMaxWidth := 0;
if Canvas.TextWidth(FPropertyLabel.Caption ) > LabelMaxWidth then LabelMaxWidth := Canvas.TextWidth(FPropertyLabel.Caption);
if Canvas.TextWidth(FGroupLabel.Caption ) > LabelMaxWidth then LabelMaxWidth := Canvas.TextWidth(FGroupLabel.Caption);
if Canvas.TextWidth(FComputerLabel.Caption ) > LabelMaxWidth then LabelMaxWidth := Canvas.TextWidth(FComputerLabel.Caption);
if Canvas.TextWidth(FOPCServerLabel.Caption ) > LabelMaxWidth then LabelMaxWidth := Canvas.TextWidth(FOPCServerLabel.Caption);
if Canvas.TextWidth(FItemLabel.Caption ) > LabelMaxWidth then LabelMaxWidth := Canvas.TextWidth(FItemLabel.Caption);
if Canvas.TextWidth(FUpdateRateLabel.Caption) > LabelMaxWidth then LabelMaxWidth := Canvas.TextWidth(FUpdateRateLabel.Caption);
LabelLeftRef := FOPCItemList.Left + FOPCItemList.Width + 10;
FPropertyLabel.Left := LabelLeftRef;
FGroupLabel.Left := LabelLeftRef;
FComputerLabel.Left := LabelLeftRef;
FOPCServerLabel.Left := LabelLeftRef;
FItemLabel.Left := LabelLeftRef;
FUpdateRateLabel.Left := LabelLeftRef;
if FShowProperty then FPropertyLabel.Width := LabelMaxWidth;
FGroupLabel.Width := LabelMaxWidth;
FComputerLabel.Width := LabelMaxWidth;
FOPCServerLabel.Width := LabelMaxWidth;
FItemLabel.Width := LabelMaxWidth;
FUpdateRateLabel.Width := LabelMaxWidth;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -