Ir al contenido


Foto

Problema con Interfaces en delphi 10.2


Mejor respuesta audiopesa , 05 abril 2022 - 03:25

Perfecto egostar, ya me compila.

Estaba mirando los metodos en activex de delphi7, que los han cambiado con respecto a delphi 10.2 y me estaba liando.

 

Gracias

Ir al mensaje completo


  • Por favor identifícate para responder
6 respuestas en este tema

#1 audiopesa

audiopesa

    Member

  • Miembros
  • PipPip
  • 11 mensajes

Escrito 05 abril 2022 - 05:58

Hola como están;

 

Estoy intentancompilar esta unidad en delphi 10.2 y no compila, sin embargo en delphi 7 si funciona


delphi
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7. Dialogs,ActiveX;
  8.  
  9. type
  10. TForm1 = class(TForm)
  11. private
  12. { Private declarations }
  13. public
  14. { Public declarations }
  15. end;
  16.  
  17.  
  18.  
  19.  
  20. TStreamOwnership = (soReference, soOwned);
  21.  
  22. TStreamAdapter = class(TInterfacedObject, IStream)
  23. private
  24. FStream: TStream;
  25. FOwnership: TStreamOwnership;
  26. public
  27. constructor Create(Stream: TStream; Ownership: TStreamOwnership = soReference);
  28. destructor Destroy; override;
  29. function Read(pv: Pointer; cb: Longint;
  30. pcbRead: PLongint): HResult; virtual; stdcall;
  31. function Write(pv: Pointer; cb: Longint;
  32. pcbWritten: PLongint): HResult; virtual; stdcall;
  33. function Seek(dlibMove: Largeint; dwOrigin: Longint;
  34. out libNewPosition: Largeint): HResult; virtual; stdcall;
  35. function SetSize(libNewSize: Largeint): HResult; virtual; stdcall;
  36. function CopyTo(stm: IStream; cb: Largeint; out cbRead: Largeint;
  37. out cbWritten: Largeint): HResult; virtual; stdcall;
  38. function Commit(grfCommitFlags: Longint): HResult; virtual; stdcall;
  39. function Revert: HResult; virtual; stdcall;
  40. function LockRegion(libOffset: Largeint; cb: Largeint;
  41. dwLockType: Longint): HResult; virtual; stdcall;
  42. function UnlockRegion(libOffset: Largeint; cb: Largeint;
  43. dwLockType: Longint): HResult; virtual; stdcall;
  44. function Stat(out statstg: TStatStg;
  45. grfStatFlag: Longint): HResult; virtual; stdcall;
  46. function Clone(out stm: IStream): HResult; virtual; stdcall;
  47. property Stream: TStream read FStream;
  48. property StreamOwnership: TStreamOwnership read FOwnership write FOwnership;
  49. end;
  50. var
  51. Form1: TForm1;
  52.  
  53. implementation
  54.  
  55. {$R *.dfm}
  56. constructor TStreamAdapter.Create(Stream: TStream;
  57. Ownership: TStreamOwnership);
  58. begin
  59. inherited Create;
  60. FStream := Stream;
  61. FOwnership := Ownership;
  62. end;
  63.  
  64. destructor TStreamAdapter.Destroy;
  65. begin
  66. if FOwnership = soOwned then
  67. begin
  68. FStream.Free;
  69. FStream := nil;
  70. end;
  71. inherited Destroy;
  72. end;
  73.  
  74. function TStreamAdapter.Read(pv: Pointer; cb: Longint; pcbRead: PLongint): HResult;
  75. var
  76. NumRead: Longint;
  77. begin
  78. try
  79. if pv = Nil then
  80. begin
  81. Result := STG_E_INVALIDPOINTER;
  82. Exit;
  83. end;
  84. NumRead := FStream.Read(pv^, cb);
  85. if pcbRead <> Nil then pcbRead^ := NumRead;
  86. Result := S_OK;
  87. except
  88. Result := S_FALSE;
  89. end;
  90. end;
  91.  
  92. function TStreamAdapter.Write(pv: Pointer; cb: Longint; pcbWritten: PLongint): HResult;
  93. var
  94. NumWritten: Longint;
  95. begin
  96. try
  97. if pv = Nil then
  98. begin
  99. Result := STG_E_INVALIDPOINTER;
  100. Exit;
  101. end;
  102. NumWritten := FStream.Write(pv^, cb);
  103. if pcbWritten <> Nil then pcbWritten^ := NumWritten;
  104. Result := S_OK;
  105. except
  106. Result := STG_E_CANTSAVE;
  107. end;
  108. end;
  109.  
  110. function TStreamAdapter.Seek(dlibMove: Largeint; dwOrigin: Longint;
  111. out libNewPosition: Largeint): HResult;
  112. var
  113. NewPos: LargeInt;
  114. begin
  115. try
  116. if (dwOrigin < STREAM_SEEK_SET) or (dwOrigin > STREAM_SEEK_END) then
  117. begin
  118. Result := STG_E_INVALIDFUNCTION;
  119. Exit;
  120. end;
  121. NewPos := FStream.Seek(dlibMove, dwOrigin);
  122. if @libNewPosition <> nil then libNewPosition := NewPos;
  123. Result := S_OK;
  124. except
  125. Result := STG_E_INVALIDPOINTER;
  126. end;
  127. end;
  128.  
  129. function TStreamAdapter.SetSize(libNewSize: Largeint): HResult;
  130. begin
  131. try
  132. FStream.Size := libNewSize;
  133. if libNewSize <> FStream.Size then
  134. Result := E_FAIL
  135. else
  136. Result := S_OK;
  137. except
  138. Result := E_UNEXPECTED;
  139. end;
  140. end;
  141.  
  142. function TStreamAdapter.CopyTo(stm: IStream; cb: Largeint; out cbRead: Largeint;
  143. out cbWritten: Largeint): HResult;
  144. const
  145. MaxBufSize = 1024 * 1024; // 1mb
  146. var
  147. Buffer: Pointer;
  148. BufSize, N, I, R: Integer;
  149. BytesRead, BytesWritten, W: LargeInt;
  150. begin
  151. Result := S_OK;
  152. BytesRead := 0;
  153. BytesWritten := 0;
  154. try
  155. if cb > MaxBufSize then
  156. BufSize := MaxBufSize
  157. else
  158. BufSize := Integer(cb);
  159. GetMem(Buffer, BufSize);
  160. try
  161. while cb > 0 do
  162. begin
  163. if cb > MaxInt then
  164. I := MaxInt
  165. else
  166. I := cb;
  167. while I > 0 do
  168. begin
  169. if I > BufSize then N := BufSize else N := I;
  170. R := FStream.Read(Buffer^, N);
  171. if R = 0 then Exit; // The end of the stream was hit.
  172. Inc(BytesRead, R);
  173. W := 0;
  174. Result := stm.Write(Buffer, R, @W);
  175. Inc(BytesWritten, W);
  176. if (Result = S_OK) and (Integer(W) <> R) then Result := E_FAIL;
  177. if Result <> S_OK then Exit;
  178. Dec(I, R);
  179. Dec(cb, R);
  180. end;
  181. end;
  182. finally
  183. FreeMem(Buffer);
  184. if (@cbWritten <> nil) then cbWritten := BytesWritten;
  185. if (@cbRead <> nil) then cbRead := BytesRead;
  186. end;
  187. except
  188. Result := E_UNEXPECTED;
  189. end;
  190. end;
  191.  
  192. function TStreamAdapter.Commit(grfCommitFlags: Longint): HResult;
  193. begin
  194. Result := S_OK;
  195. end;
  196.  
  197. function TStreamAdapter.Revert: HResult;
  198. begin
  199. Result := STG_E_REVERTED;
  200. end;
  201.  
  202. function TStreamAdapter.LockRegion(libOffset: Largeint; cb: Largeint;
  203. dwLockType: Longint): HResult;
  204. begin
  205. Result := STG_E_INVALIDFUNCTION;
  206. end;
  207.  
  208. function TStreamAdapter.UnlockRegion(libOffset: Largeint; cb: Largeint;
  209. dwLockType: Longint): HResult;
  210. begin
  211. Result := STG_E_INVALIDFUNCTION;
  212. end;
  213.  
  214. function TStreamAdapter.Stat(out statstg: TStatStg; grfStatFlag: Longint): HResult;
  215. begin
  216. Result := S_OK;
  217. try
  218. if (@statstg <> nil) then
  219. with statstg do
  220. begin
  221. dwType := STGTY_STREAM;
  222. cbSize := FStream.Size;
  223. mTime.dwLowDateTime := 0;
  224. mTime.dwHighDateTime := 0;
  225. cTime.dwLowDateTime := 0;
  226. cTime.dwHighDateTime := 0;
  227. aTime.dwLowDateTime := 0;
  228. aTime.dwHighDateTime := 0;
  229. grfLocksSupported := LOCK_WRITE;
  230. end;
  231. except
  232. Result := E_UNEXPECTED;
  233. end;
  234. end;
  235.  
  236. function TStreamAdapter.Clone(out stm: IStream): HResult;
  237. begin
  238. Result := E_NOTIMPL;
  239. end;
  240. end.

