Einzelnen Beitrag anzeigen

Reinhard Kern

Registriert seit: 22. Okt 2006
772 Beiträge
 
#9

Re: Änderung einer Deklarartion integer <-> double mög

  Alt 15. Jun 2009, 11:57
Zitat von BAMatze:
Also möchte eigentlich keine weiteren Operationen damit durchführen. Ich möchte eigentlich nur den Wert, der in meiner Komponente in einem TEdit steht variabel halten.
Würde das gehen?
Hallo,

grundsätzlich geht immer alles, ist bloss eine Frage des Aufwands. Ich benutze im Folgenden einen Record mit case of, keine Delphi Varianten. Wichtig: es gibt für jeden Typ einen Constructor, und der legt auch für den Rest des Lebens den Typ fest. Abgerufen werden die Werte mit Object.GetInteger, Object.GetString usw. dadurch ist Typprüfung gegeben - ich benutze absichtlich kein Overloading, ich will lieber einen Fehler sehen, wenn ich mich vertan habe. Das mit der Konstruktion auch dyn. Array und Strings möglich sind (Casting mit TRKiniSettingRecordS anstatt TRKiniSettingRecord), tut hier nichts zur Sache. Ist nur ein unvollständiges Schema, keine Copy&Paste-Vorlage!!

Gruss Reinhard

Delphi-Quellcode:
   TRKiniSettingVariant = (sv_Undef,sv_String,sv_Bool,sv_Integer,
                           sv_Real,sv_Color,sv_Pen,sv_WinPos,sv_Font,sv_Binary);
{...}
   PRKiniSettingRecord = ^TRKiniSettingRecord;
   TRKiniSettingRecord = packed record
     SetupControl : TControl;
     dirty : boolean;
     removed : boolean;
       case TRKiniSettingVariant of
         sv_Undef : (vUndef : int64); { 8 bytes }
         sv_Bool : (vBool : boolean); { svWinpos }
         sv_Integer : (vInteger : longint);
         sv_Real : (vReal : double);
         sv_Color : (vColor : TColor);
         sv_Pen : (vPen : longint);
       { sv_WinPos  :  see above }
       { sv_Binary,sv_String,sv_Font  :  see below }
     end;
    { record size : 20 b }

   PRKiniSettingRecordB = ^TRKiniSettingRecordB;
   TRKiniSettingRecordB = packed record
     SetupControl : TControl;
     dirty : boolean;
     removed : boolean;
     vBinary : TRKIniBinaryArray;
     BDummy : DWord;
     end;

   PRKiniSettingRecordS = ^TRKiniSettingRecordS;
   TRKiniSettingRecordS = packed record
     SetupControl : TControl;
     dirty : boolean;
     removed : boolean;
     vString : TRKIniDynString;
     BDummy : DWord;
     end;
{...}
   TRKiniSettingValue = class
     sType : TRKiniSettingVariant;
     gType : TRKIniSettingsGrouping;
     digits : Smallint;
     Uplink : TRKIniSettingTable;
     ForwardLink : TRKiniSettingValue;
     pGroupItems : PRKiniSettingRecord; { 0 : Default. 1..n : Items }
     IniGroup,IniItem : TRKiniSettingName;
     FirstRecord,FieldLength,ExtraRecords : word;
     procedure SetupGrouping (imax : Smallint);
     procedure Create_General (imax : Smallint; IG,II : TRKiniSettingName;
                const Def; pCC : PAoTC; maxCC : Smallint; OwnerTable : TRKIniSettingTable);
     constructor Create_String (imax : Smallint; IG,II : TRKiniSettingName;
             Def : ShortString; EC : array of TEdit; OwnerTable : TRKIniSettingTable);
     constructor Create_Bool (imax : Smallint; IG,II : TRKiniSettingName;
                    Def : Boolean; BC : array of TButtonControl; OwnerTable : TRKIniSettingTable);
     constructor Create_Integer (imax : Smallint; IG,II : TRKiniSettingName;
                    Def : longint; EC : array of TEdit; OwnerTable : TRKIniSettingTable);
{...}
     function GetString (ix : Smallint) : ShortString;
     function GetBool (ix : Smallint) : boolean;
     function GetInteger (ix : Smallint) : longint;
     function GetReal (ix : Smallint) : Double;
     function GetColor (ix : Smallint) : TColor;
     function GetPenWidth (ix : Smallint) : Smallint;
{...}
{ speziell für ein Projekt: }
  TBPMLogSettings = class (TRKIniSettingTable)
    public
    Station_Node : TRKiniSettingValue; { group }
    Station_Description : TRKiniSettingValue; { group }
{...}
constructor TBPMLogSettings.CreateTable (IC : TRKIniClass);
var CSection : ShortString;

begin
inherited Create (IC);

with BLMainForm do
  begin
  CSection := 'Station';
  Station_Node := TRKiniSettingValue.Create_Integer (-maxStationNo,CSection,
        'Node',0, [] ,self);
  Station_Description := TRKiniSettingValue.Create_String (-maxStationNo,CSection,
        'Description','', [] ,self);
{...}
  Mit Zitat antworten Zitat