Index: BasicCompiler32/Compile_Var.cpp
===================================================================
--- BasicCompiler32/Compile_Var.cpp	(revision 11)
+++ BasicCompiler32/Compile_Var.cpp	(revision 17)
@@ -157,5 +157,5 @@
 	return 1;
 }
-BOOL GetMemberOffset(bool ErrorEnabled,CClass *pobj_c,char *member,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpNestIndex,BOOL bPrivateAccess){
+BOOL GetMemberOffset(bool isErrorEnabled, bool isWriteAccess, CClass *pobj_c, char *member, int *pType, RELATIVE_VAR *pRelativeVar, LONG_PTR *plpNestIndex, BOOL bPrivateAccess){
 	int i,offset;
 
@@ -175,5 +175,5 @@
 	offset=GetSizeOfClassMember(pobj_c,VarName,&i);
 	if(i==pobj_c->iMemberNum){
-		if(ErrorEnabled) SetError(103,VarName,cp);
+		if(isErrorEnabled) SetError(103,VarName,cp);
 		return 0;
 	}
@@ -183,5 +183,5 @@
 		//同一クラスオブジェクトの場合はプライベートアクセスを容認する
 		if(pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){
-			if(ErrorEnabled) SetError(107,VarName,cp);
+			if(isErrorEnabled) SetError(107,VarName,cp);
 			return 0;
 		}
@@ -190,11 +190,21 @@
 		if((bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)||
 			pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){
-			if(ErrorEnabled) SetError(107,VarName,cp);
+			if(isErrorEnabled) SetError(107,VarName,cp);
 			return 0;
 		}
 		else if(bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PROTECTED){
-			if(ErrorEnabled) SetError(108,VarName,cp);
+			if(isErrorEnabled) SetError(108,VarName,cp);
 			return 0;
 		}
+	}
+
+	//Const定義の場合は書き込みアクセスを制限する
+	//※コンストラクタをコンパイル中の場合は例外的に許可する
+	if( pobj_c->ppobj_Member[i]->IsConst() &&		//定数メンバである
+		isWriteAccess &&							//書き込みアクセスを要求されている
+		pobj_c->IsCompilingConstructor() == false	//コンストラクタ コンパイル中を除く
+		){
+			//Const定義の変数に書き込みアクセスをしようとした場合
+			SetError(61,VarName,cp);
 	}
 
@@ -211,5 +221,5 @@
 	else{
 		if(lpPtrOffset[0]){
-			if(ErrorEnabled) SetError(16,member,cp);
+			if(isErrorEnabled) SetError(16,member,cp);
 			return 0;
 		}
@@ -227,5 +237,5 @@
 		//配列オフセット
 		if(!GetArrayOffset(pobj_c->ppobj_Member[i]->SubScripts,array,*pType,pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex))
-			if(ErrorEnabled) SetError(14,member,cp);
+			if(isErrorEnabled) SetError(14,member,cp);
 	}
 	else if(pobj_c->ppobj_Member[i]->SubScripts[0]!=-1){
@@ -238,5 +248,5 @@
 		if(*pType==DEF_OBJECT){
 			if(RefType!=DEF_OBJECT){
-				if(ErrorEnabled) SetError(104,member,cp);
+				if(isErrorEnabled) SetError(104,member,cp);
 				return 0;
 			}
@@ -248,5 +258,5 @@
 				//pObj[n].member
 				if(RefType!=DEF_OBJECT){
-					if(ErrorEnabled) SetError(104,member,cp);
+					if(isErrorEnabled) SetError(104,member,cp);
 					return 0;
 				}
@@ -261,5 +271,5 @@
 				//pObj->member
 				if(RefType!=DEF_PTR_OBJECT){
-					if(ErrorEnabled) SetError(104,member,cp);
+					if(isErrorEnabled) SetError(104,member,cp);
 					return 0;
 				}
@@ -287,5 +297,5 @@
 				//ppObj[n]->member
 				if(RefType!=DEF_PTR_OBJECT){
-					if(ErrorEnabled) SetError(104,member,cp);
+					if(isErrorEnabled) SetError(104,member,cp);
 					return 0;
 				}
@@ -302,10 +312,13 @@
 			}
 			else{
-				if(ErrorEnabled) SetError(104,member,cp);
+				if(isErrorEnabled) SetError(104,member,cp);
 				return 0;
 			}
 		}
 
-		if(!GetMemberOffset(ErrorEnabled,pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class,
+		if(!GetMemberOffset(
+			isErrorEnabled,
+			isWriteAccess,
+			pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class,
 			NestMember,
 			pType,
@@ -344,5 +357,5 @@
 }
 
-BOOL GetVarOffset(bool ErrorEnabled,bool WriteAccess,char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){
+BOOL GetVarOffset(bool isErrorEnabled, bool isWriteAccess, char *NameBuffer, int *pType, RELATIVE_VAR *pRelativeVar, LONG_PTR *plpIndex, int *pss){
 	extern BOOL bCompilingGlobal;
 	int i,RefType;
@@ -441,5 +454,12 @@
 
 		pRelativeVar->dwKind=VAR_DIRECTMEM;
-		if(!GetMemberOffset(ErrorEnabled,pobj_CompilingClass,variable,pType,pRelativeVar,&lpIndex,1)) return 0;
+		if(!GetMemberOffset(
+			isErrorEnabled,
+			isWriteAccess,
+			pobj_CompilingClass,
+			variable,
+			pType,
+			pRelativeVar,
+			&lpIndex,1)) return 0;
 		if(plpIndex) *plpIndex=lpIndex;
 		return 1;
@@ -513,5 +533,5 @@
 	}
 
-	if(ErrorEnabled) SetError(3,variable,cp);
+	if(isErrorEnabled) SetError(3,variable,cp);
 	pRelativeVar->dwKind=NON_VAR;
 	return 0;
@@ -547,5 +567,5 @@
 ok:
 
-	if(bConst && WriteAccess){
+	if(bConst && isWriteAccess){
 		//Const定義の変数に書き込みアクセスをしようとした場合
 		SetError(61,VarName,cp);
@@ -581,8 +601,4 @@
 				return 0;
 			}
-
-			LONG_PTR lp2;
-			if(!GetMemberOffset(ErrorEnabled,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
-			if(plpIndex) *plpIndex=lp2;
 		}
 		else if(*pType==DEF_PTR_OBJECT){
@@ -597,8 +613,4 @@
 				SetRelativeOffset(pType,lpIndex,pRelativeVar,lpPtrOffset);
 				pRelativeVar->dwKind=VAR_DIRECTMEM;
-
-				LONG_PTR lp2;
-				if(!GetMemberOffset(ErrorEnabled,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
-				if(plpIndex) *plpIndex=lp2;
 			}
 			else{
@@ -616,8 +628,4 @@
 				OpBuffer[obp++]=(char)0x8B;
 				OpBuffer[obp++]=(char)0x08;
-
-				LONG_PTR lp2;
-				if(!GetMemberOffset(ErrorEnabled,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
-				if(plpIndex) *plpIndex=lp2;
 			}
 		}
@@ -641,8 +649,4 @@
 				OpBuffer[obp++]=(char)0x8B;
 				OpBuffer[obp++]=(char)0x08;
-
-				LONG_PTR lp2;
-				if(!GetMemberOffset(ErrorEnabled,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
-				if(plpIndex) *plpIndex=lp2;
 			}
 			else{
@@ -657,4 +661,13 @@
 			return 0;
 		}
+
+		LONG_PTR lp2;
+		if(!GetMemberOffset(
+			isErrorEnabled,
+			isWriteAccess,
+			(CClass *)lpIndex,
+			member,pType,pRelativeVar,&lp2,0)) return 0;
+		if(plpIndex) *plpIndex=lp2;
+
 		return 1;
 	}
