Autor Beitrag
Lux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Di 21.12.04 10:53 
Guten Morgen auch :)

Ich hab hier mal wieder ein Problem. Und zwar möchte ich einen StringGrid sortieren.
Das klappt auch wunderbar, kann auf wie auch ab sortieren. Nun hab ich ein neues Fenster gemacht, wo man aussuchen kann, nach welcher Spalte man sortieren will.
Da dachte ich mir, da du in deiner Procedure SortiereStringGrid die Spaltenzahl angeben musst (Um nach Spalte 1 zu sortieren gibt man halt 1 ein usw.) kannst du ja den ItemIndex von der Combobox nehmen und dann danach sortieren lassen.

Also hab ich in der Combobox die Auswahl so angelegt, das jeder Sortiername der Nummer der Spalte gleicht.

Starten tut Delphi das Programm auch. Allerdings, wenn ich dann das ganze noch in eine Ini speichern möchte, damit das Prog beim nächsten starten noch weiß wie sortiert wurde. Bekomme ich eine Fehlermeldung mit Absturz.

Zitat:
Debugger Exception Notification

Project Cogpack.exe raised exception class EAccessViolation with message 'Access Violation at address 00477A5B in module 'Cogpack.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue


Wisst ihr warum das nicht klappt, und wie man das beheben kann?

Quellcode:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  Sortierung: integer;
begin
  //Hier beim speichern in die Variable bricht er ab
  Sortierung := Sortierung_frm.ComboBox1.ItemIndex; //das Speichern der Inidatei erfolgt
                                                    //in hauptmenue_frm und die 
                                                    //Sortierung in Sortierung_frm
with IniDat do
  begin
    WriteInteger('Sortierung','Nach',Sortierung)
  end;
end;

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Di 21.12.04 11:09 
Auf den ersten Blick sollte das funktionieren.

Voraussetzung ist natürlich, dass du auch dein Ini-File vernünftig erzeugt hast.

Das Lesen von ItemIndex der Combobox sollte mit deinem Problem nichts zu tun haben. Du bekommst da Werte von 0 bis ... bzw. -1, wenn kein Eintrag ausgewählt ist.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 21.12.04 11:09 
Wird Sortierung_frm dynamisch, d.h. zur Laufzeit erzeugt?
Wenn ja, liegt der Fehler sicherlich daran, dass Sortierung_frm nicht initialisiert ist.

Ansonsten:
Setz dir mal einen Haltepunkt auf diese Zeile und trag folgende beide Ausdrücke in deiner "Liste überwachter Ausdrücke" ein:
1. Sortierung_frm
2. Sortierung_frm.Combobox1
Ich bin mir jetzt grad nicht ganz sicher, aber du solltest "Funktionsaufrufe gestatten" aktivieren. Sonst kann es passieren, dass der Compiler die Ergebnisse fälschlicherweise als "unverfügbar" markiert.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Di 21.12.04 11:41 
Hallo..
Hier das Ergebnis.

Zitat:
Sortierung_frm: ([csInheritable], False, False, (0,0), nil, [], nil,nil,nil,nil,nil,nil,nil)
Sortierung_frm.ComboBox1: nil


und zusätzlich noch:

Zitat:
Sortierung_frm.ComboBox1.ItemIndex: Expression illegal in evaluator.


Ich sortiere vorher ja auch mit dem ItemIndex. Da klappt das auch wunderbar. Da kann ich das auch in eine andere Variable speichern.
Vorher mach ich:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
//Ausszug aus der Procedure
SortiereStringGrid(StringGrid1, ThatCol)

begin
 ThatCol := ThatCol + 1;
end;

SortiereStringGrid(StringGrid1, ComboBox1.ItemIndex);

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 21.12.04 12:02 
Igedwo wird die ComboBox1 freigegeben. Poste mal den Unit-Source der Funktionen, die du vorher noch mit aufrufst.

Ich weiß zumindest schon, dass der Bug in einer der anderen Routinen liegen muss.

Wenn Sortierung_frm.FindComponent('ComboBox1') auch nil ergibt, wird die Kompo durch irgendwas freigegeben, ansonsten überschreibst du ausversehen den Wert im Form-Objekt.

Weiteres kann ich mit den Unit-Sources gucken.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Di 21.12.04 12:16 
Was genau meinst du mit Unit-Source?

den Source des ganzen Programms?
Sonst wo finde ich den denn?

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.
Lux Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 104

Win XP Home
D2005 Pers.
BeitragVerfasst: Di 21.12.04 12:37 
Ich denke den Fehler gefunden zu haben.
Und zwar mache ich nachdem man auf OK geklickt hat. Natürlich Sortierung_frm.Hide damit das Fenster wieder verschwindet. Wenn ich nun vorher das comboBox1.ItemIndex in einer globale Variable schiebe, und diese dann nachher in die INI-Datei speicher, dann klappt es auch mit dem Nachbarn.

Gibt es noch eine feinere Variante oder ist das schon die Beste?

_________________
There are 10 different people.
Those who understand binary code and those who don't understand.