![]() |
Delphi-Version: 10 Seattle
TClientDataSet aus Klassenstruktur
Gibt es eine Moeglichkeit, ein
Delphi-Quellcode:
automatisch aus einer Objekt-Struktur zu bestuecken?
TClientDataSet
Ich will vermeiden, fuer eine Klasse
Delphi-Quellcode:
ein TClientDataSet ausfuehrlich mit
type
TIngredient = class(TCollectionItem) private FName, // <<--- FArticleNumber, FScaleUnit, FBarcode, FCategory: String; published property Name: String read FName write FName; // <<--- property ArticleNumber: String read FArticleNumber write FArticleNumber; property ScaleUnit: String read FScaleUnit write FScaleUnit; property Barcode: String read FBarcode write FBarcode; property Category: String read FCategory write FCategory; end; TIngredients = class(TPersistent) private FIngredients: TCollection; public constructor Create; destructor Destroy; procedure Read; procedure Write; function GetIngredient(Index: Integer): TIngredient; procedure SetIngredient(Index: Integer; Value: TIngredient); property Item[Index: Integer]: TIngredient read GetIngredient write SetIngredient; default; published property Items: TCollection read FIngredients write FIngredients; end;
Delphi-Quellcode:
etc. zu bestuecken.
TClientDataSet.FieldDefs.Add('Name', ftString, 0, False); // <<---
Ich will die Klasse TIngredient angeben und die FieldDefs automatisch aus den published properties ableiten lassen. |
AW: TClientDataSet aus Klassenstruktur
Zitat:
|
AW: TClientDataSet aus Klassenstruktur
Zitat:
Kann aber echt nichts fertiges finden. Komisch, das Problem stellt sich sicher oefters... Danke fuers Lesen |
AW: TClientDataSet aus Klassenstruktur
In seinem Buch Mastering Delphi 7 beschreibt Marco Cantú im Kapitel
![]()
Delphi-Quellcode:
procedure TMdObjDataSet.InternalInitFieldDefs;
var i: Integer; begin if FObjClass = nil then raise Exception.Create ('TMdObjDataSet: Unassigned class'); // field definitions FieldDefs.Clear; nProps := GetTypeData(fObjClass.ClassInfo)^.PropCount; GetMem(PropList, nProps * SizeOf(Pointer)); GetPropInfos (fObjClass.ClassInfo, PropList); for i := 0 to nProps - 1 do case PropList [i].PropType^.Kind of tkInteger, tkEnumeration, tkSet: FieldDefs.Add (PropList [i].Name, ftInteger, 0); tkChar: FieldDefs.Add (PropList [i].Name, ftFixedChar, 0); tkFloat: FieldDefs.Add (PropList [i].Name, ftFloat, 0); tkString, tkLString: FieldDefs.Add (PropList [i].Name, ftString, 50); // TODO: fix size tkWString: FieldDefs.Add (PropList [i].Name, ftWideString, 50); // TODO: fix size end; end; |
AW: TClientDataSet aus Klassenstruktur
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:34 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