- Fixed string type in TfrmAccountControl

This commit is contained in:
Andreas Schneider 2009-12-20 15:49:19 +01:00
parent 158403e41a
commit ee9a44219f
2 changed files with 414 additions and 415 deletions

View File

@ -15,7 +15,7 @@ object frmAccountControl: TfrmAccountControl
OnDestroy = FormDestroy OnDestroy = FormDestroy
OnShow = FormShow OnShow = FormShow
Position = poOwnerFormCenter Position = poOwnerFormCenter
LCLVersion = '0.9.27' LCLVersion = '0.9.29'
object tbMain: TToolBar object tbMain: TToolBar
Left = 0 Left = 0
Height = 26 Height = 26
@ -95,9 +95,10 @@ object frmAccountControl: TfrmAccountControl
Text = 'Accesslevel' Text = 'Accesslevel'
Width = 100 Width = 100
end> end>
Header.DefaultHeight = 17
Header.Options = [hoColumnResize, hoDrag, hoVisible] Header.Options = [hoColumnResize, hoDrag, hoVisible]
Header.ParentFont = True Header.ParentFont = True
Header.Style = hsPlates Header.Style = hsFlatButtons
Images = ilAccesslevel Images = ilAccesslevel
TabOrder = 1 TabOrder = 1
TreeOptions.AutoOptions = [toAutoScrollOnExpand, toAutoTristateTracking, toAutoDeleteMovedNodes] TreeOptions.AutoOptions = [toAutoScrollOnExpand, toAutoTristateTracking, toAutoDeleteMovedNodes]
@ -110,7 +111,6 @@ object frmAccountControl: TfrmAccountControl
OnGetImageIndex = vstAccountsGetImageIndex OnGetImageIndex = vstAccountsGetImageIndex
end end
object ilToolbar: TImageList object ilToolbar: TImageList
Masked = False
left = 144 left = 144
Bitmap = { Bitmap = {
4C69040000001000000010000000000000000000000000000000000000000000 4C69040000001000000010000000000000000000000000000000000000000000
@ -245,7 +245,6 @@ object frmAccountControl: TfrmAccountControl
} }
end end
object ilAccesslevel: TImageList object ilAccesslevel: TImageList
Masked = False
left = 176 left = 176
Bitmap = { Bitmap = {
4C69040000001000000010000000000000000000000000000000000000000000 4C69040000001000000010000000000000000000000000000000000000000000

View File

@ -1,411 +1,411 @@
(* (*
* CDDL HEADER START * CDDL HEADER START
* *
* The contents of this file are subject to the terms of the * The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only * Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance * (the "License"). You may not use this file except in compliance
* with the License. * with the License.
* *
* You can obtain a copy of the license at * You can obtain a copy of the license at
* http://www.opensource.org/licenses/cddl1.php. * http://www.opensource.org/licenses/cddl1.php.
* See the License for the specific language governing permissions * See the License for the specific language governing permissions
* and limitations under the License. * and limitations under the License.
* *
* When distributing Covered Code, include this CDDL HEADER in each * When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at * file and include the License file at
* http://www.opensource.org/licenses/cddl1.php. If applicable, * http://www.opensource.org/licenses/cddl1.php. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed * add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying * information: * by brackets "[]" replaced with your own identifying * information:
* Portions Copyright [yyyy] [name of copyright owner] * Portions Copyright [yyyy] [name of copyright owner]
* *
* CDDL HEADER END * CDDL HEADER END
* *
* *
* Portions Copyright 2008 Andreas Schneider * Portions Copyright 2008 Andreas Schneider
*) *)
unit UfrmAccountControl; unit UfrmAccountControl;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
interface interface
uses uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ComCtrls, Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ComCtrls,
VirtualTrees, Math, UEnhancedMemoryStream, UEnums; VirtualTrees, Math, UEnhancedMemoryStream, UEnums;
type type
{ TfrmAccountControl } { TfrmAccountControl }
TfrmAccountControl = class(TForm) TfrmAccountControl = class(TForm)
ilToolbar: TImageList; ilToolbar: TImageList;
ilAccesslevel: TImageList; ilAccesslevel: TImageList;
tbMain: TToolBar; tbMain: TToolBar;
tbRefresh: TToolButton; tbRefresh: TToolButton;
tbAddUser: TToolButton; tbAddUser: TToolButton;
tbEditUser: TToolButton; tbEditUser: TToolButton;
tbDeleteUser: TToolButton; tbDeleteUser: TToolButton;
tbSeparator1: TToolButton; tbSeparator1: TToolButton;
vstAccounts: TVirtualStringTree; vstAccounts: TVirtualStringTree;
procedure tbEditUserClick(Sender: TObject); procedure tbEditUserClick(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject); procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
procedure tbAddUserClick(Sender: TObject); procedure tbAddUserClick(Sender: TObject);
procedure tbDeleteUserClick(Sender: TObject); procedure tbDeleteUserClick(Sender: TObject);
procedure tbRefreshClick(Sender: TObject); procedure tbRefreshClick(Sender: TObject);
procedure vstAccountsDblClick(Sender: TObject); procedure vstAccountsDblClick(Sender: TObject);
procedure vstAccountsFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode); procedure vstAccountsFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vstAccountsGetImageIndex(Sender: TBaseVirtualTree; procedure vstAccountsGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex; Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: Integer); var Ghosted: Boolean; var ImageIndex: Integer);
procedure vstAccountsGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; procedure vstAccountsGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: UTF8String); Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
protected protected
procedure OnModifyUserResponse(ABuffer: TEnhancedMemoryStream); procedure OnModifyUserResponse(ABuffer: TEnhancedMemoryStream);
procedure OnDeleteUserResponse(ABuffer: TEnhancedMemoryStream); procedure OnDeleteUserResponse(ABuffer: TEnhancedMemoryStream);
procedure OnListUsersPacket(ABuffer: TEnhancedMemoryStream); procedure OnListUsersPacket(ABuffer: TEnhancedMemoryStream);
function FindNode(AUsername: string): PVirtualNode; function FindNode(AUsername: string): PVirtualNode;
end; end;
var var
frmAccountControl: TfrmAccountControl; frmAccountControl: TfrmAccountControl;
implementation implementation
uses uses
UdmNetwork, UPacket, UPacketHandlers, UAdminHandling, UfrmEditAccount; UdmNetwork, UPacket, UPacketHandlers, UAdminHandling, UfrmEditAccount;
type type
PAccountInfo = ^TAccountInfo; PAccountInfo = ^TAccountInfo;
TAccountInfo = record TAccountInfo = record
Username: string; Username: string;
AccessLevel: TAccessLevel; AccessLevel: TAccessLevel;
Regions: TStringList; Regions: TStringList;
end; end;
{ TModifyUserPacket } { TModifyUserPacket }
TModifyUserPacket = class(TPacket) TModifyUserPacket = class(TPacket)
constructor Create(AUsername, APassword: string; AAccessLevel: TAccessLevel; constructor Create(AUsername, APassword: string; AAccessLevel: TAccessLevel;
ARegions: TStrings); ARegions: TStrings);
end; end;
{ TDeleteUserPacket } { TDeleteUserPacket }
TDeleteUserPacket = class(TPacket) TDeleteUserPacket = class(TPacket)
constructor Create(AUsername: string); constructor Create(AUsername: string);
end; end;
{ TRequestUserListPacket } { TRequestUserListPacket }
TRequestUserListPacket = class(TPacket) TRequestUserListPacket = class(TPacket)
constructor Create; constructor Create;
end; end;
{ TModifyUserPacket } { TModifyUserPacket }
constructor TModifyUserPacket.Create(AUsername, APassword: string; constructor TModifyUserPacket.Create(AUsername, APassword: string;
AAccessLevel: TAccessLevel; ARegions: TStrings); AAccessLevel: TAccessLevel; ARegions: TStrings);
var var
regionCount: Byte; regionCount: Byte;
i: Integer; i: Integer;
begin begin
inherited Create($03, 0); inherited Create($03, 0);
FStream.WriteByte($05); FStream.WriteByte($05);
FStream.WriteStringNull(AUsername); FStream.WriteStringNull(AUsername);
FStream.WriteStringNull(APassword); FStream.WriteStringNull(APassword);
FStream.WriteByte(Byte(AAccessLevel)); FStream.WriteByte(Byte(AAccessLevel));
regionCount := Min(ARegions.Count, 256); regionCount := Min(ARegions.Count, 256);
FStream.WriteByte(regionCount); FStream.WriteByte(regionCount);
for i := 0 to regionCount - 1 do for i := 0 to regionCount - 1 do
FStream.WriteStringNull(ARegions.Strings[i]); FStream.WriteStringNull(ARegions.Strings[i]);
end; end;
{ TDeleteUserPacket } { TDeleteUserPacket }
constructor TDeleteUserPacket.Create(AUsername: string); constructor TDeleteUserPacket.Create(AUsername: string);
begin begin
inherited Create($03, 0); inherited Create($03, 0);
FStream.WriteByte($06); FStream.WriteByte($06);
FStream.WriteStringNull(AUsername); FStream.WriteStringNull(AUsername);
end; end;
{ TRequestUserListPacket } { TRequestUserListPacket }
constructor TRequestUserListPacket.Create; constructor TRequestUserListPacket.Create;
begin begin
inherited Create($03, 0); inherited Create($03, 0);
FStream.WriteByte($07); FStream.WriteByte($07);
end; end;
{ TfrmAccountControl } { TfrmAccountControl }
procedure TfrmAccountControl.FormCreate(Sender: TObject); procedure TfrmAccountControl.FormCreate(Sender: TObject);
begin begin
vstAccounts.NodeDataSize := SizeOf(TAccountInfo); vstAccounts.NodeDataSize := SizeOf(TAccountInfo);
AssignAdminPacketHandler($05, TPacketHandler.Create(0, @OnModifyUserResponse)); AssignAdminPacketHandler($05, TPacketHandler.Create(0, @OnModifyUserResponse));
AssignAdminPacketHandler($06, TPacketHandler.Create(0, @OnDeleteUserResponse)); AssignAdminPacketHandler($06, TPacketHandler.Create(0, @OnDeleteUserResponse));
AssignAdminPacketHandler($07, TPacketHandler.Create(0, @OnListUsersPacket)); AssignAdminPacketHandler($07, TPacketHandler.Create(0, @OnListUsersPacket));
end; end;
procedure TfrmAccountControl.FormClose(Sender: TObject; procedure TfrmAccountControl.FormClose(Sender: TObject;
var CloseAction: TCloseAction); var CloseAction: TCloseAction);
begin begin
CloseAction := caHide; CloseAction := caHide;
end; end;
procedure TfrmAccountControl.tbEditUserClick(Sender: TObject); procedure TfrmAccountControl.tbEditUserClick(Sender: TObject);
var var
selected: PVirtualNode; selected: PVirtualNode;
accountInfo: PAccountInfo; accountInfo: PAccountInfo;
regions: TStrings; regions: TStrings;
begin begin
selected := vstAccounts.GetFirstSelected; selected := vstAccounts.GetFirstSelected;
if selected <> nil then if selected <> nil then
begin begin
accountInfo := vstAccounts.GetNodeData(selected); accountInfo := vstAccounts.GetNodeData(selected);
with frmEditAccount do with frmEditAccount do
begin begin
edUsername.Text := accountInfo^.Username; edUsername.Text := accountInfo^.Username;
edUsername.Color := clBtnFace; edUsername.Color := clBtnFace;
edUsername.ReadOnly := True; edUsername.ReadOnly := True;
edPassword.Text := ''; edPassword.Text := '';
lblPasswordHint.Visible := True; lblPasswordHint.Visible := True;
SetAccessLevel(accountInfo^.AccessLevel); SetAccessLevel(accountInfo^.AccessLevel);
SetRegions(accountInfo^.Regions); SetRegions(accountInfo^.Regions);
if ShowModal = mrOK then if ShowModal = mrOK then
begin begin
regions := GetRegions; regions := GetRegions;
dmNetwork.Send(TModifyUserPacket.Create(edUsername.Text, dmNetwork.Send(TModifyUserPacket.Create(edUsername.Text,
edPassword.Text, GetAccessLevel, regions)); edPassword.Text, GetAccessLevel, regions));
regions.Free; regions.Free;
end; end;
end; end;
end; end;
end; end;
procedure TfrmAccountControl.FormDestroy(Sender: TObject); procedure TfrmAccountControl.FormDestroy(Sender: TObject);
begin begin
if AdminPacketHandlers[$05] <> nil then FreeAndNil(AdminPacketHandlers[$05]); if AdminPacketHandlers[$05] <> nil then FreeAndNil(AdminPacketHandlers[$05]);
if AdminPacketHandlers[$06] <> nil then FreeAndNil(AdminPacketHandlers[$06]); if AdminPacketHandlers[$06] <> nil then FreeAndNil(AdminPacketHandlers[$06]);
if AdminPacketHandlers[$07] <> nil then FreeAndNil(AdminPacketHandlers[$07]); if AdminPacketHandlers[$07] <> nil then FreeAndNil(AdminPacketHandlers[$07]);
end; end;
procedure TfrmAccountControl.FormShow(Sender: TObject); procedure TfrmAccountControl.FormShow(Sender: TObject);
begin begin
tbRefreshClick(Sender); tbRefreshClick(Sender);
end; end;
procedure TfrmAccountControl.tbAddUserClick(Sender: TObject); procedure TfrmAccountControl.tbAddUserClick(Sender: TObject);
var var
regions: TStrings; regions: TStrings;
begin begin
with frmEditAccount do with frmEditAccount do
begin begin
edUsername.Text := ''; edUsername.Text := '';
edUsername.Color := clWindow; edUsername.Color := clWindow;
edUsername.ReadOnly := False; edUsername.ReadOnly := False;
edPassword.Text := ''; edPassword.Text := '';
lblPasswordHint.Visible := False; lblPasswordHint.Visible := False;
cbAccessLevel.ItemIndex := 2; cbAccessLevel.ItemIndex := 2;
SetRegions(nil); SetRegions(nil);
if ShowModal = mrOK then if ShowModal = mrOK then
begin begin
regions := GetRegions; regions := GetRegions;
dmNetwork.Send(TModifyUserPacket.Create(edUsername.Text, edPassword.Text, dmNetwork.Send(TModifyUserPacket.Create(edUsername.Text, edPassword.Text,
GetAccessLevel, regions)); GetAccessLevel, regions));
regions.Free; regions.Free;
end; end;
end; end;
end; end;
procedure TfrmAccountControl.tbDeleteUserClick(Sender: TObject); procedure TfrmAccountControl.tbDeleteUserClick(Sender: TObject);
var var
selected: PVirtualNode; selected: PVirtualNode;
accountInfo: PAccountInfo; accountInfo: PAccountInfo;
begin begin
selected := vstAccounts.GetFirstSelected; selected := vstAccounts.GetFirstSelected;
if selected <> nil then if selected <> nil then
begin begin
accountInfo := vstAccounts.GetNodeData(selected); accountInfo := vstAccounts.GetNodeData(selected);
if MessageDlg('Confirmation', Format('Do you really want to delete "%s"?', if MessageDlg('Confirmation', Format('Do you really want to delete "%s"?',
[accountInfo^.Username]), mtConfirmation, [mbYes, mbNo], 0) = mrYes then [accountInfo^.Username]), mtConfirmation, [mbYes, mbNo], 0) = mrYes then
dmNetwork.Send(TDeleteUserPacket.Create(accountInfo^.Username)); dmNetwork.Send(TDeleteUserPacket.Create(accountInfo^.Username));
end; end;
end; end;
procedure TfrmAccountControl.tbRefreshClick(Sender: TObject); procedure TfrmAccountControl.tbRefreshClick(Sender: TObject);
begin begin
dmNetwork.Send(TRequestUserListPacket.Create); dmNetwork.Send(TRequestUserListPacket.Create);
end; end;
procedure TfrmAccountControl.vstAccountsDblClick(Sender: TObject); procedure TfrmAccountControl.vstAccountsDblClick(Sender: TObject);
begin begin
tbEditUserClick(Sender); tbEditUserClick(Sender);
end; end;
procedure TfrmAccountControl.vstAccountsFreeNode(Sender: TBaseVirtualTree; procedure TfrmAccountControl.vstAccountsFreeNode(Sender: TBaseVirtualTree;
Node: PVirtualNode); Node: PVirtualNode);
var var
accountInfo: PAccountInfo; accountInfo: PAccountInfo;
begin begin
accountInfo := vstAccounts.GetNodeData(Node); accountInfo := vstAccounts.GetNodeData(Node);
accountInfo^.Username := ''; accountInfo^.Username := '';
if accountInfo^.Regions <> nil then FreeAndNil(accountInfo^.Regions); if accountInfo^.Regions <> nil then FreeAndNil(accountInfo^.Regions);
end; end;
procedure TfrmAccountControl.vstAccountsGetImageIndex(Sender: TBaseVirtualTree; procedure TfrmAccountControl.vstAccountsGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex; Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: Integer); var Ghosted: Boolean; var ImageIndex: Integer);
var var
accountInfo: PAccountInfo; accountInfo: PAccountInfo;
begin begin
if Column = 0 then if Column = 0 then
begin begin
accountInfo := Sender.GetNodeData(Node); accountInfo := Sender.GetNodeData(Node);
case accountInfo^.AccessLevel of case accountInfo^.AccessLevel of
alNone: ImageIndex := 0; alNone: ImageIndex := 0;
alView: ImageIndex := 1; alView: ImageIndex := 1;
alNormal: ImageIndex := 2; alNormal: ImageIndex := 2;
alAdministrator: ImageIndex := 3; alAdministrator: ImageIndex := 3;
end; end;
end; end;
end; end;
procedure TfrmAccountControl.vstAccountsGetText(Sender: TBaseVirtualTree; procedure TfrmAccountControl.vstAccountsGetText(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: UTF8String); var CellText: String);
var var
accountInfo: PAccountInfo; accountInfo: PAccountInfo;
begin begin
accountInfo := Sender.GetNodeData(Node); accountInfo := Sender.GetNodeData(Node);
case Column of case Column of
1: CellText := UTF8Encode(accountInfo^.Username); 1: CellText := accountInfo^.Username;
2: CellText := UTF8Encode(GetAccessLevelString(accountInfo^.AccessLevel)); 2: CellText := GetAccessLevelString(accountInfo^.AccessLevel);
else else
CellText := ''; CellText := '';
end; end;
end; end;
procedure TfrmAccountControl.OnModifyUserResponse(ABuffer: TEnhancedMemoryStream); procedure TfrmAccountControl.OnModifyUserResponse(ABuffer: TEnhancedMemoryStream);
var var
node: PVirtualNode; node: PVirtualNode;
modifyStatus: TModifyUserStatus; modifyStatus: TModifyUserStatus;
username: string; username: string;
accountInfo: PAccountInfo; accountInfo: PAccountInfo;
i, regions: Integer; i, regions: Integer;
begin begin
modifyStatus := TModifyUserStatus(ABuffer.ReadByte); modifyStatus := TModifyUserStatus(ABuffer.ReadByte);
username := ABuffer.ReadStringNull; username := ABuffer.ReadStringNull;
case modifyStatus of case modifyStatus of
muAdded: muAdded:
begin begin
node := vstAccounts.AddChild(nil); node := vstAccounts.AddChild(nil);
accountInfo := vstAccounts.GetNodeData(node); accountInfo := vstAccounts.GetNodeData(node);
accountInfo^.Username := username; accountInfo^.Username := username;
accountInfo^.AccessLevel := TAccessLevel(ABuffer.ReadByte); accountInfo^.AccessLevel := TAccessLevel(ABuffer.ReadByte);
accountInfo^.Regions := TStringList.Create; accountInfo^.Regions := TStringList.Create;
regions := ABuffer.ReadByte; regions := ABuffer.ReadByte;
for i := 0 to regions - 1 do for i := 0 to regions - 1 do
accountInfo^.Regions.Add(ABuffer.ReadStringNull); accountInfo^.Regions.Add(ABuffer.ReadStringNull);
Messagedlg('Success', Format('The user "%s" has been added.', [username]), Messagedlg('Success', Format('The user "%s" has been added.', [username]),
mtInformation, [mbOK], 0); mtInformation, [mbOK], 0);
end; end;
muModified: muModified:
begin begin
node := FindNode(username); node := FindNode(username);
if node <> nil then if node <> nil then
begin begin
accountInfo := vstAccounts.GetNodeData(node); accountInfo := vstAccounts.GetNodeData(node);
accountInfo^.AccessLevel := TAccessLevel(ABuffer.ReadByte); accountInfo^.AccessLevel := TAccessLevel(ABuffer.ReadByte);
accountInfo^.Regions.Clear; accountInfo^.Regions.Clear;
regions := ABuffer.ReadByte; regions := ABuffer.ReadByte;
for i := 0 to regions - 1 do for i := 0 to regions - 1 do
accountInfo^.Regions.Add(ABuffer.ReadStringNull); accountInfo^.Regions.Add(ABuffer.ReadStringNull);
Messagedlg('Success', Format('The user "%s" has been modified.', [username]), Messagedlg('Success', Format('The user "%s" has been modified.', [username]),
mtInformation, [mbOK], 0); mtInformation, [mbOK], 0);
end; end;
end; end;
muInvalidUsername: muInvalidUsername:
MessageDlg('Error', Format('The username "%s" is not valid.', [username]), MessageDlg('Error', Format('The username "%s" is not valid.', [username]),
mtError, [mbOK], 0); mtError, [mbOK], 0);
end; end;
end; end;
procedure TfrmAccountControl.OnDeleteUserResponse(ABuffer: TEnhancedMemoryStream); procedure TfrmAccountControl.OnDeleteUserResponse(ABuffer: TEnhancedMemoryStream);
var var
node: PVirtualNode; node: PVirtualNode;
deleteStatus: TDeleteUserStatus; deleteStatus: TDeleteUserStatus;
username: string; username: string;
begin begin
deleteStatus := TDeleteUserStatus(ABuffer.ReadByte); deleteStatus := TDeleteUserStatus(ABuffer.ReadByte);
username := ABuffer.ReadStringNull; username := ABuffer.ReadStringNull;
case deleteStatus of case deleteStatus of
duDeleted: duDeleted:
begin begin
node := FindNode(username); node := FindNode(username);
if node <> nil then if node <> nil then
begin begin
vstAccounts.DeleteNode(node); vstAccounts.DeleteNode(node);
Messagedlg('Success', Format('The user "%s" has been deleted.', [username]), Messagedlg('Success', Format('The user "%s" has been deleted.', [username]),
mtInformation, [mbOK], 0); mtInformation, [mbOK], 0);
end; end;
end; end;
duNotFound: duNotFound:
MessageDlg('Error', Format('The user "%s" could not be deleted. Maybe ' + MessageDlg('Error', Format('The user "%s" could not be deleted. Maybe ' +
'your list is out of date or you tried to delete yourself.', [username]), 'your list is out of date or you tried to delete yourself.', [username]),
mtError, [mbOK], 0); mtError, [mbOK], 0);
end; end;
end; end;
procedure TfrmAccountControl.OnListUsersPacket(ABuffer: TEnhancedMemoryStream); procedure TfrmAccountControl.OnListUsersPacket(ABuffer: TEnhancedMemoryStream);
var var
node: PVirtualNode; node: PVirtualNode;
accountInfo: PAccountInfo; accountInfo: PAccountInfo;
i, j, count, regions: Integer; i, j, count, regions: Integer;
begin begin
vstAccounts.BeginUpdate; vstAccounts.BeginUpdate;
vstAccounts.Clear; vstAccounts.Clear;
count := ABuffer.ReadWord; count := ABuffer.ReadWord;
for i := 1 to count do for i := 1 to count do
begin begin
node := vstAccounts.AddChild(nil); node := vstAccounts.AddChild(nil);
accountInfo := vstAccounts.GetNodeData(node); accountInfo := vstAccounts.GetNodeData(node);
accountInfo^.Username := ABuffer.ReadStringNull; accountInfo^.Username := ABuffer.ReadStringNull;
accountInfo^.AccessLevel := TAccessLevel(ABuffer.ReadByte); accountInfo^.AccessLevel := TAccessLevel(ABuffer.ReadByte);
accountInfo^.Regions := TStringList.Create; accountInfo^.Regions := TStringList.Create;
regions := ABuffer.ReadByte; regions := ABuffer.ReadByte;
for j := 0 to regions - 1 do for j := 0 to regions - 1 do
accountInfo^.Regions.Add(ABuffer.ReadStringNull); accountInfo^.Regions.Add(ABuffer.ReadStringNull);
end; end;
vstAccounts.EndUpdate; vstAccounts.EndUpdate;
end; end;
function TfrmAccountControl.FindNode(AUsername: string): PVirtualNode; function TfrmAccountControl.FindNode(AUsername: string): PVirtualNode;
var var
node: PVirtualNode; node: PVirtualNode;
accountInfo: PAccountInfo; accountInfo: PAccountInfo;
begin begin
Result := nil; Result := nil;
node := vstAccounts.GetFirst; node := vstAccounts.GetFirst;
while (node <> nil) and (Result = nil) do while (node <> nil) and (Result = nil) do
begin begin
accountInfo := vstAccounts.GetNodeData(node); accountInfo := vstAccounts.GetNodeData(node);
if accountInfo^.Username = AUsername then if accountInfo^.Username = AUsername then
Result := node; Result := node;
node := vstAccounts.GetNext(node); node := vstAccounts.GetNext(node);
end; end;
end; end;
initialization initialization
{$I UfrmAccountControl.lrs} {$I UfrmAccountControl.lrs}
end. end.