📄 iopcbrowserpanel.pas
字号:
finally
Screen.Cursor := crDefault;
end;
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.UpdateItemEdit;
var
iOPCItem : TiOPCItem;
GroupHandle : Integer;
begin
FErrorLabel.Caption := '';
FEvaluationLabel.Caption := '';
if OPCDLLNotLoaded then FErrorLabel.Caption := 'Iocomp OPC DLL Missing'
else if OPCDLLIsEvaluation then FEvaluationLabel.Caption := 'Iocomp OPC Evaluation';
if FOPCItemList.ItemIndex = - 1 then
begin
FOPCItemList.Enabled := False;
FRemoveItemButton.Enabled := False;
FPropertyNameEdit.Disable;
FGroupNameEdit.Disable;
FComputerNameEdit.Disable;
FOPCServerNameEdit.Disable;
FItemNameEdit.Disable;
FAutoConnectCheckBox.Disable;
FAutoErrorCheckBox.Disable;
FUpdateRateEdit.Disable;
FPropertyNameEditButton.Enabled := False;
FComputerNameEditButton.Enabled := False;
FOPCServerNameEditButton.Enabled := False;
FItemNameEditButton.Enabled := False;
FGroupNameEditButton.Enabled := False;
end
else
begin
FOPCItemList.Enabled := True;
FRemoveItemButton.Enabled := True;
FPropertyNameEdit.Disable;
FGroupNameEdit.Disable;
FComputerNameEdit.Enable;
FOPCServerNameEdit.Enable;
FItemNameEdit.Enable;
FAutoConnectCheckBox.Enable;
FAutoErrorCheckBox.Enable;
FUpdateRateEdit.Enable;
FPropertyNameEditButton.Enabled := True;
FComputerNameEditButton.Enabled := True;
FOPCServerNameEditButton.Enabled := True;
FItemNameEditButton.Enabled := True;
FGroupNameEditButton.Enabled := True;
iOPCItem := FOPCItemList.Items.Objects[FOPCItemList.ItemIndex] as TiOPCItem;
FPropertyNameEdit.AsString := iOPCItem.PropertyName;
FGroupNameEdit.AsString := iOPCItem.GroupName;
FComputerNameEdit.AsString := iOPCItem.ComputerName;
FOPCServerNameEdit.AsString := iOPCItem.ServerName;
FItemNameEdit.AsString := iOPCItem.ItemName;
FUpdateRateEdit.AsInteger := iOPCItem.UpdateRate;
FAutoConnectCheckBox.AsBoolean := iOPCItem.AutoConnect;
FAutoErrorCheckBox.AsBoolean := iOPCItem.AutoError;
if Trim(FGroupNameEdit.AsString) = '' then
begin
FComputerNameEdit.Enable; FComputerNameEditButton.Enabled := True;
FOPCServerNameEdit.Enable; FOPCServerNameEditButton.Enabled := True;
FUpdateRateEdit.Enabled;
FGroupNameEdit.DisableNoClear;
end
else
begin
FComputerNameEdit.Disable; FComputerNameEditButton.Enabled := False;
FOPCServerNameEdit.Disable; FOPCServerNameEditButton.Enabled := False;
FUpdateRateEdit.Disable;
FGroupNameEdit.DisableNoClear;
if not OPCDLLNotLoaded then
begin
GroupHandle := OPCDLLGroupGetHandleByName(PChar(FGroupNameEdit.AsString));
if GroupHandle <> 0 then
begin
FErrorLabel.Caption := '';
FComputerNameEdit.AsString := OPCDLLGroupGetComputerName(GroupHandle);
FOPCServerNameEdit.AsString := OPCDLLGroupGetOPCServerName(GroupHandle);
FUpdateRateEdit.AsInteger := OPCDLLGroupGetUpdateRate(GroupHandle);
end
else FErrorLabel.Caption := 'Group Not Found';
end;
end;
if FOPCServerNameEdit.AsString = '' then
begin
FItemNameEdit.DisableNoClear;
FItemNameEditButton.Enabled := False;
end;
end;
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.ItemChange;
var
iOPCItem : TiOPCItem;
begin
if FOPCItemList.ItemIndex <> -1 then
begin
iOPCItem := FOPCItemList.Items.Objects[FOPCItemList.ItemIndex] as TiOPCItem;
iOPCItem.PropertyName := FPropertyNameEdit.AsString;
iOPCItem.GroupName := FGroupNameEdit.AsString;
iOPCItem.ComputerName := FComputerNameEdit.AsString;
iOPCItem.ServerName := FOPCServerNameEdit.AsString;
iOPCItem.ItemName := FItemNameEdit.AsString;
iOPCItem.UpdateRate := FUpdateRateEdit.AsInteger;
iOPCItem.AutoConnect := FAutoConnectCheckBox.AsBoolean;
iOPCItem.AutoError := FAutoErrorCheckBox.AsBoolean;
end;
if (Owner is TiCustomEditorForm) then (Owner as TiCustomEditorForm).UserChange;
if Assigned(FOnChange) then FOnChange(Self);
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.SetPropertyName(Index:Integer;Value:String );begin(FOPCItemList.Items.Objects[Index]as TiOPCItem).PropertyName:=Value;FOPCItemList.Items.Strings[Index]:=Value;end;
procedure TiOPCBrowserPanel.SetGroupName (Index:Integer;Value:String );begin(FOPCItemList.Items.Objects[Index]as TiOPCItem).GroupName :=Value;end;
procedure TiOPCBrowserPanel.SetComputerName(Index:Integer;Value:String );begin(FOPCItemList.Items.Objects[Index]as TiOPCItem).ComputerName:=Value;end;
procedure TiOPCBrowserPanel.SetServerName (Index:Integer;Value:String );begin(FOPCItemList.Items.Objects[Index]as TiOPCItem).ServerName :=Value;end;
procedure TiOPCBrowserPanel.SetItemName (Index:Integer;Value:String );begin(FOPCItemList.Items.Objects[Index]as TiOPCItem).ItemName :=Value;end;
procedure TiOPCBrowserPanel.SetUpdateRate (Index:Integer;Value:Integer);begin(FOPCItemList.Items.Objects[Index]as TiOPCItem).UpdateRate :=Value;end;
procedure TiOPCBrowserPanel.SetAutoConnect (Index:Integer;Value:Boolean);begin(FOPCItemList.Items.Objects[Index]as TiOPCItem).AutoConnect :=Value;end;
procedure TiOPCBrowserPanel.SetAutoError (Index:Integer;Value:Boolean);begin(FOPCItemList.Items.Objects[Index]as TiOPCItem).AutoError :=Value;end;
//****************************************************************************************************************************************************
function TiOPCBrowserPanel.GetPropertyName(Index:Integer):String; begin Result:=(FOPCItemList.Items.Objects[Index]as TiOPCItem).PropertyName;end;
function TiOPCBrowserPanel.GetGroupName (Index:Integer):String; begin Result:=(FOPCItemList.Items.Objects[Index]as TiOPCItem).GroupName; end;
function TiOPCBrowserPanel.GetComputerName(Index:Integer):String; begin Result:=(FOPCItemList.Items.Objects[Index]as TiOPCItem).ComputerName;end;
function TiOPCBrowserPanel.GetServerName (Index:Integer):String; begin Result:=(FOPCItemList.Items.Objects[Index]as TiOPCItem).ServerName; end;
function TiOPCBrowserPanel.GetUpdateRate (Index:Integer):Integer;begin Result:=(FOPCItemList.Items.Objects[Index]as TiOPCItem).UpdateRate; end;
function TiOPCBrowserPanel.GetItemName (Index:Integer):String; begin Result:=(FOPCItemList.Items.Objects[Index]as TiOPCItem).ItemName; end;
function TiOPCBrowserPanel.GetAutoConnect (Index:Integer):Boolean;begin Result:=(FOPCItemList.Items.Objects[Index]as TiOPCItem).AutoConnect; end;
function TiOPCBrowserPanel.GetAutoError (Index:Integer):Boolean;begin Result:=(FOPCItemList.Items.Objects[Index]as TiOPCItem).AutoError; end;
//****************************************************************************************************************************************************
function TiOPCBrowserPanel.AddItem: Integer;
var
OPCItem : TiOPCItem;
begin
OPCItem := TiOPCItem.Create;
Result := FOPCItemList.Items.AddObject('', OPCItem);
FOPCItemList.ItemIndex := Result;
end;
//****************************************************************************************************************************************************
function TiOPCBrowserPanel.ItemCount: Integer;
begin
Result := FOPCItemList.Items.Count;
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.RemoveAllItems;
begin
while FOPCItemList.Items.Count <> 0 do
begin
FOPCItemList.Items.Objects[0].Free;
FOPCItemList.Items.Delete(0);
end;
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.AddButtonClick(Sender: TObject);
var
OPCItem : TiOPCItem;
Index : Integer;
begin
if not Assigned(FPersistent) then raise Exception.Create('Class not Defined');
Screen.Cursor := crHourGlass;
try
iOPCPropertySelectorForm := TiOPCPropertySelectorForm.Create(Application);
try
iOPCPropertySelectorForm.Setup(FPersistent, '');
iOPCPropertySelectorForm.AddUnassigned;
iOPCPropertySelectorForm.PropertyName := FPropertyNameEdit.Text;
if iOPCPropertySelectorForm.ShowModal = mrOK then
begin
OPCItem := TiOPCItem.Create;
GetDefaults(OPCItem);
Index := FOPCItemList.Items.AddObject('', OPCItem);
SetPropertyName(Index, iOPCPropertySelectorForm.PropertyName);
FOPCItemList.ItemIndex := Index;
end;
finally
iOPCPropertySelectorForm.Free;
end;
finally
Screen.Cursor := crDefault;
end;
UpdateItemEdit;
ItemChange;
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.RemoveButtonClick(Sender: TObject);
begin
if FOPCItemList.ItemIndex <> - 1 then FOPCItemList.DeleteSelectedObject;
UpdateItemEdit;
ItemChange;
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.GetDefaults(OPCItem: TiOPCItem);
{$ifdef iVCL}
var
Registry : TRegistry;
AString : String;
{$endif}
begin
{$ifdef iVCL}
Registry := TRegistry.Create;
try
Registry.RootKey := HKEY_CURRENT_USER;
if Registry.OpenKey('SOFTWARE\Iocomp\OPC',False) then
begin
OPCItem.ComputerName := Registry.ReadString('ComputerName');
OPCItem.ServerName := Registry.ReadString('ServerName');
AString := Registry.ReadString('UpdateRate');
if AString <> '' then OPCItem.UpdateRate := StrToInt(AString);
end;
finally
Registry.Free;
end;
{$endif}
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.SetDefaults(PropertyName, PropertyData: String);
{$ifdef iVCL}
var
Registry : TRegistry;
{$endif}
begin
{$ifdef iVCL}
Registry := TRegistry.Create;
try
Registry.RootKey := HKEY_CURRENT_USER;
if Registry.OpenKey('SOFTWARE\Iocomp\OPC',True) then
begin
Registry.WriteString(PropertyName, PropertyData);
end;
finally
Registry.Free;
end;
{$endif}
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.ItemMoveEvent(Sender: TObject);
begin
if (Owner is TiCustomEditorForm) then (Owner as TiCustomEditorForm).UserChange;
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.SetShowProperty(const Value: Boolean);
begin
if FShowProperty <> Value then
begin
FShowProperty := Value;
AdjustLayout;
end;
end;
//****************************************************************************************************************************************************
procedure TiOPCBrowserPanel.SetShowAutoError(const Value: Boolean);
begin
if FShowAutoError <> Value then
begin
FShowAutoError := Value;
AdjustLayout;
end;
end;
//****************************************************************************************************************************************************
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -