Elimde şöyle bir attribute sınıfım var
Birde aşağıdaki gibi bir table sınıfım var. Bu table sınıfına Table ve Field attribute tanımlamalarını yapıyorum.
Bu fonksiyonla table attribute bilgilsine çalışma sırasında erişebiliyorum
Bu fonksiyonla field attribute bilgilerinin tümüne çalışma sırasında erişebiliyorum. Şu anda ikinci parametrenin hiç bir anlamı yok.
fonksiyonları şu şekilde çağırarak table ve field attribute bilgilerine erişiyorum
type AttTableName = class(TCustomAttribute) private FName: string; public property Name: string read FName write FName; constructor Create(AValue: string); end; AttFieldName = class(TCustomAttribute) private FName: String; public property Name: String read FName write FName; end;
Birde aşağıdaki gibi bir table sınıfım var. Bu table sınıfına Table ve Field attribute tanımlamalarını yapıyorum.
type
[AttTableName('country')]
TCountry = class(TTable)
private
FCountryCode : string;
FCountryName : string;
public
[AttFieldName('country_code')]
Property CountryCode : string read FCountryCode write FCountryCode;
[AttFieldName('country_name')]
Property CountryName : string read FCountryName write FCountryName;
end;
Bu fonksiyonla table attribute bilgilsine çalışma sırasında erişebiliyorum
function GetTableAttribute(pClass: TTable): string; var vC: TRttiContext; vT: TRttiType; vA: TCustomAttribute; begin Result := ''; if pClass <> nil then begin vC := TRttiContext.Create; try vT := vC.GetType(pClass.ClassType); for vA in vT.GetAttributes do if vA is AttTableName then Result := Result + (vA as AttTableName).Name; finally vC.Free end; end; end;
Bu fonksiyonla field attribute bilgilerinin tümüne çalışma sırasında erişebiliyorum. Şu anda ikinci parametrenin hiç bir anlamı yok.
function TTable.GetFieldAttribute(pClass: TTable; pFieldName: string): string; var vC: TRttiContext; vT: TRttiType; vA: TCustomAttribute; vP: TRttiProperty; begin Result := ''; if pClass <> nil then begin vC := TRttiContext.Create; try vT := vC.GetType(pClass.ClassType); for vP in vT.GetProperties do begin - for vA in vP.GetAttributes do begin if vA is AttFieldName then Result := Result + AttFieldName(vA).Name + sLineBreak; end; end; finally vC.Free end; end; end;
fonksiyonları şu şekilde çağırarak table ve field attribute bilgilerine erişiyorum
vCountry := TCountry.Create(SingletonDB.DataBase); try ShowMessage(vCountry.GetFieldAttribute(vCountry, '')); ShowMessage(vCountry.GetTableAttribute(vCountry)); finally vCountry.Free; end;
{
** Fakat benim istediğim sadece istediğim property için attribute bilgisine erişmek.
** Bu şekilde sadece istediğim property için attribute bilgisini alabilir miyim? Bunu nasıl yapabilirim?
** Property ler içinde yeni TFieldDB şeklinde yeni bir sınıf yapıp. Bu sınıf üzerinden mi attribute almalıyım.
classType.PropertyName
}
vCountry.CountryCode
PostgreSQL - Linux - Delphi, Poliüretan

