2009-06-25 4 views
0

난 C#으로 이하의 방법이있다 :delphi 2009/2010에서 C# Generics를 사용하는 방법?

public T Read<T>() 
    { 
     T[] t = new T[1]; 

     int s = Marshal.SizeOf(typeof(T)); 
     if (index + s > size) 
      throw new Exception("Error 101 Celebrity"); 

     GCHandle handle = GCHandle.Alloc(t, GCHandleType.Pinned); 
     Marshal.Copy(dataRead, index, handle.AddrOfPinnedObject(), s); 

     index += s; 

     return t[0]; 
    } 

dataRead는 바이트 [] 배열이다. 인덱스 및 크기는 정수 유형입니다.

이 함수는 dataRead (byte [])에서 유형을 읽고 색인 (index + = type)을 증가시킵니다.

인터넷을 통해 "델파이 범용 제품"이라고 할 때 - 내가 필요한 것은 Trecords와 클래스입니다.

어떻게 델파이에서 코드를 만들 수 있습니까?

답변

4
function TReader.Read <T>: T; 
begin 
    if FIndex + SizeOf (T) > Length (FDataRead) then 
    raise Exception.Create ('Error 101 Celebrity'); 
    Move (FDataRead[FIndex], Result, SizeOf (T)); 
    Inc (FIndex, SizeOf (T)); 
end; 
관련 문제