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;
:
: 이렇게 해 보았는데 에러가 나네요.
: 정상적인 방법이 아니라고 합니다.
|