Index: BasicCompiler64/Compile_Var.cpp
===================================================================
--- BasicCompiler64/Compile_Var.cpp	(revision 9)
+++ BasicCompiler64/Compile_Var.cpp	(revision 11)
@@ -179,5 +179,5 @@
 	return 1;
 }
-BOOL GetMemberOffset(BOOL bError,CClass *pobj_c,char *member,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpNestIndex,BOOL bPrivateAccess){
+BOOL GetMemberOffset(bool ErrorEnabled,CClass *pobj_c,char *member,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpNestIndex,BOOL bPrivateAccess){
 	int i,offset;
 
@@ -202,5 +202,5 @@
 	offset=GetSizeOfClassMember(pobj_c,VarName,&i);
 	if(i==pobj_c->iMemberNum){
-		if(bError) SetError(103,VarName,cp);
+		if(ErrorEnabled) SetError(103,VarName,cp);
 		return 0;
 	}
@@ -211,5 +211,5 @@
 		//同一クラスオブジェクトの場合はプライベートアクセスを容認する
 		if(pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){
-			if(bError) SetError(107,VarName,cp);
+			if(ErrorEnabled) SetError(107,VarName,cp);
 			return 0;
 		}
@@ -218,9 +218,9 @@
 		if((bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PRIVATE)||
 			pobj_c->ppobj_Member[i]->dwAccess==ACCESS_NON){
-			if(bError) SetError(107,VarName,cp);
+			if(ErrorEnabled) SetError(107,VarName,cp);
 			return 0;
 		}
 		else if(bPrivateAccess==0&&pobj_c->ppobj_Member[i]->dwAccess==ACCESS_PROTECTED){
-			if(bError) SetError(108,VarName,cp);
+			if(ErrorEnabled) SetError(108,VarName,cp);
 			return 0;
 		}
@@ -239,5 +239,5 @@
 	else{
 		if(lpPtrOffset[0]){
-			if(bError) SetError(16,member,cp);
+			if(ErrorEnabled) SetError(16,member,cp);
 			return 0;
 		}
@@ -256,5 +256,5 @@
 		//配列オフセット
 		if(!GetArrayOffset(pobj_c->ppobj_Member[i]->SubScripts,array,*pType,pobj_c->ppobj_Member[i]->TypeInfo.u.lpIndex)){
-			if(bError) SetError(14,member,cp);
+			if(ErrorEnabled) SetError(14,member,cp);
 		}
 	}
@@ -268,5 +268,5 @@
 		if(*pType==DEF_OBJECT){
 			if(RefType!=DEF_OBJECT){
-				if(bError) SetError(104,member,cp);
+				if(ErrorEnabled) SetError(104,member,cp);
 				return 0;
 			}
@@ -278,5 +278,5 @@
 				//pObj[n].member
 				if(RefType!=DEF_OBJECT){
-					if(bError) SetError(104,member,cp);
+					if(ErrorEnabled) SetError(104,member,cp);
 					return 0;
 				}
@@ -291,5 +291,5 @@
 				//pObj->member
 				if(RefType!=DEF_PTR_OBJECT){
-					if(bError) SetError(104,member,cp);
+					if(ErrorEnabled) SetError(104,member,cp);
 					return 0;
 				}
@@ -315,5 +315,5 @@
 				//ppObj[n]->member
 				if(RefType!=DEF_PTR_OBJECT){
-					if(bError) SetError(104,member,cp);
+					if(ErrorEnabled) SetError(104,member,cp);
 					return 0;
 				}
@@ -329,10 +329,10 @@
 			}
 			else{
-				if(bError) SetError(104,member,cp);
+				if(ErrorEnabled) SetError(104,member,cp);
 				return 0;
 			}
 		}
 
-		if(!GetMemberOffset(bError,
+		if(!GetMemberOffset(ErrorEnabled,
 			pobj_c->ppobj_Member[i]->TypeInfo.u.pobj_Class,
 			NestMember,
@@ -371,5 +371,5 @@
 	SetReg_WholeVariable(DEF_PTR_VOID,&RelativeVar,reg);
 }
-BOOL GetVarOffset(BOOL bError,char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){
+BOOL GetVarOffset(bool ErrorEnabled,bool WriteAccess,char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss){
 	extern BOOL bCompilingGlobal;
 	int i,RefType;
@@ -387,4 +387,5 @@
 	LONG_PTR lpIndex;
 	int *pSubScripts;
+	bool bConst = false;
 
 
@@ -423,4 +424,5 @@
 			if(plpIndex) *plpIndex=lpIndex;
 			pSubScripts=LocalVar[i].SubScripts;
+			bConst = LocalVar[i].bConst;
 
 			goto ok;
@@ -463,5 +465,5 @@
 
 		pRelativeVar->dwKind=VAR_DIRECTMEM;
-		if(!GetMemberOffset(bError,pobj_CompilingClass,variable,pType,pRelativeVar,&lpIndex,1)) return 0;
+		if(!GetMemberOffset(ErrorEnabled,pobj_CompilingClass,variable,pType,pRelativeVar,&lpIndex,1)) return 0;
 		if(plpIndex) *plpIndex=lpIndex;
 		return 1;
@@ -534,5 +536,5 @@
 	}
 
-	if(bError) SetError(3,variable,cp);
+	if(ErrorEnabled) SetError(3,variable,cp);
 	pRelativeVar->dwKind=NON_VAR;
 	return 0;
@@ -563,4 +565,5 @@
 	if(plpIndex) *plpIndex=lpIndex;
 	pSubScripts=GlobalVar[i].SubScripts;
+	bConst = GlobalVar[i].bConst;
 
 
@@ -568,4 +571,8 @@
 ok:
 
+	if(bConst && WriteAccess){
+		//Const定義の変数に書き込みアクセスをしようとした場合
+		SetError(61,VarName,cp);
+	}
 
 	if(array[0]==0&&pSubScripts[0]!=-1){
@@ -600,5 +607,5 @@
 
 			LONG_PTR lp2;
-			if(!GetMemberOffset(bError,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
+			if(!GetMemberOffset(ErrorEnabled,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
 			if(plpIndex) *plpIndex=lp2;
 		}
@@ -616,5 +623,5 @@
 
 				LONG_PTR lp2;
-				if(!GetMemberOffset(bError,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
+				if(!GetMemberOffset(ErrorEnabled,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
 				if(plpIndex) *plpIndex=lp2;
 			}
@@ -634,5 +641,5 @@
 
 				LONG_PTR lp2;
-				if(!GetMemberOffset(bError,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
+				if(!GetMemberOffset(ErrorEnabled,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
 				if(plpIndex) *plpIndex=lp2;
 			}
@@ -658,5 +665,5 @@
 
 				LONG_PTR lp2;
-				if(!GetMemberOffset(bError,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
+				if(!GetMemberOffset(ErrorEnabled,(CClass *)lpIndex,member,pType,pRelativeVar,&lp2,0)) return 0;
 				if(plpIndex) *plpIndex=lp2;
 			}
@@ -1109,6 +1116,6 @@
 			lstrcpy(pVar->name,VarName);
 			pVar->fRef=0;
-			if(dwFlag & DIMFLAG_CONST) pVar->bConst = 1;
-			else pVar->bConst = 0;
+			if(dwFlag & DIMFLAG_CONST) pVar->bConst = true;
+			else pVar->bConst = false;
 			if(SubScripts[0]==-1) pVar->bArray=0;
 			else pVar->bArray=1;
@@ -1124,4 +1131,8 @@
 
 			if(InitBuf[0]){
+				//初期代入時のみ、書き込みアクセスを許可する
+				bool bConstBack = pVar->bConst;
+				pVar->bConst = false;
+
 				int result = InitLocalVar(-pVar->offset,
 					pVar->type,
@@ -1136,4 +1147,6 @@
 					OpcodeCalc(temporary);
 				}
+
+				pVar->bConst = bConstBack;
 			}
 			else{
