[fpc-devel] LocalReferenceFixup

José Mejuto joshyfun at gmail.com
Fri Oct 8 11:16:44 CEST 2010


Hello FPC,

Friday, October 8, 2010, 8:35:44 AM, you wrote:

>> Aha. In MSEgui application.createform()/createdatamodule() must be called in
>> order to allow component linking with already loaded modules, t*form.create()
>> is not enough. I don't know how this works in Lazarus.
MG> In Lazarus both use the same loading mechanism. Referenced
MG> datamodules are automatically found if they already exist.
MG> The main difference is that CreateForm sets the variable (e.g.
MG> Form1) before it creates and loads the form, while
MG> Form1:=TForm1.Create(nil) sets Form1 after creation and loading.
MG> It is up to the programmer to create the forms and datamodules in the
MG> right order. If you have circle dependencies, follow Martin's advice
MG> and enclose the creation of datamodule and forms in
MG> Begin/Notify/EndGlobalLoading.

I'm not aware about any cycle dependency, but I'm not completly sure
as I do not know which kind of dependency (from the technical point of
view I think) you are talking about, so I'll explain a layuot to try
to narrow the source of the problem (my design or library design):

I have a very simple application, 2 forms and 1 datamodule. The first
form is a simple "select your option" which will load all forms on
demand. When this main form is loaded the datamodule is being created
also, but not the second form.

Datamodule
----------
In datamodule I have 1 firebird connection and 1 firebird transaction.
The connection is at design time linked with the transaction via
property and proper connect data is filled in.

Secondary form
--------------
It have a simple SQLQuery, linked with the firebird connection in the
datamodule. Transaction property is automagically filled with the
firebird connection transaction. The "Active" property is set to true
and at design time if I drop a grid I can see that data is being
retrieved.

Relationship
------------

  Main    Second form      Datamodule
+------+  +----------+    +---------------+
|      |  | SQLQuery |+---> SQLConnection --+
|Button-->|        | ||   |               | |
+------+  +--------+--+---> Transaction <---+
                          +---------------+

Creation order
--------------
1) Create main form
2) Create data module
3) Wait in main form for user input
4) Create second form

I had put some writeln in the source code at the property sets of
active and database of SQLQuery and the expected sequece is:

------
qryGroupClientsWatch set active to: -1
qryGroupClientsWatch set to database
qryGroupClientsWatch set active to: -1
------

First line receives the "Active:=true", but as csLoading is present it
sets a flag to activate after complete loading, second line sets the
database property and the third line should came from the "Loaded"
event which checks the flag and if not csLoading is present try to
open the dataset. This layout must work.

But the layout that I receive is:

------
qryGroupClientsWatch set active to: -1
qryGroupClientsWatch set active to: -1
------

First line is the "Active:=true", as csLoading is present the activate
is delayed. The reader reads the database property, as it is a tkClass
it add it to LocalReferenceFixups and do not set the property (so no
call to property set), and them the "Loaded" event is fired and as
csLoading is not present it tries to open the dataset raising the
"database not set" exception.

I hope I had explained it in detail.

-- 
Best regards,
 José




More information about the fpc-devel mailing list