los errores que me salen son:

 

[dcc32 Error] Unit1.pas(22): E2291 Missing implementation of interface method IStream.Seek
[dcc32 Error] Unit1.pas(22): E2291 Missing implementation of interface method IStream.SetSize
[dcc32 Error] Unit1.pas(22): E2291 Missing implementation of interface method IStream.CopyTo
[dcc32 Error] Unit1.pas(22): E2291 Missing implementation of interface method IStream.Commit
[dcc32 Error] Unit1.pas(22): E2291 Missing implementation of interface method IStream.LockRegion
[dcc32 Error] Unit1.pas(22): E2291 Missing implementation of interface method IStream.UnlockRegion
[dcc32 Error] Unit1.pas(22): E2291 Missing implementation of interface method IStream.Stat
[dcc32 Error] Unit1.pas(22): E2291 Missing implementation of interface method ISequentialStream.Read
[dcc32 Error] Unit1.pas(22): E2291 Missing implementation of interface method ISequentialStream.Write

 

me dice que no estoy implementando los metodos pero si que están

 

alguna idea?

 


  • 0

#2 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 05 abril 2022 - 11:16

Hola Audiopesa, bienvenido a DelphiAccess
 
El problema es que la definición de los parámetros son diferentes, necesitas asegurar que tengan los mismos valores,
 
