Archive: Failing section access by index at runtime


Failing section access by index at runtime
Hello,

I am seeing a strange thing:

I have several sections built using macros, they have index {S1} to {S5}.
The sections have empty name and have the /o setting to make them disabled by default.
Then, within the onInit handler, I call the following function to work on the {Sn} indexed sections.

Function InitializeSections
${ForEach} $i 1 5 + 1
StrCpy $P_SectionIndex "S$i"

ClearErrors
SectionGetText {$P_SectionIndex} $P_SectionName
IfErrors 0 +2
MessageBox MB_OK "Error!"
MessageBox MB_OK "Section Name: $P_SectionName"

(... do something else on the section with {$P_SectionIndex} index)

${Next}
FunctionEnd


The problem is that the code seems to access the sections by sequence instead of by name.
The error message is never shown.
I thought I would be able to access sections using their index stored in a variable, but it doesn't seem to work.
If I try to retrieve the text when P_SectionName is "S1" I get the very first section of the whole project, "S2" gets the second and so on, in other words it seems only the numeric part of the index is used. Am I missing something or do indexes only work by numeric index?

Thanks,
Mario

http://forums.winamp.com/showpost.ph...79&postcount=4

I have several sections built using macros, they have index {S1} to {S5}.
No, they don't. It's ${S1} to ${S5}. Also these are defines containing 0 to 4 respectively.

If you want to enumerate sections, enumerate by index number (0...) and ignore those defines.

Edit: And I'll say this again (and again) you can't do...

!define SomeDefine1
StrCpy $0 1
!ifdef SomeDefine$0
!echo ${SomeDefine$0}
!endif


...which is effectively what you are trying to do. Defines are compile time constants and their values are evaluated on compile. Variables are run time and therefore you cannot use them in constant names. The names of constants do not exist after compile.

Stu

Yeah, it took a while but I think I got the concept now.

I used ${S1} to get the numeric index of the first section involved and I loop from there on.

Looks fine now.

Thanks a lot!

- Mario