Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TField in Memory...

Status
Not open for further replies.

Ulfeng

Programmer
Dec 9, 2001
12
US
I have a requirement to add a TField in memory to an in-memory TQuery. This TQuery component is not on a data module.

The code follows: Note AField is defined as TField;
qCorrect:= TQuery.Create(nil);
with qCorrect do begin
Name := 'qCorrect';
AutoCalcFields := False;
DataBaseName := fDataBaseName;
SessionName := fCurrSessionName;
BeforeOpen := qBeforeOpen;
OnCalcFields := qCorrectCalcFields;
//persistent fields for <correct> follow....
Fields.Clear;
AField := TIntegerField.Create(qCorrect);
if Assigned(AField) then begin
with AField do begin
name := 'qCorrectnumLR';
fieldName := 'numLR';
fieldKind := fkCalculated;
ReadOnly := False;
//DisplayName := 'numLR';
required := False;
end;
Fields.Add(AField);
end;
When the OnCalcFields event fires I get an error for the calculated field that says: &quot;Error Field 'numLR' has no dataset&quot;.

Anybody know why this occurs? Thanks, Jonathan

 
Do you not need to add some SQL to it, so it can perform the calculations on the open
 
If it says that a field has no dataset, then &quot;give&quot; it dataset :)
Code:
...
 if Assigned(AField) then begin
 with AField do begin
   DataSet := qCorrect; // <-- here :)
   name := 'qCorrectnumLR';
   ...
 end;

--- markus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top