Recent

Author Topic: [SOLVED] Access Violation  (Read 2384 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1709
Re: Access Violation
« Reply #15 on: November 14, 2025, 02:45:05 am »
How is FrmClientsMgt created? It is not created automatically.

Thausand

  • Sr. Member
  • ****
  • Posts: 437
Re: Access Violation
« Reply #16 on: November 14, 2025, 03:22:23 am »
Why a DataModule???
Manual https://www.freepascal.org/docs-html/rtl/classes/tdatamodule.html

Quote
TDataModule is a container for non-visual objects which can be used in an IDE to group non-visual objects which can be used by various other containers (forms) in a project. Notably, data access components are typically stored on a datamodule. Web components and services can also be implemented as descendants of datamodules.

TDataModule introduces some events which make it easier to program, and provides the needed streaming capabilities for persistent storage.

An IDE will typically allow to create a descendant of TDataModule which contains non-visual components in it's published property list.
That is short why  :)

Then have think. Why have form make clutter with non-visual component ? When use datamodule then have group database function for one location. That important for more easy for maintain. When have database components for form then have multiple form then when want change for database then have visit and change all form (unit code/component property).

Use datamodule not have mandator but have convenient. Can make convenient when use normal unit. When have database then is no require visual component. Visual database component is same when datamodule and is convenient.

Thausand

  • Sr. Member
  • ****
  • Posts: 437
Re: Access Violation
« Reply #17 on: November 14, 2025, 03:33:07 am »
Hi, I see i one thing that can produce issue: the data module is created BEFORE the main form.
Someone more experimented than me can say if it is ?
I no expert. but have sense logic :)

Answer is depend. When want database setup before form show and form have property connect then form most have depend database then datamodule first, form after. When form is make open database and connect runtime then is form first then have datamodule.

It can have complicate many things when user make use many event connection when develop. Example: when have event formshow and then have code for query database then database is first setup, after then form. There many event both form and database. So when event depend when database or form available then have impact order creation.

So I have personal think that create database visual and have set event properties IDE is no good for understand how is impact form and database. Is happen many time that user have violation access (and why have no idea because have not learn how is work this impact)

Handoko

  • Hero Member
  • *****
  • Posts: 5505
  • My goal: build my own game engine using Lazarus
Re: Access Violation
« Reply #18 on: November 14, 2025, 04:31:59 am »
So I have personal think that create database visual and have set event properties IDE is no good for understand how is impact form and database.
Me too avoid setting events for database visual components. In the past I like the idea of database visual components, setting the AfterInsert, AfterDelete events, etc. At the beginning that seemed good, but it became harder to understand the flow. Now, I put all the database related code into a single unit. Functions and procedures are all called by code not events. I separate properly the database and UI parts. The code now becomes easier to follow, extend and debug.

Thaddy

  • Hero Member
  • *****
  • Posts: 18475
  • Here stood a man who saw the Elbe and jumped it.
Re: Access Violation
« Reply #19 on: November 14, 2025, 06:23:59 am »
I totally agree with that. This week, I happened to stumble into some code I wrote in the 1996/7/8 era with Delphi 1 and 2:
OMG what a mess. Can't believe I got any money for that! I must have been so into that code that nobody else could make any sense of it and that includes me after 28 odd years. It was around then that we decided all the database stuff should be done in code, not through the screendrawing properties. Things got better when the actionlist and actions were introduced and we introduced the rule that we only write IDE's based on actions, never direct. That code, from the early 2000's looks a lot better!
But as with any programming it takes some discipline, but makes a team and yourself a lot more productive.
The 1996/7 code shows its age: hey Delphi is great, we need to do everything visually. NOT. It happened to be a false promise in many ways.
Things like Datamodules and Action lists were the onset of better programming when combined.
Writing more in code helps a lot regarding quality and maintenance.
After all, a good program is usually not the userinterface, although it is part of its usefulness.
Many should un-learn user interface centric programming, a.k.a. screen drawing, because it is plain wrong.
Wrong in the sense that perfectly good tools are used in the wrong way.

All this because I found an USB floppy drive in the attick along with some floppies that were not deceased yet..
Now all I need is an USB ide interface for my BigFoots to be able to see what other damage I have caused in the past... :P
<shiver>

(D2 was distributed on around 20! floppies)
« Last Edit: November 14, 2025, 06:41:33 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 407
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Access Violation
« Reply #20 on: November 16, 2025, 04:48:40 pm »
Yup, I finally figured out most of all my issues.  When I first started on this project, I had all the Queries defined on the DataModule and then changed my designed and just had the Queries for just the lookup tables, i.e. States/Provinces, Countries, etc. on the DM and moved my Queries for the main units/forms to their forms/units, i.e. Appointments, Clients, ContactsMgt., etc.  Just discovered that all the Query-Field declarations were left in the DM-interface section, i.e. QryAppmts: TSQLQuery, QryAppmtsACTIVE:TBooleanField;, etc.  So, those queries were deleted and moved to their own units and all this was left behind but when I compiled, it didn't catch these left behind.  So, decided to move everything back like before and the Clients. Appointments, ContactsMgt forms just have DataSouces components on their forms pointing back to their Queries. But just working with just the Appointments form which now just has DataSource components on the form for all the DBEdits, DBNav, DBGrid, etc.  I can code for example:
Code: Pascal  [Select][+][-]
  1. DSrcAppmts.DataSet:= PMSDataModule.QryAppmts;
  2. DSrcCntks.DataSet:= PMSDataModule.QryCntks;
  3. etc.
  4.  

But, the actual Appointment form DataSource component can't see the DataModule.  I can assign in code but if I click on the DataSource on the form and attempt to assign the DataSet property, the dropdown doesn't reveal the DataModule Queries.  I have the datamodule in the USES in the InterFace so tried defining a USES DM in the implementation but Lazarus doesn't see the DM???????

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 407
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Access Violation
« Reply #21 on: November 17, 2025, 11:09:54 pm »
Figured this out, had to learn a bit about inline I guess, use of procedures since all database everything is now in the DataModule.  So, an AfterInsert or AfterDelete in a unit that's using the DataModule learned this and works:

Code: Pascal  [Select][+][-]
  1. QryPropsls.AfterInsert:= @PMSDataModule.QryPropslsAfterInsert;
  2. QryPropsls.AfterDelete:= @PMSDataModule.QryPropslsAfterDelete;
  3.  

That's all folks, thanks for all the education!

Thausand

  • Sr. Member
  • ****
  • Posts: 437
Re: [SOLVED] Access Violation
« Reply #22 on: November 17, 2025, 11:29:25 pm »
What write Thaddy is good example why I think is better for make setup and have use write code.

When have old project and use visual property setting then I no know or have remember what property is set. This special true for database.

When make setup when use code then can
- see what is code do
- have code line comment for explain what code is do

I have make many waste time when work for project that have many coder because I have make watch all property and see what is set and connect.

All person that work on project make change personal and have make time for detection what is change to make fix problem I have work for.

Visual develop is concept but when have example many database and have team work then is no practible.

This personal think. It no wrong when have different practice. For me is simple no practible. When example have problem and post problem on forum and not show all property (or have database same) then how can see or tell what wrong ? I have see this write happen many time on forum and I think  is waste many time.

Thank Thaddy for example and good explain.

 

TinyPortal © 2005-2018