AGB  ·  Datenschutz  ·  Impressum  







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

Problem mit Property

Ein Thema von sebi87 · begonnen am 23. Apr 2008 · letzter Beitrag vom 23. Apr 2008
Antwort Antwort
Seite 1 von 2  1 2      
sebi87
(Gast)

n/a Beiträge
 
#1

Problem mit Property

  Alt 23. Apr 2008, 08:41
Hallo Leute ich hab volgenden Quellcode:

Delphi-Quellcode:
unit Ball;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls;

type
  TMyPoint = class(TPersistent)
  Private
    fx, fy : integer ;
  Published
    constructor Create ;
    property x: integer read fx write fx;
    property y: integer read fy write fy;
  end;

  TBall= class(TComponent)
  private
    FMittelpunkt : TPoint ;
    BMittelpunkt : TMyPoint ;
    FImage : TImage ;
    FFont : TFont ;
    { Private-Deklarationen }
  protected
    { Protected-Deklarationen }
  public
    constructor Create(AOwner : TComponent) ;
    destructor Destroy ;
    procedure GetPoint(Y : integer) ;
    { Public-Deklarationen }
  published
    property MittelpunktLeft : integer read FMittelpunkt.x write FMittelpunkt.x ;
    property MittelpunktHight : integer read FMittelpunkt.y write FMittelpunkt.y ;
    property Mittelpunkt : TMyPoint read BMittelpunkt write BMittelpunkt ;
    property PaintPlane : TImage read FImage write FImage ;
    property Font: TFont read FFont write FFont;
    { Published-Deklarationen }
  end;

procedure Register;

implementation

constructor TMyPoint.Create ;
begin
  fy := 0 ;
  fx := 0 ;
end ;

procedure Register;
begin
  RegisterComponents('Kugel', [TBall]);
end;


constructor TBall.Create(AOwner: TComponent);
begin
  inherited Create(AOwner) ;
  BMittelpunkt := TMyPoint.Create ;
  FMittelpunkt.y := 0 ;
  PaintPlane := nil ;
  FFont := TFont.Create;
end;

destructor TBall.Destroy ;
begin
  BMittelpunkt.Free ;
  FFont.Free ;
  inherited Destroy ;
end ;

procedure TBall.GetPoint(Y : integer) ;
begin
  FMittelpunkt.y := Y ;
end ;

end.
Wenn ich jetzt im OI auf die property Font zugreifen will erscheint jedes mal die Fehlermeldung
Zitat:
Zugriffsverletzung bei Adresse 400039709 in Modul 'Vcl40.bpl'. Lesen von Adresse 00000000
Wie kann ich das beheben?

Sebastian
  Mit Zitat antworten Zitat
Benutzerbild von Bernhard Geyer
Bernhard Geyer

Registriert seit: 13. Aug 2002
17.171 Beiträge
 
Delphi 10.4 Sydney
 
#2

Re: Problem mit Property

  Alt 23. Apr 2008, 09:07
Für ein Property das ein Objekt darstellt brauchst du eine Setter-Methode.

Delphi-Quellcode:
procedure TBall.SetFont(AFont: TFont);
begin
  FFont.Assign(AFont);
end;
Windows Vista - Eine neue Erfahrung in Fehlern.
  Mit Zitat antworten Zitat
sebi87
(Gast)

n/a Beiträge
 
#3

Re: Problem mit Property

  Alt 23. Apr 2008, 14:28
ich hab die Set-Procedure jetzt wie folgt eingebaut
Delphi-Quellcode:
property Font: TFont read FFont write SetFont;

procedure TBall.SetFont(AFont : TFont) ;
begin
  FFont.Assign(AFont) ;
end ;
es erscheint dennoch der gleiche Fehler.

Was mache ich falsch
  Mit Zitat antworten Zitat
guidok

Registriert seit: 28. Jun 2007
417 Beiträge
 
#4

Re: Problem mit Property

  Alt 23. Apr 2008, 14:40
Ich schätze mal du musst im constructor erst mal eine Instanz von TFont erzeugen FFont := TFont.Create;
Im destructor dann natürlich wieder entfernen.
  Mit Zitat antworten Zitat
sebi87
(Gast)

n/a Beiträge
 
#5

Re: Problem mit Property

  Alt 23. Apr 2008, 16:18
muss ich deine Schätzung leider wiederlegen, denn wenn du den Quelltext angesehen hast müsstest du gesehen haben das ich das gemscht habe, wenn ich es falsch gemacht habe dann ok.
Ich weiß einfach nicht warum das so nicht funktioniert
  Mit Zitat antworten Zitat
sebi87
(Gast)

n/a Beiträge
 
#6

Re: Problem mit Property

  Alt 23. Apr 2008, 20:23
Kann mir hier niemand weiterhelfen?
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

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

Re: Problem mit Property

  Alt 23. Apr 2008, 20:24
Poste doch mal den kompletten Code, falls er nicht zu umfangreich ist.
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 Bernhard Geyer
Bernhard Geyer

Registriert seit: 13. Aug 2002
17.171 Beiträge
 
Delphi 10.4 Sydney
 
#8

Re: Problem mit Property

  Alt 23. Apr 2008, 20:24
Zitat von sebi87:
Kann mir hier niemand weiterhelfen?
Schau mal in deiner Delphi4-VCL-Source nach wie es dort gemacht wird.
Windows Vista - Eine neue Erfahrung in Fehlern.
  Mit Zitat antworten Zitat
sebi87
(Gast)

n/a Beiträge
 
#9

Re: Problem mit Property

  Alt 23. Apr 2008, 20:30
Ist momentan noch nicht mehr Code wie oben zu sehen, ich versuch im Moment aus einem Objekt eine Komponente zu basteln und hab mich jetzt mal an die Propertys gewagt, aber geht nicht.
  Mit Zitat antworten Zitat
23. Apr 2008, 21:05
Dieses Thema wurde von "Matze" von "Programmieren allgemein" nach "Object-Pascal / Delphi-Language" verschoben.
Delphi-Frage
Antwort Antwort
Seite 1 von 2  1 2      


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 11:31 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