Por ejemplo el método Seek() tiene las siguientes diferencias 

 


delphi
  1.     function Seek(dlibMove: Largeint; dwOrigin: Longint; out libNewPosition: Largeint): HResult; virtual; stdcall;
  2.     function Seek(dlibMove: Largeint; dwOrigin: DWORD; out libNewPosition: LargeUInt): HResult; stdcall;

 
 
Saludos


  • 0

#3 audiopesa

audiopesa

    Member

  • Miembros
  • PipPip
  • 11 mensajes

Escrito 05 abril 2022 - 02:40

Gracias por responder egostar.

 

esta definición de donde sale..


delphi
  1. function Seek(dlibMove: Largeint; dwOrigin: DWORD; out libNewPosition: LargeUInt): HResult; stdcall;

 


  • 0

#4 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 05 abril 2022 - 02:59

 

Gracias por responder egostar.

 

esta definición de donde sale..


delphi
  1. function Seek(dlibMove: Largeint; dwOrigin: DWORD; out libNewPosition: LargeUInt): HResult; stdcall;

 

Hola audiopesa

 

De la unidad Winapi.ActiveX que es donde se localiza la interfaz IStream.

 

post-12129-0-29937900-1649192254.png

 

Saludos

Archivos adjuntos


  • 0

#5 audiopesa

audiopesa

    Member

  • Miembros
  • PipPip
  • 11 mensajes

Escrito 05 abril 2022 - 03:25   Mejor respuesta

Perfecto egostar, ya me compila.

Estaba mirando los metodos en activex de delphi7, que los han cambiado con respecto a delphi 10.2 y me estaba liando.

 

Gracias


  • 1

#6 audiopesa

audiopesa

    Member

  • Miembros
  • PipPip
  • 11 mensajes

Escrito 05 abril 2022 - 03:33

Perfecto Egostar, ya me compila.

Me estaba liando con los metodos de delphi 7, que son diferentes a delphi 10.2

 

Gracias, un saludo.


  • 1

#7 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 05 abril 2022 - 03:35

Que bien, marcamos como resuelto el hilo.

 

Saludos


  • 0




IP.Board spam blocked by CleanTalk.