Author Topic: Dynamic referencing of TEdit.Name  (Read 589 times)

J-G

  • Hero Member
  • *****
  • Posts: 1300
Re: Dynamic referencing of TEdit.Name
« Reply #15 on: September 02, 2026, 02:36:02 am »
Yes, you and me are not a fan of screen drawing development, that is clear ;)
Programming in code is usually a way around that paradigm.
If I understand you correctly @Thaddy,  it seems that I am quite opposite in my aproach. I probably spend as much time creating the visual aspect of any project as I do coding. Witness the attached screen grabs where most of the components are TImages with bitmaps designed in CorelDRAW and/or PhotoShop.

I've spent that past two days resizing the main 'Book' which is why I'm two days late responding.

I've also made time to look properly at your suggestion on how to create an array of TEdits. (Reply #5) Although I've sorted the original reason for my question, there is another aspect of the project that needs potentially 12 sets of 4 pieces of Data, for which the Strings will be assembled in an 2D array but will ultimately need to be transfered to the TLabels. This data will not be [Entered] at this juncture but will be gleaned from existing database entries, so TEdit won't be needed.

I say 'potentially' 12 sets  -  these will be the names etc. of a Family's 'Issue'. Going back only two generations it was common for families to have 8/9/10 offspring - My mother was youngest of 11 so I'm adding an extra one for good measure!

As I said before I think that I get the principles involved but there are many aspects that are completely new to me. For instance : 'Specialize Tarray<Tedit>', 'AControl.Controls[ i ]'.

I can easily see that 'FormCreate' might better be called 'ArrayCreate' and I suspect that
var
  edt:TEdit;
is a typo.

Tomorrow (Ooops - later today!) I'll copy the code into a separate project and try to get a better understanding - and maybe adjust the number and type.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Thaddy

  • Hero Member
  • *****
  • Posts: 19805
  • Glad to be alive.
Re: Dynamic referencing of TEdit.Name
« Reply #16 on: September 02, 2026, 05:39:05 am »
The art work looks great!
Any "programmer" that knows only one programming language is not a programmer

Zvoni

  • Hero Member
  • *****
  • Posts: 3532
Re: Dynamic referencing of TEdit.Name
« Reply #17 on: September 02, 2026, 08:10:23 am »
Agree with Thaddy: Artwork is great.

re Array of TEdits: I like Thaddy's approach with the Generics Array. Clean and concise.
The thing making me to rethink it: Is the order of the TEdits in the Forms-Control-Collection the same as the TabOrder of the TEdits?

How do you know, that MyEdits[3] is the TEdit for the Mother's Name?

Do you always want to check some Property to find out, which TEdit it actually is?
Code: Pascal  [Select][+][-]
  1.   If MyEdits[2].Name='Father' Then //..........
  2.   If MyEdits[6].Tag=17 Then IamTheDaughter //or whichever other property you want too use to identify

What i like about the non-generic approach.
You can do stuff like this:

AIRCODE
Code: Pascal  [Select][+][-]
  1. Type
  2.   TMyFamily=(mfPaternalGrandFather, mfPaternalGrandmother, mfMaternalGrandfather, mfMaternalGrandmother, mfFather, mfMother, mfSon, mfDaughter);
  3.  
  4. Var
  5.   MyEdits:Array[TMyFamily] Of TEdits;
  6.  
  7. Procedure TMyForm.FormCreate(Sender:TObject);
  8. Begin
  9.    MyEdits[mfPaternalGrandFather]:=edtPaternalGrandFather;  //Properly named TEdits !!!!
  10.    //And so on.....
  11. End;

That way it doesn't matter, in what order the TEdits are on the Form, which TabOrder they have or what ever else

Downside of course: You're bound to a static amount of Controls.
No Dynamics
« Last Edit: September 02, 2026, 08:15:35 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

J-G

  • Hero Member
  • *****
  • Posts: 1300
Re: Dynamic referencing of TEdit.Name
« Reply #18 on: September 02, 2026, 10:16:12 am »
@Thaddy
@Zvoni

Thanks for you kind comments  -  I've been 'in' Graphic Design for some time 😂   -   [EDIT] hmmmm! I've just 'viewed' the attachments and regretably see that the low res demanded by the 500k restriction on attachment size means that they are not as clear as I would like  😞  No matter, they have served their purpose.

The aspect that you raise, @Zvoni, is a non starter. In this instance, the 'List' is only of the 'Offspring' from a Union and, naturally, will be in Birth Date order. It will also only be a 'display' - not a data entry.  On the screen grab B you will see 3 entries under [Issue], that list could grow to 12 and I've already calculated the changing positions of the TLabel.top depending upon the total needed and being æsthetically pleasing. The start and finish are not constant (for all numbers of offspring) so they will probably be declared in a const array (as a 'start' and an 'increment') which will be used at run-time to position the TLabels.   

I am of course assuming that once the array of TLabel components is created, their Position and Visibility can be adjusted via code, but I'm about to start the serious  business of creating a test project so should find out a little more before breakfast  ;D

« Last Edit: September 02, 2026, 10:30:55 am by J-G »
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Zvoni

  • Hero Member
  • *****
  • Posts: 3532
Re: Dynamic referencing of TEdit.Name
« Reply #19 on: September 02, 2026, 10:23:40 am »
@Thaddy
@Zvoni

Thanks for you kind comments  -  I've been 'in' Graphic Design for some time 😂

The aspect that you raise, @Zvoni, is a non starter. In this instance, the 'List' is only of the 'Offspring' from a Union and, naturally, will be in Birth Date order. It will also only be a 'display' - not a data entry.  On the screen grab B you will see 3 entries under [Issue], that list could grow to 12 and I've already calculated the changing positions of the TLabel.top depending upon the total needed and being æsthetically pleasing. The start and finish are not constant (for all numbers of offspring) so they will probably be declared in a const array (as a 'start' and an 'increment') which will be used at run-time to position the TLabels.   

I am of course assuming that once the array of TLabel components is created, their Position and Visibility can be adjusted via code, but I'm about to start the serious  business of creating a test project so should find out a little more before breakfast  ;D

Ah, yes.
In that case a static array makes no sense.

And yes: You can adjust Position and any other writable Properties of the TLabel by accessing the Array
Aircode
Code: Pascal  [Select][+][-]
  1. //.................
  2. //Increase Array
  3. SetLength(MyLabels, Length(MyLabels)+1);
  4. //Add new TLabel to Array
  5. MyLabels[High(MyLabels)]:=TLabel.Create(Self);  
  6. //Calculate position Top and Left
  7. //Set up everything
  8. MyLabels[High(MyLabels)].Top:=NewTop;
  9. MyLabels[High(MyLabels)].Left:=NewLeft;
  10. MyLabels[High(MyLabels)].Caption:=NewChildName;
  11. MyLabels[High(MyLabels)].Visible:=True;
Note: This is for a NON-Generic Array!
as in:
Code: Pascal  [Select][+][-]
  1. Var  MyLabels:Array of TLabel;
No Idea how to increase Array-Length for a "generic" Array as shown in Thaddy's example.
Never worked with it

Quote
On the screen grab B you will see 3 entries under [Issue], that list could grow to 12 and I've
12 Kids?
Dear Lord.........  :P :P :P
« Last Edit: September 02, 2026, 10:52:40 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

J-G

  • Hero Member
  • *****
  • Posts: 1300
Re: Dynamic referencing of TEdit.Name
« Reply #20 on: September 02, 2026, 11:26:22 am »
12 Kids?
Dear Lord.........  :P :P :P
As in the animal kingdom the number of offspring is determined/affected by the Infant Mortality rate - as well as availability of contraception of course  ;)

Even in the early 1900's about 15% of children didn't survive past age 1  -  today that is <4%  -  hence there were large families and I anticipate going back to at least 1800 - eventually, maybe further.  When I looked into my mother's side a few years ago I got some 'sketchy' info back to the 1300's.

The world record for child-birth is 69!!! (67 survived infancy) and the father later re-married and had a further 18 with his second wife !!
« Last Edit: September 02, 2026, 01:54:25 pm by J-G »
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Zvoni

  • Hero Member
  • *****
  • Posts: 3532
Re: Dynamic referencing of TEdit.Name
« Reply #21 on: September 02, 2026, 11:30:48 am »
The world record for child-birth is 69!!! (67 survived infancy) and the father later re-married and had a further 18 with his second wife !!

Talk about having no hobbies whatsoever.....
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

J-G

  • Hero Member
  • *****
  • Posts: 1300
Re: Dynamic referencing of TEdit.Name
« Reply #22 on: September 02, 2026, 01:19:40 pm »
Well, eventually a productive morning - - -  I looked at @Thaddy's code (post #5) and although I can see a potential I was unable (through my lack of knowledge) to create a working program. I did get the code to compile but failed to 'step through' to get an understanding.

After ~ 8/10 attempts I gave up and looked at the suggestion from @tetrastes (Post #12) which I can fully understand and 'manipulate'  -  I changed the TEdit to a TLabel, the Array[1..4] to Array[1..12,1..4]  and could create as many (or as few) elements as needed;  plus various other manipulations, which you can see in the attached 'Published Project'.

The 'concept' I think is proven, now I have to incorporate it into the real project - - - but that will be after breakfast!


 
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

 

TinyPortal © 2005-2018