Forum > FPC development

'treat private like protected'

(1/6) > >>

SymbolicFrank:
Can we get an option for that? So we can fix bugs and extend the functionality of existing classes, without having to modify the FPC source code and make a merge request?

As an example, I want to expand the TSQLConnector to pass the TSQLite3Connection.OpenFlags. But the encapsulated TSQLConnection object (FProxy) is private, so that's a no-go.

marcov:
http://talkdelphi.blogspot.com/2009/04/how-to-hack-into-delphi-class.html

SymbolicFrank:
Interesting. But I'm probably doing it wrong:


--- 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";}};} ---type  TSpecialConnector = class(TSQLConnector)  protected    procedure DoInternalConnect; override;  end;   TConnectionAccessor = class  public    FProxy: TSQLite3Connection;  end; implementation procedure TSpecialConnector.DoInternalConnect;begin  if ConnectorType = 'SQLite3' then    TConnectionAccessor(Self).FProxy.OpenFlags :=      [sofReadWrite, sofCreate, sofFullMutex, sofSharedCache];  inherited DoInternalConnect;end;
This gives the compile error:


--- Code: ---tablefunctions.pas(1473,5) Error: Class or Object types "TSpecialConnector" and "TConnectionAccessor" are not related
--- End code ---

Zvoni:
?

--- 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";}};} ---TConnectionAccessor = class(TSpecialConnector)  public    FProxy: TSQLite3Connection;  end;
EDIT: Related to your other thread:
Have you tried by checking the ConnectionDef of the FProxy?
FProxy is a TSQLConnection, but you could try casting it
AIRCODE

--- 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";}};} ---procedure TSpecialConnector.DoInternalConnect;begin  if ConnectorType = 'SQLite3' then    TSQLite3Connection(Self).FProxy.OpenFlags :=      [sofReadWrite, sofCreate, sofFullMutex, sofSharedCache];  inherited DoInternalConnect;//blablabla.... and i was under the impression one should call the inherited Method first in this case...

--- 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";}};} ---procedure TSQLConnector.DoInternalConnect; Var  D : TConnectionDef; begin  inherited DoInternalConnect;  CheckProxy;  FProxy.CharSet:=Self.CharSet;  FProxy.DatabaseName:=Self.DatabaseName;

Martin_fr:
Also keep in mind: https://wiki.freepascal.org/FPC_New_Features_3.0.0#Class_field_reordering


--- Quote ---Since the internal memory layout of a class is opaque
--- End quote ---
In other words, whatever works now (with current FPC versions), it may stop work with any upcoming FPC version. (By either this, or by other optimizations / even by changes that aren't optimizations).


--- Quote ---this optimization may be moved to level -O2
--- End quote ---
While FPC 3.0.0 only does this in -O4, it is already announced to come to -O2 (and we are past 3.0.0 ...)

Navigation

[0] Message Index

[#] Next page

Go to full version