Ich habe eine Klasse programmiert, die u.a. mehrere TBitmaps deklariert:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67:
| Type TFirma = class private fCode: String; fLongName: String; fLaufwerk: String; fLogoName: String; fMarkenLogoName: String; fPromotionLogoName: String; fLogo: TBitmap; fMarkenLogo: TBitmap; fPromotionLogo: TBitmap; fFirmaNr: ShortInt; public Function Init: Boolean; Function Dispose: Boolean; Function Lesen: Boolean; Function Schreiben: Boolean; Function Wechseln(fnr: ShortInt): Boolean; overload; function Wechseln: Boolean; overload; published Property FirmaNr: ShortInt read fFirmaNr; Property Code: String read fCode; Property Name: String read fLongName; Property Laufwerk: String read fLaufwerk; Property Logo: TBitmap read fLogo; Property MarkenLogo: TBitmap read fMarkenLogo; Property PromotionLogo: TBitmap read fPromotionLogo; end;
Function TFirma.Init: Boolean; begin Result := True; Firma := TFirma.Create; Firma.fFirmaNr := -1; try firma.fLogo := TBitmap.Create; Firma.fMarkenLogo := TBitmap.Create; Firma.fPromotionLogo := TBitmap.Create; except Result := False; end; end;
function TFirma.Lesen: Boolean; const Modul: String = 'Firma.Lesen'; var IniFileApplication: TiniFile; b: TBitmap; fn: String; begin Result := True; ... try Firma.fLogo := nil; Firma.fMarkenLogo := nil; Firma.fPromotionLogo := nil; b := TBitmap.Create; try fn := IniLaufwerk+':\Data\Firma_'+IntToStr(Firma.FirmaNr)+'\'+Firma.fLogoName; b.LoadFromFile(fn); Firma.fLogo := b; except Assert(false, 'Firmenlogo kann nicht geladen werden: '+fn); Firma.fLogo := nil; end; ... end; |
Firma.Init und Firma.Laden gehen wundervoll.
Sobald ich aber auf eine Grafik zugreifen will (z.B.
Delphi-Quelltext
1:
| if (not Firma.Logo.Empty then ...) |
erhalte ich eine access violation.
Was mache ich falsch?