Autor Beitrag
110022
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Sa 06.12.08 20:47 
Hi

Ich bekomme es einfach nicht hin den wert von "WindowState"
in einer Ini einzuspeichern

So hab ich es bisher versucht
ausblenden Delphi-Quelltext
1:
2:
3:
ini.writebool('MainWindow','WindowState',form1.Windowstate);

[Fehler] Unit4.pas(113): Inkompatible Typen: 'Double' und 'TWindowState'


Aber es klappt nicht und mit der Fehlermeldung kann ich nichts anfangen.

Kann mir da bitte jemand helfen?

danke im Voraus.
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Sa 06.12.08 20:51 
Windowstate ist ein integer, also musst du auch einen Integer speichern...
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Sa 06.12.08 20:59 
user profile iconBoldar hat folgendes geschrieben Zum zitierten Posting springen:
Windowstate ist ein integer, also musst du auch einen Integer speichern...

Integer funktioniert auch nicht, es wird diese Meldung ausgespuckt

ausblenden Delphi-Quelltext
1:
[Fehler] Unit4.pas(113): Inkompatible Typen: 'Integer' und 'TWindowState'					
SAiBOT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: Sa 06.12.08 21:09 
ausblenden Delphi-Quelltext
1:
ini.writeInteger('MainWindow','WindowState',Integer(form1.Windowstate));					


ausblenden Quelltext
1:
(wsNormal = 0, wsMinimized = 1, wsMaximized = 2)					


:wink:

_________________
Debuggers don't remove bugs, they only show them in slow-motion.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 06.12.08 21:51 
Ich würde es eher nach Byte casten, denn intern wird AFAIK das benutzt für Aufzählungen und nicht Integer. ;-)
Speichern geht dann natürlich damit über WriteInteger.
SAiBOT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: Sa 06.12.08 22:09 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
Ich würde es eher nach Byte casten, denn intern wird AFAIK das benutzt für Aufzählungen und nicht Integer. ;-)
Speichern geht dann natürlich damit über WriteInteger.


Hat das Sinn wenn WriteInteger es wieder "nach" Integer Castet?

_________________
Debuggers don't remove bugs, they only show them in slow-motion.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 06.12.08 22:14 
Ich müsste mir mal den Assemblercode dazu anschauen, aber das ist ja kein Cast im eigentlichen Sinn, da kann man schon davon ausgehen, dass der Compiler das dann schon richtig macht. ;-)
Ein direkter Cast wird aber von Delphi nicht weiter geprüft. D.h. da muss man dann schon sicher sein, dass es exakt dieser Typ ist, denn man sagt ja: "Egal was du denkst was das ist, du, Delphi, behandele das jetzt als Integer.". Und meiner Meinung nach war das Byte und nicht Integer. Und da ist ja ein Unterschied von 3 Byte.

Aber das lässt sich ja überprüfen wie das auf Assemblerebene aussieht, da hab ich bisher nicht diesen Fall angeschaut. ;-)
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Sa 06.12.08 22:15 
Ja, das mit byte sieht schöner aus...
man kann auch das schreiben:
ausblenden Delphi-Quelltext
1:
ini.writeinteger('Mainwindow''Windowstate', integer(byte(cardinal(char(byte(self.windowstate))))));					
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 06.12.08 22:27 
Ich habe mich geirrt, bei Sets ist es Byte, bei Aufzählungen wohl nicht, da ist Integer wohl richtig. :oops:

// EDIT:
Ich sehe schon, die Größe wird dynamisch verändert je nach Anzahl und Inhalt der Werte. Sind es bis zu 256 wird 1 Byte verwendet, sind die Werte darüber 2 Byte, etc.
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Sa 06.12.08 23:29 
user profile iconSAiBOT hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
ini.writeInteger('MainWindow','WindowState',Integer(form1.Windowstate));					


ausblenden Quelltext
1:
(wsNormal = 0, wsMinimized = 1, wsMaximized = 2)					


:wink:


Hab das genommen, das mit Byte ist mir zu kompliziert^^
Funktioniert der überhaupt mit Byte?

Wie sieht as aus wenn ich aus der Ini den wert wieder auslesen will?

so?
ausblenden Delphi-Quelltext
1:
form1.WindowState:=Ini.readInteger('MainWindow','WindowState',Integer(form1.Windowstate));					


Zuletzt bearbeitet von 110022 am Sa 06.12.08 23:31, insgesamt 1-mal bearbeitet
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Sa 06.12.08 23:30 
Kann man den löschen?

Hab mich verklickt.....
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 07.12.08 00:18 
ausblenden Delphi-Quelltext
1:
Form1.WindowState := TWindowState(Ini.readInteger('MainWindow''WindowState', Integer(wsNormal)));					
Wenn der Typ TWindowState ist, sonst musst du den entsprechend schreiben.
Der dritte Parameter ist der Standardwert, der zurückgegeben wird, wenn der Wert nicht existiert.
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: So 07.12.08 00:22 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
Form1.WindowState := TWindowState(Ini.readInteger('MainWindow''WindowState', Integer(wsNormal)));					
Wenn der Typ TWindowState ist, sonst musst du den entsprechend schreiben.
Der dritte Parameter ist der Standardwert, der zurückgegeben wird, wenn der Wert nicht existiert.

