![]() |
Kann man den Typ vererbter Properties oder Methoden ändern
Hallo,
ich versuche gerade, den Zugriff auf DataModule in meinem Code zu vereinfachen. Momentan habe ich eine virtuelle Methode DM: TDataModule in meinen Base DataForms. In den abgeleiteten DataForms wie TfrmKunde ist aber der Typ dann z.B. TDMKunden. Momentan caste ich beim Zugriff immer, wenn ich spezielle Eigenschaften des DataModules brauche. Genial wäre es, wenn ich auch in TfrmKunden einfach DM verwenden könnte ohne zu casten. Den Typ kann ich aber nicht ändern, oder gibt es da einen Trick? Frank |
AW: Kann man den Typ vererbter Properties oder Methoden ändern
Du meinst in etwa so?
Delphi-Quellcode:
type
TBaseDataModule = class end; TBaseDataForm = class private FDataModule: TBaseDataModule; protected function GetDataModule: TBaseDataModule; procedure SetDataModule(const Value: TBaseDataModule); public property DataModule: TBaseDataModule read GetDataModule write SetDataModule; end; TCustomerDataModule = class(TBaseDataModule) end; TCustomerDataForm = class(TBaseDataForm) protected function GetDataModule: TCustomerDataModule; procedure SetDataModule(const Value: TCustomerDataModule); public property DataModule: TCustomerDataModule read GetDataModule write SetDataModule; end; { TBaseDataForm } function TBaseDataForm.GetDataModule: TBaseDataModule; begin Result := FDataModule end; procedure TBaseDataForm.SetDataModule(const Value: TBaseDataModule); begin FDataModule := Value; end; { TCustomerDataForm } function TCustomerDataForm.GetDataModule: TCustomerDataModule; begin Result := inherited GetDataModule as TCustomerDataModule; end; procedure TCustomerDataForm.SetDataModule(const Value: TCustomerDataModule); begin inherited SetDataModule(Value); end; |
AW: Kann man den Typ vererbter Properties oder Methoden ändern
Zitat:
Ich hatte es so schon probiert, bin aber durch einen peinlichen Fehler erfolglos gewesen. Vielen Dank. Frank |
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:39 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz