[Gambas-user] Using Character constants in Gambas

vikram austinium at ...43...
Tue Mar 8 08:09:23 CET 2011


Hi,

I am working on an application in which I reuse the same dialog for performing different tasks. I have a PUBLIC INTEGER variable(named dialogType) in the dialog's .class file. When creating instances of this dialog I set the DialogInstance.dialogType to the value(0,1,2,...) which indicates the purpose of the dialog. The value of DialogInstance.dialogType is used within the dialog to decide what to do with the user input.

I am using numeric values to indicate the dialog type. This isn't very elegant. I am looking for the Gambas equivalent of doing a #define CHARCONST value in C.

I have tried using a Collection.

DIM DialogType AS NEW Collection
DialogType["SomeType0"] = 0
DialogType["SomeType1"] = 1
DialogType["SomeType2"] = 2
DialogType["SomeType3"] = 3
DialogType["SomeType4"] = 4

I am thinking of placing the collection's definition in a Module and then using it to replace the numeric constants:
DIM DialogInstance as DialogName
DialogInstance = NEW DialogName
DialogInstance.dialogType = ModuleName.DialogType["SomeType0"]
'current code
'DialogInstance.dialogType = 0

Is there a better way of using character constants in Gambas?

Gambas 2.21/Debian 6

Thanks,
Vikram Nair



      


More information about the User mailing list