Autor Beitrag
ALF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 28.11.09 12:31 
Hi,
Wie der Titel schon sagt, möchte ich diesen Wert in eine Ini speichern und dann wieder lesen!
und in Form1.Position setzen.
Vorteil, zu Hause Arbeite ich mit mehreren Monitore. Gehe ich wo anders hin wo es nur ein Monitor gibt, kann ich in der Ini den Wert ändern z.B von poDesign auf poDefault und das Prog ist auf den StandartMonitor.
Diese Aufgabe stellt sich aber gar nicht so einfach dar wie ich dachte!???
Genauer gesagt ich komm damit nicht klar :oops: :roll:
Da ich den Wert als String in der Ini speichere.
Ich weiss das Form1.Position ein Array ist und poDesign usw. eine Constante! bekomme es aber nicht gebacken!!


Kann mir jemand helfen!?

Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
FinnO
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: Sa 28.11.09 12:51 
man kann auch mit TInifile.writeInteger('Section','key',123456789);//value wunderbar integer speichern und entsprechend mit TInifile.readIntegeR('Section','key',0); //Default wieder lesen.

schließlich ist po***** nichts weiter als eine Konstante mit ord. Wert.
ALF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 28.11.09 13:25 
Wie die Ini funct, weiss ich :wink:
Sorry, ich bin einfach zu blöd das umzusetzen. Hab irgendwie nen blackout

Ein integer wert dafür zu nehmen ist nicht gut, da man sich die po... Konstante als Namen besser merken kann!?

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
FinnO
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: Sa 28.11.09 13:48 
gemeint war:

ausblenden Delphi-Quelltext
1:
2:
3:
myInifile.writeInteger('Section','Key',form1.position);
//bzw.
form1.position := myInifile.readInteger('Section','Key',poScreenCenter);
ALF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 28.11.09 14:00 
Sorry: Das habe ich doch auch schon probiert geht doch nicht!!!

Fehler: Inkompatible Typen: 'integer' und 'TPosition'

Irgend wie wo was, war da noch was, keine Ahnung mehr :cry:
Programmiere nur gelegentlich wenn ich Zeit habe, daher auch die Blackouts, wie wo was mal war usw. :wink:

Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!


Zuletzt bearbeitet von ALF am Sa 28.11.09 14:55, insgesamt 1-mal bearbeitet
FinnO
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: Sa 28.11.09 14:03 
versuch mal
ausblenden Delphi-Quelltext
1:
2:
3:
ord(Form1.position);
//bzw
form1.position := TPosition(myInifile.readinteger('Section','Key',0));
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Sa 28.11.09 14:20 
Du musst den Wert in Integer casten:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
//Speichern:
ini.WriteInteger('Sektion', 'Pos', Integer(Form1.Position));

//Laden:
Form1.Position := TPosition(ini.ReadInteger('Sektion', 'Pos', 0));
ALF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 28.11.09 14:54 
Ja das war es. :lol:

Problem ist natürlich, das die Integerwerte nicht mit den Werten von Form1.Position, so wie man sie im ObjektInspektor angezeigt bekommt übereinstimmt.

ObjektInspektor: Form1.Position

0 = poDefault
1 = poDefaultPosOnly
....
3 = poDesigned

usw.

TPosition = (poDesigned, poDefault, poDefaultPosOnly, poDefaultSizeOnly, poScreenCenter, poDesktopCenter, poMainFormCenter, poOwnerFormCenter);

Darum währe mir der String wichtiger gewesen! aber egal. Wichtig ist das es nun funct und ich das manuell anpassen kann.

THX für die Hilfe

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!
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: Sa 28.11.09 16:40 
Den String bekommt man, wenn man sich über die RTTI von Delphi die benötigten Daten ausliest. Gibt's hier im Forum einige Informationen dazu, daher verzichte ich an dieser Stelle das extra auszuführen.

_________________
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.
ALF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1085
Erhaltene Danke: 53

WinXP, Win7, Win10
Delphi 7 Enterprise, XE
BeitragVerfasst: Sa 28.11.09 17:25 
Habe ich mir angschaut, aber nix kapiert

GetEnumName(TypInfo(TPosition), Form1.Position)
wäre ja meine Idee, funct aber natürlich nicht. Denn das wäre ja zu einfach... omg :(

EDIT: hier die Lösung


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
uses TypInfo;

//für das schreiben in der ini
Pini.WriteString('Settings', 'Position', GetEnumName(TypeInfo(TPosition), ord(Form1.Position)));
       
//für das lesen bzw setzen der Eigenschaft
Form1.Position := TPosition(GetEnumValue(TypeInfo(TPosition), Pini.ReadString('Settings', 'Position', 'poDefault')));


funct Super :D

Gruss Alf

_________________
Wenn jeder alles kann oder wüsste und keiner hätt' ne Frage mehr, omg, währe dieses Forum leer!