Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi warum sehe ich public und published properties nicht? (https://www.delphipraxis.net/142325-warum-sehe-ich-public-und-published-properties-nicht.html)

iphi 26. Okt 2009 10:23


warum sehe ich public und published properties nicht?
 
Hallo,

Ich habe zum experimentieren ein Thread-Objekt wie folgt definiert:

Delphi-Quellcode:
unit UThreadCapture;

interface

...

type
  TCapture = class(TThread)
  private
    { Private declarations }
    s: string;
    ...
  protected
    ...
  public
    function test: boolean;
    ...
  published
    property ssss : string read s write s;
  end;

implementation
...
So weit so gut. Im Hauptprogramm möchte ich es nutzen:

Delphi-Quellcode:
var
  Capture: TThread;

...

Capture := TCapture.Create(true); //so weit so gut
Capture.test;              //kennt der Compiler nicht obwohl public!???? 
writeln(Capture.ssss);     //kennt der Compiler nicht obwohl published!????
Warum kann ich im Hauptprogramm nicht auf die public und published Methoden und Properties des Threadobjekts zugreifen? Was habe ich übersehen? Das müsste doch eigentlich so gehen. (Meine Frage zielt jetzt nicht auf Threadingsicherheit, sondern auf den Compiler).

Gruß, Thomas

Hudel1965 26. Okt 2009 10:25

Re: warum sehe ich public und published properties nicht?
 
Hallo :-)

definiere deine Variable vom Typ TCapture und nicht von TThread.

Gruß

Hudel

Mithrandir 26. Okt 2009 10:26

Re: warum sehe ich public und published properties nicht?
 
Zitat:

Zitat von iphi
Delphi-Quellcode:
var
  Capture: TThread;

Das soll wohl eher
Delphi-Quellcode:
var
  Capture: TCapture;
heißen, oder? :zwinker:

DeddyH 26. Okt 2009 10:27

Re: warum sehe ich public und published properties nicht?
 
Oder beim Zugriff auf TCapture casten, aber wer will das schon, wenn es nicht nötig ist?

Astartes 26. Okt 2009 10:32

Re: warum sehe ich public und published properties nicht?
 
Da war jmd schneller mit dem Casten =)

Delphi-Quellcode:
TCapture(Capture).test ....
Gruß, Tom

iphi 26. Okt 2009 11:30

Re: warum sehe ich public und published properties nicht?
 
Das war wirklich ne dumme Frage von mir. Beim Geschirrspülen kams mir jetzt auch.
Manchmal sieht man halt den Wald vor lauter Bäumen nicht...

Danke.

Muetze1 26. Okt 2009 12:23

Re: warum sehe ich public und published properties nicht?
 
Zitat:

Zitat von Astartes
Da war jmd schneller mit dem Casten =)

Delphi-Quellcode:
TCapture(Capture).test ....
Gruß, Tom

Das ist aber böse. Ein harter Cast wird nicht geprüft und ist damit eine große Fehlerquelle. Ein harter Cast sollte möglichst gar nicht und wenn mit bedacht und entsprechenden Sicherheitsabfragen verwendet werden. Es gibt bestimmt auch Situationen wo dies notwendig ist, aber dieses Beispiel gehört eindeutig nicht dazu!


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:07 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