Статьи по Delphi (026)…

Как создать вычисляемые поля во время исполнения программы.

Как создать вычисляемые поля во время исполнения программы

Автор: Nomadic.

Смотрите книгу "Developing Custom Delphi Components" от Рэя Конопки.

Здесь немного исправленный пример из этой книги -

Code: Function TMyClass.CreateCalcField(const AFieldName: string; AFieldClass: TFieldClass; ASize: Word): TField; Begin. Result := FDataSet.FindField(AFieldName); // Field may already exists! If Result <> nil then. Exit; If AFieldClass = nil then. Begin. DBErrorFmt(SUnknownFieldType, [AFieldName]); End; Result := FieldClass.Create(Owner); With Result do. Try. FieldName := AFieldName; If (Result is TStringField) or (Result is TBCDField) or. (Result is TBlobField) or (Result is TBytesField) or. (Result is TVarBytesField) then. Begin. Size := ASize; End; Calculated := True; DataSet := FDataset; Name := FDataSet.Name + AFieldName; Except. Free; // We must release allocated memory on error! Raise; End; End;

©Drkb::02621.

Http://delphiworld.narod.ru/

DelphiWorld 6.0.