Forum > FPC development

'treat private like protected'

<< < (2/6) > >>

SymbolicFrank:

--- Quote from: Zvoni on October 26, 2022, 03:19:05 pm ---?

--- 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;
--- End quote ---

That gives an 'invalid type cast' runtime error. I'm not sure, but I was under the impression that if you introduce a field with the same name of an inaccessible one, it creates a new field. But it's hard to find the documentation for that.


--- Quote ---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.... 
--- End quote ---

Well, yes, but I cannot access FProxy, so far. The above code generates the 'not related' or 'invalid typecast' error, depending.


--- Quote ---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;
--- End quote ---

Ok, I'll try that as soon as I can set those OpenFlags.

But it's possible I don't understand what I'm doing.

SymbolicFrank:

--- Quote from: Martin_fr on October 26, 2022, 03:24:24 pm ---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 ...)

--- End quote ---

Or, a hack like the above ones isn't going to keep on working, if I can get it functioning at all.

Back to the drawing board.

Zvoni:
This compiles

--- 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";}};} ---program Project1;Uses Sysutils, Classes, sqldb, sqlite3conn; Type   { TMyConnector }  TMyConnector = Class(TSQLConnector)    Protected      FProxy:TSQLConnection;  end;   { TMyHelper }   TMyHelper = Class helper for TMyConnector    Public      Procedure SetOpenFlags;  end; { TMyHelper } Procedure DoSomethingElse;BeginEnd; procedure TMyHelper.SetOpenFlags;begin  If ConnectorType='SQLite3' Then    TSQLite3Connection(FProxy).OpenFlags:=[sofReadWrite, sofCreate, sofFullMutex, sofSharedCache];  If ConnectorType='MySQL' Then DoSomethingElse;end;   beginend. 

SymbolicFrank:
It does :)

But it gives the error below:

Tomorrow I'll look further.

ASerge:

--- Quote from: SymbolicFrank on October 26, 2022, 01:12:41 pm ---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.

--- End quote ---
May be

--- 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";}};} ---uses SQLDB, SQLite3Conn; type  TSpecialConnector = class(TSQLConnector)  protected    procedure CreateProxy; override;  end; procedure TSpecialConnector.CreateProxy;begin  inherited;  if Proxy is TSQLite3Connection then    TSQLite3Connection(Proxy).OpenFlags := [sofReadWrite, sofCreate, sofFullMutex, sofSharedCache];end;

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version