Danke, das klappt wunderbar, musste nur das "wsNormal" gegen das passende form1.Windowstate austauschen.

Vielen dank für eure Hilfe :zustimm:
Chemiker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 194
Erhaltene Danke: 14

XP, Vista 32 Bit, Vista 64 Bit, Win 7 64 Bit, Win 10, Win 11
BDS 2006, RAD Studio 2009+C++, Delphi 13, VS 2010 Prof.
BeitragVerfasst: So 07.12.08 10:07 
Hallo 110022,

in der Delphi-Hilfe steht unter „TIniFile und TMemIniFile verwenden“, dass folgende Beispiel:


ausblenden volle Höhe Delphi-Quelltext
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:
procedure TForm1.FormCreate(Sender: TObject);
var
  Ini: TIniFile;
begin
  Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.INI' ) );
  try
    Top     := Ini.ReadInteger( 'Form''Top'100 );
 Left    := Ini.ReadInteger( 'Form''Left'100 );
 Caption := Ini.ReadString( 'Form''Caption''New Form' );
    if Ini.ReadBool( 'Form''InitMax', false ) then
      WindowState = wsMaximized
    else
      WindowState = wsNormal;
  finally
    TIniFile.Free;
  end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action TCloseAction)
var
  Ini: TIniFile;
begin
  Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.INI' ) );
  try
    Ini.WriteInteger( 'Form''Top', Top);
    Ini.WriteInteger( 'Form''Left', Left);
 Ini.WriteString( 'Form''Caption', Caption );
    Ini.WriteBool( 'Form''InitMax', WindowState = wsMaximized );
  finally
    TIniFile.Free;
  end;
end;


Bis bald Chemiker
SAiBOT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: Mo 08.12.08 11:28 
user profile iconChemiker hat folgendes geschrieben Zum zitierten Posting springen:
Hallo 110022,

in der Delphi-Hilfe steht unter „TIniFile und TMemIniFile verwenden“, dass folgende Beispiel:


ausblenden volle Höhe Delphi-Quelltext
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:
procedure TForm1.FormCreate(Sender: TObject);
var
  Ini: TIniFile;
begin
  Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.INI' ) );
  try
    Top     := Ini.ReadInteger( 'Form''Top'100 );
 Left    := Ini.ReadInteger( 'Form''Left'100 );
 Caption := Ini.ReadString( 'Form''Caption''New Form' );
    if Ini.ReadBool( 'Form''InitMax', false ) then
      WindowState = wsMaximized
    else
      WindowState = wsNormal;
  finally
    TIniFile.Free;
  end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action TCloseAction)
var
  Ini: TIniFile;
begin
  Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.INI' ) );
  try
    Ini.WriteInteger( 'Form''Top', Top);
    Ini.WriteInteger( 'Form''Left', Left);
 Ini.WriteString( 'Form''Caption', Caption );
    Ini.WriteBool( 'Form''InitMax', WindowState = wsMaximized );
  finally
    TIniFile.Free;
  end;
end;


Bis bald Chemiker


Dort wird wsMinimized nicht behandelt!

_________________
Debuggers don't remove bugs, they only show them in slow-motion.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 08.12.08 12:15 
Das sollte sich mit minimalem Aufwand ja nachrüsten lassen. Viel mehr Sorge macht mir
Zitat:
ausblenden Delphi-Quelltext
1:
2:
3:
finally
    TIniFile.Free;
  end;

Hier soll eine Klasse freigegeben werden und keine Instanz :shock:
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 08.12.08 12:23 
Und das steht wirklich original so inkl. der verkorksten Einrückung in der Hilfe von D7, ich hab grad nochmal nachgeschaut.
:autsch: :autsch: :autsch: :autsch: :autsch: :autsch:
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mo 08.12.08 12:27 
user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
Und das steht wirklich original so inkl. der verkorksten Einrückung in der Hilfe von D7, ich hab grad nochmal nachgeschaut.
:autsch: :autsch: :autsch: :autsch: :autsch: :autsch:

Und in Delphi 2006 steht es auch noch genauso drin.

Gruß,
Jens
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 08.12.08 12:30 
Danach hab ich es fast geahnt, das gilt auch für Delphi 2009... :roll:
Sollte das wirklich noch niemandem aufgefallen sein? :shock:

// EDIT:
Doch, ist es, das steht seit 2003 für D7 in der Quality Central die Meldung... :autsch:
SAiBOT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: Mo 08.12.08 13:49 
user profile iconDeddyH hat folgendes geschrieben Zum zitierten Posting springen:
Das sollte sich mit minimalem Aufwand ja nachrüsten lassen.


Ja nur dann nicht mehr mit Boolean, also ist das ganze Bsp. futsch :P .

user profile iconDeddyH hat folgendes geschrieben Zum zitierten Posting springen:
Viel mehr Sorge macht mir
Zitat:
ausblenden Delphi-Quelltext
1:
2:
3:
finally
    TIniFile.Free;
  end;

Hier soll eine Klasse freigegeben werden und keine Instanz :shock:


xD

_________________
Debuggers don't remove bugs, they only show them in slow-motion.