[DUG] Creating fields at runtime
Alister Christie
alister at SalesPartner.co.nz
Wed Jun 1 11:51:56 NZST 2005
For those interested in a solution:
q := TQuery.Create(Nil);
try
q.DatabaseName := 'Rezy';
q.SQL.Add('Select Surname, Tit_Init, Greeting, StNo, Street, Add2,
Add3, Ph1, Ph1Type, Ph2, Ph2Type, Ph3, Ph3Type, Fax, Price, Bedrooms,
email, LookingFor');
q.SQL.Add('from contact where status = ''A''');
q.Name := 'Contact';
q.Open; //fill fielddefs
q.Close;
for i := 0 to pred(q.FieldDefs.Count) do
q.FieldDefs[i].CreateField(q);
strfield := TStringField.Create(q);
strfield.FieldKind := fkCalculated;
strfield.FieldName := 'RequirementsDesc';
strfield.Size := 200;
strfield.DataSet := q;
q.OnCalcFields := qContactCalcField;
q.Open;
....
Open and Close needs to be called to fill the fielddefs property. This
is probably similar to what the IDE does to add fields in the fields
editor. I hope someone else finds this useful.
Alister Christie
Computers for People
Ph: 04 471 1849 Fax: 04 471 1266
http://www.salespartner.co.nz
PO Box 13085
Johnsonville
Wellington
Alister Christie wrote:
> No it's created at runtime:
>
> q := TQuery.Create(Nil);
> q.DatabaseName := 'Rezy';
> q.SQL.Add('Select Surname, Tit_Init, Greeting, StNo, Street, Add2,
> Add3, Ph1, Ph1Type, Ph2, Ph2Type, Ph3, Ph3Type, Fax, Price, Bedrooms,
> email');
> q.SQL.Add('from contact where status = ''A''');
> q.Name := 'Contact';
> // q.OnCalcFields := qContactCalcField;
> // strfield := TStringField.Create(q);
> // strfield.FieldName := 'RequirementsDesc';
> // strfield.FieldKind := fkCalculated;
> // strfield.DataSet := q;
> q.Open;
>
> The commented out bit creates the calculated field which obscures the
> other fields once created. I want to be able to add all the other
> fields to the q.Fields property, but not have to write the code to add
> each field individually.
>
> Any Suggestions?
>
> Alister Christie
> Computers for People
> Ph: 04 471 1849 Fax: 04 471 1266
> http://www.salespartner.co.nz
> PO Box 13085
> Johnsonville
> Wellington
>
> Todd Martin wrote:
>
>> Are your existing fields in the dataset create at design time?
>>
>> ----- Original Message ----- From: "Alister Christie"
>> <alister at salespartner.co.nz>
>> To: "NZ Borland Developers Group - Delphi List" <delphi at ns3.123.co.nz>
>> Sent: Tuesday, May 31, 2005 1:29 PM
>> Subject: [DUG] Creating fields at runtime
>>
>>
>>> I'm creating a TQuery (descriptively called q) at runtime with a with
>>> a query such as "select * from contact". However I want to add a
>>> calculated field to this using the following code
>>> strfield := TStringField.Create(q);
>>> strfield.FieldName := 'RequirementsDesc';
>>> strfield.FieldKind := fkCalculated;
>>> strfield.DataSet := q;
>>> However, by adding a calculated field I hide all the fields in the
>>> fielddefs. Does anyone know of a way around this, either by putting
>>> the calculated field in q.fielddefs or adding all the fields to
>>> q.fields in some easy fashion
>>>
>>>
>>> --
>>> Alister Christie
>>> Computers for People
>>> Ph: 04 471 1849 Fax: 04 471 1266
>>> http://www.salespartner.co.nz
>>> PO Box 13085
>>> Johnsonville
>>> Wellington
>>> _______________________________________________
>>> Delphi mailing list
>>> Delphi at ns3.123.co.nz
>>> http://ns3.123.co.nz/mailman/listinfo/delphi
>>>
>>>
>>
>>
> _______________________________________________
> Delphi mailing list
> Delphi at ns3.123.co.nz
> http://ns3.123.co.nz/mailman/listinfo/delphi
>
>
More information about the Delphi
mailing list