RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TField.AssignValue Method

Sets the field value using one of the AsInteger, AsBoolean, AsString or AsFloat properties.

Pascal
procedure AssignValue(const Value: TVarRec);
C++
__fastcall AssignValue(const TVarRec Value);

Use AssignValue to assign a value to a field and, in Delphi, that comes from an array of const. AssignValue uses an As… property for the assignment based on the type of the Value parameter:

If Value is not one of the types in the table, but is of type TObject or a TObject descendant, AssignValue uses the Assign method to assign the value to the field. 

AssignValue exists primarily for internal use. In C++ applications and components, use the TField::Value property instead. In most Delphi situations, you should use the data type-specific assignment properties like AsString and AsInteger. In cases where a component or an application must be able to make field assignments from untyped arrays, the syntax for AssignValue looks like that below. In this example, a custom data class uses AssignValue in a member method named SetFieldValues to assign values to multiple fields. The values for the field assignments come from an untyped array.

procedure TCustomDataClass.SetFieldValues(Values: array of const);
var
  i: Integer;
begin
for i := 0 to High(Values) do
    Fields[i].AssignValue(Values[i]);
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!