Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[11829] Re:클래스에서 선언한 배열을 함수에서 동적으로 할당하는 방법은 있나요?
civilian [civilian] 1537 읽음    2008-03-14 16:06
type
  TTest = class
  public
    count: integer;
    data: array of byte;

    constructor Create;
    destructor Destroy; override;
    procedure TestData(Kind: Pointer; count: integer);
  end;

procedure TForm1.Button1Click(Sender: TObject);
var
  ATest: TTest;
begin
  ATest := TTest.Create;
  ATest.TestData(nil, 10);
  ATest.Free;
end;

{ Test }

constructor TTest.Create;
begin

end;

destructor TTest.Destroy;
begin

  inherited;
end;

procedure TTest.TestData(Kind: Pointer; count: integer);
begin
  SetLength(Data, count);
end;

이렇게 하니 잘되는데요?


leo21c 님이 쓰신 글 :
: c++ builder만 사용하다가 예전 소스가 파스칼 언어로 되어 있어서
: 그 부분에 data를 처리하려고 하는데 처리 방법을 몰라서 이렇게 글 올립니다.
:
: 함수에서
: var
:  data: Array of Byte
: begin
:  SetLength(data, 5);
: end;
:
: 이렇게 하면 에러가 발생하지 않습니다.
: 그런데 class에서 선언을 하고 아래와 같이 함수에서 SetLength()를 하면
: 에러가 발생합니다.
: 원래 이렇게 동적으로 사용할수 없는 건가요?
: 다른 방법이 있다면 어떤 방법이 있는지 알고 싶습니다.
:
: 처음은 C++로 만든 것입니다.
: class Test
: {
: public:
:   int count;
:   BYTE* data;

:  __fastcall Test();
:  __fastcall ~Test();
:
: void TestData(void* Kind, int count);
: }
:
: void Test::TestData(void* Kind, int count)
: {
:   data = new BYTE(count);
: }
:
: 이 소스를 델파이로 바꾸려고 합니다.
:
: Test = class
: public
:   count: integer;
:   data: array of byte;
:  
:   construct Create;
:   destructor Destroy; override;
:   precedure TestData(Kind: Pointer, count: integer);
: end;
:
: 이렇게 바꾸는게 맞는지 모르겠습니다.
:
: precedure TestData(Kind: Pointer, count: integer);
: begin
:   SetLength(data, count);
: end;
:
: 이렇게 해 보았는데 에러가 나네요.
: 정상적인 방법이 아니라고 합니다.

+ -

관련 글 리스트
11828 클래스에서 선언한 배열을 함수에서 동적으로 할당하는 방법은 있나요? leo21c 1477 2008/03/14
11829     Re:클래스에서 선언한 배열을 함수에서 동적으로 할당하는 방법은 있나요? civilian 1537 2008/03/14
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.