Forum > Beginners

Compiling - setting component properties

(1/1)

Int3g3r:
Hello

I would like to change several properties of a component before compiling.
Is there a way to do this?

For example:
I have set the property "Connected" to Enabled for programming in the TZConnection.

Is it possible to set the property "Connected" to Disabled with a compiler directive or something like that?

I want my compiled program to have this value set to Disabled by default.

When I try to change this in the "DataModuleCreate" there are always problems.

This doesnt work (project.lpr):

--- 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";}};} ---{$R *.res} begin  RequireDerivedFormResource:=True;  Application.Scaled:=True;  Application.Initialize;  // Disabe DB Connection at Startup  dmMain.dbConnn.Connected:= false;  dmMain.dbConnn.LibraryLocation:= '';  Application.CreateForm(TdmMain, dmMain);  Application.CreateForm(TformMain, formMain);  Application.Run;end.
I found a solution, i just override the constructor:

--- 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";}};} ---constructor TdmMain.Create(AOwner: TComponent);begin  inherited Create(AOwner);  // Disable DB Connection at Startup  dmMain.dbConnn.Connected:= false;  dmMain.dbConnn.LibraryLocation:= '';end;  

Regards Int3g3r

cdbc:
Hi

--- Quote ---I have set the property "Connected" to Enabled for programming in the TZConnection.
--- End quote ---
DO NOT compile with that property = "True"!!!!!
The datamodule probably tries to connect in the constructor, which you can't easily get at....
If it doesn't, you can try to override the "TDataModule.AfterConstruct" and set it there...

--- 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";}};} ---{$R *.res} begin  RequireDerivedFormResource:=True;  Application.Scaled:=True;  Application.Initialize;  Application.CreateForm(TdmMain, dmMain); //<--- create///// if applicable, then HERE after it has been created /////  // Disabe DB Connection at Startup  dmMain.dbConnn.Connected:= false;  dmMain.dbConnn.LibraryLocation:= '';  Application.CreateForm(TformMain, formMain);  Application.Run;end.HTH
Regards Benny

Int3g3r:

--- Quote from: cdbc on May 14, 2024, 04:14:54 pm ---Hi

--- Quote ---I have set the property "Connected" to Enabled for programming in the TZConnection.
--- End quote ---
override the "TDataModule.AfterConstruct" and set it there...
HTH
Regards Benny

--- End quote ---

That doesn't work...

"OnCreate" is called before the "AfterConstruction" event.
I have just tested this.

In the "OnCreate" event, the DLL and database are created the first time it is executed.
The "connected" property must therefore be set to false beforehand.

If I overwrite the constructor it works.
The constructor is called before the OnCreate event.

Navigation

[0] Message Index

Go to full version