컴파일러 지시자에 이것을 추가하세요
{$J+}
박태성 님이 쓰신 글 :
: 델마당에도 같은 질문을 올렸는데요. 여기도 다시 질문을 올려 봅니다.
:
:
http://www.angelfire.com/hi5/delphizeus/ 라는 싸이트에서 델파이로 API프로그래밍에 대해 공부중입니다.
: 아래는 소스는 15장에 나오는 코드의 일부분입니다.
:
: const
: FileID: Cardinal = $C2FAD1;
: ChunkSize: Cardinal = $200;
: Meg: Cardinal = $100000;
: ....
: ...
: procedure Split1Meg(hInFile: Cardinal; var OutFile, FileName: String);
: var
: hChopFile, Size1, ChopSize, BytesRead,
: BytesWrite, ReadSize, Total, numPieces, HeaderSize, i: Cardinal;
: NameLength: Word;
: BadFile: Bool;
: pMemBuf: Pointer;
: CreateTime: TFileTime;
:
: function tryWrite(var Source; Size: Cardinal; opPos: Integer): Bool;
: begin
: if WriteFile(hChopFile,Source,Size,BytesWrite,nil) and (BytesWrite = Size) then
: Result := False // Result is False for a Successful Write
: else
: begin
: Result := True;
: BadFile := True;
: SysErrorMsg(WriteErrText, WriteErrTitle+' '+Int2Str(opPos));
: end;
: end;
:
: begin
: ...
: GetMem(pMemBuf, ChunkSize);
: ...
: Total := HeaderSize; // Total will record the amount read from the source file
: ...
: if i = One then // only for the first piece, add a File header
: begin
: if tryWrite(FileID, SizeOf(FileID), -1) then Exit; <----- 에러나는 부분
: ...
: ...
: end;
:
: [Error] SplitFilesU.pas(373): Constant object cannot be passed as var parameter
: 컴파일해보면 위와 같은 에러가 납니다.
: 상수는 var 파라메터의 인수로 넣을수 없다는 말인것 같은데요
: 싸이트 저자가 테스트를 한후에 올린 코드일거라 생각되므로 정상적으로 컴파일 되는게 맞을것 같은데
: 제가 지금 사용하는 버전은 델파이7버전이고 저자가 사용한 델파이 버전은 뭔지는 잘모르겠네요
:
: 컴파일러 옵션으로 조정이 가능한건지 알고 싶네요
: 제가 어디서 얼핏 보기론 상수는 메모리번지를 가지지 않는다고 한걸 본것 같은데
: 그럼 var타입으로 넘긴다는게 메모리번지를 넘기는거므로 에러가 나는게 맞는것 같기도 하고
: 정확한 이유 좀 설명해 주실분 계신가요?