![]() |
AV bei Umwandlung der Klasse
Hi,
ich steh grad aufem Schlauch. Folgender Code:
Delphi-Quellcode:
Beim Pfeil gibts ne AV. Warum?
type
TEintrag = class Fenster: String; Titel: String; Caption: String; end; [...] procedure Tfmain.Button1Click(Sender: TObject); var Eintrag: TEintrag; Fenster: String; Titel: String; begin Eintrag := TEintrag.Create; Eintrag := TEintrag(Listbox1.Items[ListBox1.ItemIndex]); ShowWindow(FindWindow(PChar(Eintrag.Fenster), PChar(Eintrag.Titel)), SW_HIDE); //<--- ListBox1.Items.Strings[Index] := ListBox1.Items.Strings[Index] + '|*'; Button1.Enabled := false; Button2.Enabled := true; end; // Hinzufügen procedure Tfadd.Button2Click(Sender: TObject); begin with TEintrag.Create do begin Titel := lTitel.Caption; Fenster := lFenster.Caption; Caption := lTitel.Caption; fmain.ListBox1.AddItem(Caption, Self); end; end; |
Re: AV bei Umwandlung der Klasse
Hi,
Delphi-Quellcode:
seit wann lässt sich ein String auf eine Klasse casten? :shock:
Eintrag := TEintrag(Listbox1.Items[ListBox1.ItemIndex]);
mfG mirage228 |
Re: AV bei Umwandlung der Klasse
Wie sollte ich es sonst machen? :oops:
|
Re: AV bei Umwandlung der Klasse
Hi,
wie wäres mit
Delphi-Quellcode:
:roll:
Items.Objects[]
Und nächster Fehler:
Delphi-Quellcode:
Self = Form1 und nicht die Instanz von TEintrag. Also musst du wohl mit ner Variable arbeiten.
with TEintrag.Create do
begin Titel := lTitel.Caption; Fenster := lFenster.Caption; Caption := lTitel.Caption; fmain.ListBox1.AddItem(Caption, Self); end; mfG mirage228 |
Re: AV bei Umwandlung der Klasse
Zu dem erzeugst du mit Eintrag := TEintrag.Create; in Button1Click ein Speicherleck, weil du eine Zeile später Eintrag wieder überschreibst.
|
Re: AV bei Umwandlung der Klasse
Hi,
heut ist wohl nicht mein Tag :(. Aber Thx. :) Jetzt gehts. *MFG* Mani :hi: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:03 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-2025 by Thomas Breitkreuz