AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Pfadangaben bei Image-Dateien

Ein Thema von XardasLP · begonnen am 5. Feb 2016 · letzter Beitrag vom 6. Feb 2016
Antwort Antwort
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#1

AW: Pfadangaben bei Image-Dateien

  Alt 6. Feb 2016, 10:54
Also egal in welchem Ordner ist es ja nun nicht, sondern die Dateien befinden sich ja immer relativ zum Anwendungsverzeichnis.
Code:
.\Anwendung.exe
.\Spielkarten\Spielkarte1.jpg
.\Spielkarten\Spielkarte2.jpg
...
Diese Dateien sind also ein fester Bestandteil der Anwendung und somit per Definition eine Ressource.

Ressourcen können sich direkt in der Anwendung befinden oder eben auch getrennt vorliegen.

Am sinnvollsten definiert man das auch so in seinem Programm
Delphi-Quellcode:
unit Unit1;

interface

type
  Resources = class sealed
  private const
    SpielkartenFolder = 'Spielkarten';
    Spielkarten: array [ 0 .. 7 ] of string = (
      {} 'Spielkarte1.jpg',
      {} 'Spielkarte2.jpg',
      {} 'Spielkarte3.jpg',
      {} 'Spielkarte4.jpg',
      {} 'Spielkarte5.jpg',
      {} 'Spielkarte6.jpg',
      {} 'Spielkarte7.jpg',
      {} 'Spielkarte8.jpg' );
  private
    class function GetAppFolder: string; static;
    class function PathCombine( const PartA, PartB: string ): string; overload;
    class function PathCombine( const Parts: array of string ): string; overload;
    class function GetSpielkarte( const Index: Integer ): string; static;

    class property AppFolder: string read GetAppFolder;
  public
    class property Spielkarte1: string index 0 read GetSpielkarte;
    class property Spielkarte2: string index 1 read GetSpielkarte;
    class property Spielkarte3: string index 2 read GetSpielkarte;
    class property Spielkarte4: string index 3 read GetSpielkarte;
    class property Spielkarte5: string index 4 read GetSpielkarte;
    class property Spielkarte6: string index 5 read GetSpielkarte;
    class property Spielkarte7: string index 6 read GetSpielkarte;
    class property Spielkarte8: string index 7 read GetSpielkarte;
  end;

implementation

uses
  SysUtils;

{ Resources }

class function Resources.GetAppFolder: string;
begin
  Result := ExtractFilePath( ParamStr( 0 ) );
end;

class function Resources.GetSpielkarte( const Index: Integer ): string;
begin
  Result := PathCombine( [ AppFolder, SpielkartenFolder, Spielkarten[ index ] ] );
end;

class function Resources.PathCombine( const PartA, PartB: string ): string;
begin
  Result := IncludeTrailingPathDelimiter( PartA ) + PartB;
end;

class function Resources.PathCombine( const Parts: array of string ): string;
var
  I: Integer;
begin
  Result := Parts[ 0 ];

  for I := 1 to high( Parts ) do
    begin
      Result := PathCombine( Result, Parts[ I ] );
    end;
end;

end.
und in der Anwendung brauche ich dann nur noch Image1.Picture.LoadFromFile( Resources.Spielkarte1 ); aufrufen.

(Ist schon lange her, aber class property kennt Delphi 7 wohl noch nicht )
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:59 Uhr.
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 by Thomas Breitkreuz