I have solved the problem myself by taking the numerical position of the
controls. It works as long as you don't add, delete, or change position of
the controls.
It's not worked out for all type of controls, but it's easy to extend.
Cheers,
Stephan
//---------------------------------------------------------- --------------------
METHOD ReadIni()
LOCAL oIni
LOCAL n, aControls := {}
LOCAL cClassName
LOCAL cValue
WITH OBJECT oIni := TIni():New()
:cFilename := StrTran(Lower(Application:cFilename), ".exe", ".ini")
GetControls(Self, aControls)
FOR n := 1 TO Len(aControls)
cClassName := aControls[n]:ClassName()
IF cClassName == "TEdit" .OR. cClassName == "TEditBtn"
aControls[n]:Value := oIni:GetEntry("CONTROLS", PadL(n, 3, "0"))
ELSEIF cClassName == "TComboBox"
aControls[n]:cText := oIni:GetEntry("CONTROLS", PadL(n, 3, "0"))
ELSEIF cClassName == "TRadioMenu"
aControls[n]:nIndex := Val(oIni:GetEntry("CONTROLS", PadL(n, 3,
"0")))
ELSEIF cClassName == "TCheckBox"
aControls[n]:lChecked := oIni:GetEntry("CONTROLS", PadL(n, 3,
"0")) == "1"
ENDIF
NEXT nControl
END
RETURN Nil
//---------------------------------------------------------- --------------------
METHOD SaveIni()
LOCAL oIni
LOCAL n, aControls := {}
LOCAL cClassName
LOCAL uValue
WITH OBJECT oIni := TIni():New()
:cFilename := StrTran(Lower(Application:cFilename), ".exe", ".ini")
GetControls(Self, aControls)
FOR n := 1 TO Len(aControls)
cClassName := aControls[n]:ClassName()
IF cClassName == "TEdit" .OR. cClassName == "TEditBtn"
:SetEntry("CONTROLS", PadL(n, 3, "0"), aControls[n]:Value)
ELSEIF cClassName == "TComboBox"
:SetEntry("CONTROLS", PadL(n, 3, "0"), aControls[n]:cText)
ELSEIF cClassName == "TRadioMenu"
:SetEntry("CONTROLS", PadL(n, 3, "0"),
Ltrim(Str(aControls[n]:nIndex)))
ELSEIF cClassName == "TCheckBox"
:SetEntry("CONTROLS", PadL(n, 3, "0"),
IIF(aControls[n]:lChecked, "1", "0"))
ENDIF
NEXT nControl
:Commit()
END
RETURN Nil
//---------------------------------------------------------- --------------------
STATIC PROCEDURE GetControls(oParent, aControls)
LOCAL oCtl
IF oParent:IsKindOf( "TWinControl" )
FOR EACH oCtl IN oParent:aControls
Aadd( aControls, oCtl )
GetControls(oCtl, aControls)
NEXT
ENDIF
RETURN
"Stephan Hennekens" <
stephan.hennekens@wur.nl> wrote in message
news:[email=
46d02cb5@ozsrv2.ozlan.local...]
46d02cb5@ozsrv2.ozlan.local...[/email]
> Hi,
>
> I want to save (and restore) all values of all the controls on a form. I
> already know how to catch the controls objects (explained in a previous
> thread by Jose), but I need to know the names given by me to the controls.
> (Jose allready explainted how to catch the values). I tried with
> aControl:cVarName, but this raises an error. Strange, because cVarName is
> a property that is present in the object browser.
>
> Cheers,
> Stephan
>