Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Mehrere Instanzen einer von TObject abgeleiteten Klasse (https://www.delphipraxis.net/73818-mehrere-instanzen-einer-von-tobject-abgeleiteten-klasse.html)

Alex2.2 24. Jul 2006 13:14


Mehrere Instanzen einer von TObject abgeleiteten Klasse
 
Ich bin im Moment völlig ratlos. Ich arbeite an einem ASP.NET Projekt in dem mich mir eine Klasse für Benutzerrechte (für den Zugang zur Webseitenfuntionalität) gebaut habe. Diese ist von TObject abgeleitet und deren Interface ist wie folgt definiert:
Delphi-Quellcode:
 {$REGION 'RightsStructure'}


   type TServerActionValues = record
      all :            Boolean;
      add :            Boolean;
      edit:            Boolean;
      editAccUser:     Boolean;
      editAccVehicles: Boolean;
   end;
   type TOwnAccActionsValues = record
      all :            Boolean;
      add :            Boolean;
      edit:            Boolean;
      editOwnPassword: Boolean;
      SetupUserRights: Boolean;
   end;
   type TOwnJouneyActionsValues = record
      all :            Boolean;
      add :            Boolean;
      edit:            Boolean;
   end;

   type TOwnVehicleActionsValues = record
      all :            Boolean;
      edit:            Boolean;
   end;
   type TOwnAlarmActionsValues = record
      all :            Boolean;
      add :            Boolean;
      edit:            Boolean;
   end;
   type TViewVehicleActionsValues = record
      all :            Boolean;
      view :           Boolean;
   end;
   type TViewJourneyActionsValues = record
      all :            Boolean;
      view :           Boolean;
      viewOwn :        Boolean;
   end;
   type TViewDataActionsValues = record
      all :            Boolean;
      viewVehicleSetup: Boolean;
      viewActuals :    Boolean;
      viewHistory :    Boolean;
      viewAlarms :     Boolean;
   end;
   type TViewMapActionsValues = record
      all :            Boolean;
      viewActuals :    Boolean;
      viewHistory :    Boolean;
      viewAlarms :     Boolean;
      Zooming :        Boolean;
      Tracing :        Boolean;
   end;

 {$ENDREGION}


 {$REGION 'Constant Strings'}
   type TServerActions = record
      const all :            String = 'ALL';
      const add :            String = 'ADD';
      const edit:            String = 'EDIT';
      const editAccUser:     String = 'ACCUSEREDIT';
      const editAccVehicles: String = 'ACCVEHICLEEDIT';
   end;
   type TOwnAccActions = record
      const all :            String = 'ALL';
      const add :            String = 'ADD';
      const edit:            String = 'EDIT';
      const editOwnPassword: String = 'OWNPW';
      const SetupUserRights: String = 'URSETUP';
   end;
   type TOwnJouneyActions = record
      const all :            String = 'ALL';
      const add :            String = 'ADD';
      const edit:            String = 'EDIT';
   end;

   type TOwnVehicleActions = record
      const all :            String = 'ALL';
      const edit:            String = 'EDIT';
   end;
   type TOwnAlarmActions = record
      const all :            String = 'ALL';
      const add :            String = 'ADD';
      const edit:            String = 'EDIT';
   end;
   type TViewVehicleActions = record
      const all :            String = 'ALL';
      const view :           String = 'VIEW';
   end;
   type TViewJourneyActions = record
      const all :            String = 'ALL';
      const view :           String = 'VIEW';
      const viewOwn :        String = 'VIEWOWN';
   end;
   type TViewDataActions = record
      const all :            String = 'ALL';
      const viewVehicleSetup: String = 'SETTINGS';
      const viewActuals :    String = 'ACTUALS';
      const viewHistory :    String = 'HISTORY';
      const viewAlarms :     String = 'ALARMS';
   end;
   type TViewMapActions = record
      const all :            String = 'ALL';
      const viewActuals :    String = 'ACTUALS';
      const viewHistory :    String = 'HISTORY';
      const viewAlarms :     String = 'ALARMS';
      const Zooming :        String = 'ZOOM';
      const Tracing :        String = 'TRACE';
   end;
   type TUserActions = record
        ServerSetup    : TServerActions;
        OwnAccSetup    : TOwnAccActions;
        OwnJourneysSetup: TOwnJouneyActions;
        OwnVehicleSetup : TOwnVehicleActions;
        OwnAlarmsSetup : TOwnAlarmActions;
        OwnVehiclesView : TViewVehicleActions;
        OwnJourneysView : TViewJourneyActions;
        DataView       : TViewDataActions;
        Maps           : TViewMapActions;
   end;

   type TModuleStrings = Record
      const ServerSetup     : String = 'SERVERSETUP';
      const OwnAccSetup     : String = 'OWNACCOUNTSETUP';
      const OwnJourneysSetup : String = 'OWNJOURNEYSETUP';
      const OwnVehicleSetup : String = 'OWNVEHICLESETUP';
      const OwnAlarmsSetup  : String = 'OWNALARMSSETUP';
      const OwnVehiclesView : String = 'OWNVEHICLESVIEW';
      const OwnJourneysView : String = 'OWNJOURNEYSVIEW';
      const DataView        : String = 'DATAVIEW';
      const Maps            : String = 'MAPSVIEW';
   end;

 {$ENDREGION}


   type TYN = Array[boolean] of String;
   type TUserRightsSetting = record
       Module : String;
       Action : String;
       Value : Boolean;
   end;

   type TUserRightsTable = record
     class var
     Changable         : Boolean;
     StandardUser      : Boolean;
     DataBaseID        : Integer;
     ServerSetup       : TServerActionValues;
     OwnAccSetup       : TOwnAccActionsValues;
     OwnJourneysSetup  : TOwnJouneyActionsValues;
     OwnVehicleSetup   : TOwnVehicleActionsValues;
     OwnAlarmsSetup    : TOwnAlarmActionsValues;
     OwnVehiclesView   : TViewVehicleActionsValues;
     OwnJourneysView   : TViewJourneyActionsValues;
     DataView          : TViewDataActionsValues;
     Maps              : TViewMapActionsValues;
   end;

 {$REGION 'Private Declarations'}

   private
      { Private Declarations }
      ModulesStr : TModuleStrings;
      ActionsStr : TUserActions;
      Rights : TUserRightsTable;
      function getChangable : boolean;
      function getStandardUser : boolean;
      procedure setChangable(value: Boolean);
      procedure setStandardUser(value : Boolean);
      function getDataBaseID : Integer;
      procedure setDataBaseID(DBID: Integer);
      function getRightItems : Integer;
      function getRightItem(itemid: integer):TUserRightsSetting;
      function getItemCount(item : Integer; var UserRightItem : TUserRightsSetting) :Integer;
  {$ENDREGION}
 {$REGION 'public Declarations'}
   public
      constructor Create;
      property Modules : TModuleStrings read ModulesStr;
      property Actions : TUserActions read ActionsStr;
      property DBID : Integer read getDataBaseID write setDataBaseID;
      property isChangable : Boolean read getChangable write setChangable;
      property isStandardUser : Boolean read getStandardUser write setStandardUser;
      property Items : Integer read getRightItems;
      property Item[itemid : integer] : TUserRightsSetting read getRightItem;
      procedure CopyRightsFrom(Input : TUserRightsTable);
      function getRightsTable : TUserRightsTable;
      property RightsTable : TUserRightsTable read getRightsTable write CopyRightsFrom;
      function getRightFor(currModule: String; currAction: String): Boolean;
      procedure setRightFor(currModule: String; currAction: String; currValue :Boolean);
      function getRightForAsYN(currModule: String; currAction: String): String;
      procedure setRightForAsYN(currModule: String; currAction: String; currValue :String);
      function getChangableAsYN : String;
      function getStandardUserAsYN : String;
      procedure setChangableAsYN(value: String);
      procedure setStandardUserAsYN(value : String);
  {$ENDREGION}
  end;
Mein Problem ist dabei nun, daß ich solange ich ein Object, das mit dieser Klasse instaziert wurde, allein verwende keine Probleme habe, wenn aber ein 2. Object instanziert wird, scheinen beide den selben Speicherraum zu verwenden. Da ich kein absoluter O-O Freak bin, bin ich sicher, daß ich irgendetwas nicht beachtet habe. Nur Was?

mkinzler 24. Jul 2006 13:20

Re: Mehrere Instanzen einer von TObject abgeleiteten Klasse
 
Wie intatntiierst du die Objekte?

Alex2.2 24. Jul 2006 13:31

Re: Mehrere Instanzen einer von TObject abgeleiteten Klasse
 
In Der Klasse befindet sich der Konstruktor:
Delphi-Quellcode:
constructor TUserAccessRights.Create;
begin
  inherited Create;
  // TODO: Add any constructor code here
  Rights.Changable    := true;
  Rights.StandardUser := false;
  Rights.DataBaseID   := 0;

{$REGION 'SettingRightsInit'}

  with Rights.ServerSetup do begin
     all            := true;
     add            := true;
     edit           := true;
     editAccUser    := true;
     editAccVehicles := true;
  end;
  with Rights.OwnAccSetup do begin
     all            :=true;
     add            :=true;
     edit           :=true;
     editOwnPassword :=true;
     SetupUserRights :=true;
  end;
  with Rights.OwnJourneysSetup do begin
     all            :=true;
     add            :=true;
     edit           :=true;
  end;
  with Rights.OwnVehicleSetup do begin
     all            :=true;
     edit           :=true;
  end;
  with Rights.OwnAlarmsSetup do begin
     all            :=true;
     add            :=true;
     edit           :=true;
  end;
{$ENDREGION}
{$REGION 'ViewRightsInit'}
  with Rights.OwnVehiclesView do begin
     all            :=true;
     view           :=true;
  end;
  with Rights.OwnJourneysView do begin
     all            :=true;
     view           :=true;
     viewOwn        :=true;
  end;
  with Rights.DataView do begin
     all             :=true;
     viewVehicleSetup :=true;
     viewActuals     :=true;
     viewHistory     :=true;
     viewAlarms      :=true;
  end;
  with Rights.Maps do begin
     all          :=true;
     viewActuals  :=true;
     viewHistory  :=true;
     viewAlarms   :=true;
     Zooming      :=true;
     Tracing      :=true;
  end;

{$ENDREGION}
end;
und im Parent Object:
wird dann eben der Konstruktor aufgerufen, wie z.B:

Delphi-Quellcode:
function x : boolean
var:
OwnRights : TUserAccessRights;
begin
OwnRights:= TUserAccessRights.create;
...


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:45 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz