Einzelnen Beitrag anzeigen

Benutzerbild von negaH
negaH

Registriert seit: 25. Jun 2003
Ort: Thüringen
2.950 Beiträge
 
#2

Re: Unbegrenzt viele Nachkommastellen

  Alt 23. Okt 2004, 03:20
Ich verstehe dich jetzt nicht so richtig.

Die Methode .SetName(const Name: String); solltest du prozedurale mal so betrachten:

procedure SetName(Self: PMyRecord; const Name: String); stdcall; Self zeigt also auf deinen Record der ja sozusagen als TObject Ersatz dient. D.h. wenn du die VMT vin deinem Interface deklarierst so müsste diese so aussehen:

Delphi-Quellcode:
type
  PMyRecord = ^TMyRecord;
  TMyRecord = packed record
    VMT: PMyVMT;
    RefCount: Integer;
    Name: String;
  end;

  PMyVMT = ^TMyVMT;
  TMyVMT = packed record
    _QueryInterface: function(Self: PMyRecord; var Obj; const IID: TGUID): HResult; stdcall;
    _AddRef: function(Self: PMyRecord): HResult; sdtcall;
    _Release: function(Self: PMyRecord): HResult; sdtcall;
    GetName: function(Self: PMyRecord): String; stdcall;
    SetName: procedure(Self: PMyRecord; const Name: String); stdcall;
    GetRefCount: function(Self:PMyRecord): Integer; stdcall;
  end;

function MyQueryInterface(Self: PMyRecord; var Obj; const IID: TGUID): HResult; stdcall;
begin
  Result := S_ERROR;
end;

function MyAddref(Self: PMyRecord): HResult; stdcall;
begin
  InterlockedIncrement(Self.RefCount);
  Result := Self.RefCount;
end;

function MyRelease(Self: PMyRecord): HResult; stdcall;
begin
  InterlockedDecrement(Self.RefCount);
  Result := Self.RefCount;
  if Result = 0 then Dispose(Self);
end;

function MyGetName(Self: PMyRecord): String; stdcall;
begin
  Result := Self.Name;
end;

procedure MySetName(Self: PMyRecord; const Name: String); stdcall;
begin
  Self.Name := Name;
end;

function MyGetRefCount(Self: PMyRecord): Integer; stdcall;
begin
  Result := Self.RefCount;
end;

const
  VMT: TVMT = (
    _QueryInterface: MyQueryInterface;
    _AddRef: MyAddRef;
    _Release: MyRelease;
    GetName: MyGetName;
    SetName: MySetName;
    GetRefCount: MyGetRefCount;
);


function Alloc: IMyInterface;
var
  MyRecord: PMyRecord;
begin
  New(MyRecord);
  MyRecord.VMT := @VMT;
  Result := IInterface(MyRecord);
end;
Ohne Gewähr, ist alles aus dem Kopf

Gruß Hagen
  Mit Zitat antworten Zitat