Forum > General

[closed] Code optimization and interfaces

(1/2) > >>

HuntingKashket:
Hello everyone, i am writing about very strange syntax flavor - optimization of interface-inherited classes:
when you're declaring a class derived from interface with interface-addressed functions, the compiler says about unused variables, which is really just used to pass a parameters to com or other outer object, which not met in the current source, e.g typelibrary, COM, OLE - objects/interfaces

Code from CEF4Delphi extension
Unit uCefInerfaces.pas

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// TCefBinaryValue  // /include/capi/cef_values_capi.h (cef_binary_value_t)  ICefBinaryValue = interface(ICefBaseRefCounted)    ['{974AA40A-9C5C-4726-81F0-9F0D46D7C5B3}']    function IsValid: Boolean;    function IsOwned: Boolean;    function IsSame(const that: ICefBinaryValue): Boolean;    function IsEqual(const that: ICefBinaryValue): Boolean;    function Copy: ICefBinaryValue;    function GetSize: NativeUInt;    function GetData(buffer: Pointer; bufferSize, dataOffset: NativeUInt): NativeUInt;     property Size  : NativeUInt   read GetSize;  end;   
Unit uCEFBinaryValue.pas

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TCefBinaryValueOwn = class(TCefBaseRefCountedOwn, ICefBinaryValue)    protected      function IsValid: Boolean;      function IsOwned: Boolean;      function IsSame(const that: ICefBinaryValue): Boolean;      function IsEqual(const that: ICefBinaryValue): Boolean;      function Copy: ICefBinaryValue;      function GetSize: NativeUInt;      function GetData(buffer: Pointer; bufferSize, dataOffset: NativeUInt): NativeUInt;     public      constructor Create;  end;    
I get hints or warnings about all of the interfaced functions with parameters, like that:
 <<Hint: %s1%(%d1%,%d2%): parameter "%s2" not used>>

Is something going to change in newer versions of lazarus/fpc?

ASerge:

--- Quote from: HuntingKashket on March 17, 2019, 11:09:26 am ---Hello everyone, i am writing about very strange syntax flavor - optimization of interface-inherited classes:

--- End quote ---
Like this?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$MODE OBJFPC} type  ITestInterface = interface(IInterface)    procedure Test(SomeParam: Integer);  end;   TTestClass = class(TInterfacedObject, ITestInterface)  private    procedure Test(SomeParam: Integer);  end; procedure TTestClass.Test(SomeParam: Integer);begin  // If SomeParam is not used, the compiler hints at this, but it is true  // for all cases, with or without an interfacesend; beginend.

HuntingKashket:

--- Quote from: ASerge on March 17, 2019, 11:34:07 am ---
--- Quote from: HuntingKashket on March 17, 2019, 11:09:26 am ---Hello everyone, i am writing about very strange syntax flavor - optimization of interface-inherited classes:

--- End quote ---
Like this?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$MODE OBJFPC} type  ITestInterface = interface(IInterface)    procedure Test(SomeParam: Integer);  end;   TTestClass = class(TInterfacedObject, ITestInterface)  private    procedure Test(SomeParam: Integer);  end; procedure TTestClass.Test(SomeParam: Integer);begin  // If SomeParam is not used, the compiler hints at this, but it is true  // for all cases, with or without an interfacesend; beginend.
--- End quote ---
No, because this interface is created not to export, but to import the function functions.
The original object with all of its functions is stored in libcef.dll, which is the target of COM-interface

In delphi it's ok for compiler to use object functions from library, in lazarus this code produces hints, idk, perhaps author just didn't implemented some interfaces for lazarus, so i questioned about that.

PascalDragon:

--- Quote from: HuntingKashket on March 17, 2019, 12:00:35 pm ---No, because this interface is created not to export, but to import the function functions.
The original object with all of its functions is stored in libcef.dll, which is the target of COM-interface

--- End quote ---

But then you don't need TCefBinaryValueOwn. You only need a class implementing an interface if you want to use that class to provide that interface. If you merely import then you don't need a class for that.


--- Quote from: HuntingKashket on March 17, 2019, 12:00:35 pm ---In delphi it's ok for compiler to use object functions from library, in lazarus this code produces hints, idk, perhaps author just didn't implemented some interfaces for lazarus, so i questioned about that.

--- End quote ---

I think Delphi does not have a hint/note for "parameter not used" at all. But FPC does and so it provides that accordingly for the methods of the class.

HuntingKashket:

--- Quote from: PascalDragon on March 18, 2019, 09:25:08 am ---
--- Quote from: HuntingKashket on March 17, 2019, 12:00:35 pm ---No, because this interface is created not to export, but to import the function functions.
The original object with all of its functions is stored in libcef.dll, which is the target of COM-interface

--- End quote ---

But then you don't need TCefBinaryValueOwn. You only need a class implementing an interface if you want to use that class to provide that interface. If you merely import then you don't need a class for that.


--- Quote from: HuntingKashket on March 17, 2019, 12:00:35 pm ---In delphi it's ok for compiler to use object functions from library, in lazarus this code produces hints, idk, perhaps author just didn't implemented some interfaces for lazarus, so i questioned about that.

--- End quote ---

I think Delphi does not have a hint/note for "parameter not used" at all. But FPC does and so it provides that accordingly for the methods of the class.

--- End quote ---
Delphi had it, otherwise i wouldn't mention that, so i am quite confused about warning, and i stay assume that it's just an fpc thing, which haven't been included in the wiki.

UPD: maybe dcc is poor in interfaces analyzing, i'm not sure about.

Navigation

[0] Message Index

[#] Next page

Go to full version