Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Variable innerhalb einer anderen (https://www.delphipraxis.net/46420-variable-innerhalb-einer-anderen.html)

Khabarakh 29. Jul 2005 15:09

Re: Variable innerhalb einer anderen
 
Ich durchschaue zwar nicht ganz dein Progrmm, aber prinzipiell geht das schon. Erstmal heißt es: Records weg, OOP her :wink: . Du hast bei deiner Klasse eine Array-Property, in der die Werte gespeichert sind. Als Index der Property kannst du einen String benutzen, wenn du die Property zusätzlich noch als default markierst, kannst du sie so ansprechen:
Delphi-Quellcode:
Konfiguration['Gateway'] := ...;
Hier mal ein konkretes Beispiel (Ansprechen von Bitmaps über einen Namen):
Delphi-Quellcode:
type
  TBitmapCollection = class
  private
    FBitmapList: TObjectList;
    FNameList: TStringList;
    function GetBitmap(AName: string): TBitmap32;
  public
    constructor Create;
    destructor Destroy; override;

    procedure Add(ABit: TBitmap32; AName: string);
    function AddNew(AName: string): TBitmap32;

    property Bitmap[AName: string]: TBitmap32 read GetBitmap; default;
  end;

implementation

{ TBitmapCollection }

function TBitmapCollection.GetBitmap(AName: string): TBitmap32;
begin
  Result := TBitmap32(FBitmapList.Items[FNameList.IndexOf(AName)]);
end;

procedure TBitmapCollection.Add(ABit: TBitmap32; AName: string);
begin
  FBitmapList.Add(ABit);
  FNameList.Add(AName);
end;

function TBitmapCollection.AddNew(AName: string): TBitmap32;
begin
  Result := TBitmap32.Create;
  Add(Result, AName);
end;

destructor TBitmapCollection.Destroy;
begin
  FBitmapList.Free;
  FNameList.Free;
  inherited;
end;

constructor TBitmapCollection.Create;
begin
  inherited;
  FBitmapList := TObjectList.Create;
  FNameList := TStringList.Create;
  LoadGraphicRessources;
end;

end.
Anwendung:
Delphi-Quellcode:
try
    Stream := TFileStream.Create('Graphics.prr', fmOpenRead);

    LoadPNGintoBitmap32(Collection.AddNew('blubb'), Stream, Alpha);
    Collection['blubb'].Line(...);  
  finally
    Stream.Free;
  end;
(Stammt aus diesem Thread)


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:37 Uhr.
Seite 2 von 2     12   

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