AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

TComboBox and string object

Ein Thema von WojTec · begonnen am 14. Feb 2012 · letzter Beitrag vom 15. Feb 2012
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

TComboBox and string object

  Alt 14. Feb 2012, 13:53
Delphi-Version: 2010
Add with function():

AStrings.AddObject(Name, TObject(string(Path))) ;

Test in OnChange:

ShowMessage(string(cbList.Items.Objects[cbList.ItemIndex]));

First ShowMessage() is showing path and then raises EInvalidPointer. How to fix it?
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.679 Beiträge
 
Delphi 2007 Enterprise
 
#2

AW: TComboBox and string object

  Alt 14. Feb 2012, 14:14
The most direct way: Use a global variable for your string. But that can still end up in all sorts of messes because of the compiler magic strings come with. Especially fun stuff like copy-on-write related things.
(Edit, to be clear: Do NOT do this! It may work in some special and simple cases, but is dirty like whatnot.)

A more sensible way: Define a TStringList in a suitable scope, and put the index of your desired string from that list into your Object-Property. To read it, just use that index on your StringList. You'll save yourself a lot of potential trouble that way
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)

Geändert von Medium (14. Feb 2012 um 14:16 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.537 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: TComboBox and string object

  Alt 14. Feb 2012, 14:20
Or simply use a real TObject containing a string property
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.115 Beiträge
 
Delphi 12 Athens
 
#4

AW: TComboBox and string object

  Alt 14. Feb 2012, 14:57
Do not cast string, dyn. array oder interfaces.

This bypasses the reference count.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#5

Re: TComboBox and string object

  Alt 15. Feb 2012, 11:05
Thanks, I created class for this purpose
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:55 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz