Autor Beitrag
r4id3n
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 115

Win XP Home, Win XP Pro
D6 Prof, D7 Ent, K3 Ent
BeitragVerfasst: So 02.01.05 22:32 
Hallo zusamen, habe folgendes problem ....

Wenn ich folgenden code habe

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TBasisklasse= class(TPersistent)
  public
    constructor Create(Mess:String); overload; virtual;
    destructor destroy; override;
  end;

  TAbgeleiteteKlasse=class(TBasisklasse)
  public
    constructor Create(mess:String); overload;
    destructor destroy; override;
  end;
  TBasisKlasseClass = class of TBasisklasse;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TBasisklasse }

constructor TBasisklasse.Create(Mess: String);
begin
  ShowMessage('Basis' + mess);
  inherited create;
end;

destructor TBasisklasse.destroy;
begin

  inherited;
end;

{ TAbgeleiteteKlasse }

constructor TAbgeleiteteKlasse.Create(mess: String);
begin
  ShowMessage('ext' + mess);
  inherited create(Mess);
end;

destructor TAbgeleiteteKlasse.destroy;
begin

  inherited;
end;

procedure TForm1.Button1Click(Sender: TObject);
var Klasse:TBasisKlasseClass;

    KlassenInstanz:TBasisKlasse;
begin
    RegisterClass(TAbgeleiteteKlasse);
    Klasse:=TBasisKlasseClass(FindClass('TAbgeleiteteKlasse'));
    KlassenInstanz:=Klasse.Create('1');
    KlassenInstanz.Free;
end;

end.


Erhalte ich leider immer nur die messagebox der basisklasse, nicht aber der der abgeleiteen klasse! Sieht jemand den fehler???

Wenn ich das ganze ohne register class mache, funktioniert es wunderbar!

THX
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 03.01.05 01:17 
Ich weiß nicht, ob du auf die Compiler-Meldungen geachtet hast, aber der Compiler sollte glaube sowas in der Art "Warnung: TAbgeleiteteKlasse verbirgt geerbte Methode Create aus TBasisKlasse" oder ähnlich bringen.

Du musst bei jeder Klasse, die du ableitest darauf achten, dass du nicht verbirgst, sondern mit "override;" überschreibst.

Ergänze in Zeile 27 mal noch ein override;. Dann sollte das theoretisch funzen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
r4id3n Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 115

Win XP Home, Win XP Pro
D6 Prof, D7 Ent, K3 Ent
BeitragVerfasst: Mo 03.01.05 14:26 
Argh, manchmal sieht man den wald vor lauter bäumen nicht! THX