Circular referencing

Circular referencing

Question:
Circular referencing

Answer:
This tip addresses circular referencing between units; that is, where two units are dependent upon each other in some way. Or in more simple terms: two or more forms need to interact with each other at runtime. For those in the know, you’d probably say, “That’s not allowed!” That’s right, it’s not allowed at the public or interface level. But it is allowed at the private or implementation level.

The reason for this is that units declared in the uses clause of an implementation section are not seen by the defining unit; that is, at compile time they aren’t referenced for compilation. So if you move one or both of the uses declarations to the implementation section, you can perform circular referencing.

As an example, let’s say I have a form called Form1. It opens up another form called Form2. For simplicity’s sake, let’s say that once Form2 opens, it changes the Caption property of a TLabel on Form1 that says it’s up and ready. It’s a pretty simple one-liner:

procedure TForm2.FormCreate(Sender: TObject);begin  Form1.Label1.Caption := ‘I”m up and running!’;end;

This was possible because I declared Unit1 (associated code for Form1) in the uses section in the implementation section of Unit2.

implementationuses Unit1;{$R *.DFM}…rest of the code

Form2 came into existence because a procedure in Form1 created it. So under the implementation section of Unit1, I made a similar uses declaration to Unit2’s uses, but declared Unit2 instead of Unit1. Having done this, Unit2 now can now access Unit1’s public methods and functions and vice-versa.

Admittedly, this topic is fairly old hat to most people. But those just starting to program in Delphi will find this invaluable when they need to have their forms interact with each other.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes