Jump to content


Photo

GetItemByName()


  • Please log in to reply
7 replies to this topic

#1 Markus

Markus
  • Members
  • 54 posts

Posted 06 October 2006 - 06:04 PM

Hi,

could somebody please give me a possible use case for GetItemByName()? I suspect the function doesn't exactly do what it's supposed to do.

Markus
It compiles, ship it!

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 06 October 2006 - 07:58 PM

Hello,

This property return Item with specified name. Example:

CODE
NextInspector1.Items.ItemByName['testitem'].Caption := 'BorderWidth';


I hope that this help,

Regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 Markus

Markus
  • Members
  • 54 posts

Posted 09 October 2006 - 10:39 AM

QUOTE (Boki (Berg) @ Oct 6 2006, 08:58 PM) <{POST_SNAPBACK}>
CODE
NextInspector1.Items.ItemByName['testitem'].Caption := 'BorderWidth';


Ok, I see. In this case the function works as expected. rolleyes.gif

Markus
It compiles, ship it!

#4 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 03 December 2006 - 08:30 PM

Hi Boki,

QUOTE (Markus @ Oct 9 2006, 10:39 AM) <{POST_SNAPBACK}>
Ok, I see. In this case the function works as expected. rolleyes.gif
Markus


Is it an idea & possible to make this function case insensitive or would that break to much existing code?

Another request is to add a Name parameter to the AddChild call so you can compact code like:

CODE
NextInspector1.AddChild(TNxTextItem, 'Voornaam', 'VoornaamItem'). AsString := Klanten[ndx].Voornaam;


and

CODE
voornaam:=NextInspector1.Items.ItemByName['VoornaamItem'].AsString;

G.W. van der Vegt

#5 Markus

Markus
  • Members
  • 54 posts

Posted 04 December 2006 - 03:23 PM

Hi Wim,

QUOTE (wvd_vegt @ Dec 3 2006, 08:30 PM) <{POST_SNAPBACK}>
Is it an idea & possible to make this function case insensitive or would that break to much existing code?


Why would you want to make this function case-insensitive? This property is very useful when dealing with items at runtime, i.e. creating and destroying them at runtime. Considering this use-case there's one problem: You can assign the same string to multiple name properties. Therefore I'm against making this function case-insensitive as this would allow more redundant name property choices.

QUOTE (wvd_vegt @ Dec 3 2006, 08:30 PM) <{POST_SNAPBACK}>
Another request is to add a Name parameter to the AddChild call so you can compact code like:

CODE
NextInspector1.AddChild(TNxTextItem, 'Voornaam', 'VoornaamItem'). AsString := Klanten[ndx].Voornaam;


and
CODE
voornaam:=NextInspector1.Items.ItemByName['VoornaamItem'].AsString;


Yeah, I'm in favor of this change. Just define AddChild as this

CODE
function AddChild(ItemClass: TNxItemClass; S: string = ''; Name: String = ''): TNxPropertyItem;


and you're still compatible with one's old code.

Cheers,
Markus
It compiles, ship it!

#6 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 04 December 2006 - 09:43 PM

Hi Markus,

QUOTE (Markus @ Dec 4 2006, 03:23 PM) <{POST_SNAPBACK}>
Hi Wim,
Why would you want to make this function case-insensitive? This property is very useful when dealing with items at runtime, i.e. creating and destroying them at runtime. Considering this use-case there's one problem: You can assign the same string to multiple name properties. Therefore I'm against making this function case-insensitive as this would allow more redundant name property choices.

Markus


Good point, BUT as you cannot have two objects shareing the same name, Delphi is case in-sensitive there (and the function works on the Name property of the item only as I discovered) it would not matter at all (or am I wrong here?). It would be different if the GetItemByName function where to act on the Caption property.

If it would be as you describe, I totally agree it's a bad move.
G.W. van der Vegt

#7 Markus

Markus
  • Members
  • 54 posts

Posted 05 December 2006 - 12:26 PM

Hi Wim,

QUOTE (wvd_vegt @ Dec 4 2006, 09:43 PM) <{POST_SNAPBACK}>
Delphi is case in-sensitive there (and the function works on the Name property of the item only as I discovered) it would not matter at all (or am I wrong here?).


No, you're right. I was wrong in my assumption that you can assign the same name to multiple controls at run-time! Just tested that and it turned out that this results in an exception. Sorry for the fuss.

So, after all, I'm +1 on making the function case-insensitive. biggrin.gif

Cheers,
Markus
It compiles, ship it!

#8 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 05 December 2006 - 10:59 PM

Hi Markus,

QUOTE (Markus @ Dec 5 2006, 12:26 PM) <{POST_SNAPBACK}>
Hi Wim,
No, you're right. I was wrong in my assumption that you can assign the same name to multiple controls at run-time! Just tested that and it turned out that this results in an exception. Sorry for the fuss.

So, after all, I'm +1 on making the function case-insensitive. biggrin.gif

Markus


Actually you can AS long as the controls reside on different forms. But that would automatically mean a different NextInspector too.
G.W. van der Vegt




2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users