[Lazarus] RE : RE : How to get field-names of a table ?

Ludo Brands ludo.brands at free.fr
Mon Jan 9 17:34:24 CET 2012


> On 06-01-12 17:19, Ludo Brands wrote:
> > designer then just add a
> >    SQLQuery1.Active:=true;
> 
> > before the above loop to auto fill the fielddefs. For this
> to work, as
> > for fields, Fielddefs should be an empty array. As soon on
> element is
> > in fielddefs, the auto fill won't work.
> >
> 
> Hi,
> 
> Thanks Ludo, opening the query auto-filled the fielddefs, if
> there were 
> no manually created fielddefs.
> 

That is from inside lazarus. The code snippet did the same at run time.

> Now I have to give each field an onGetText event. I was 
> looking for some 
> documents, but I seem unable to find something. Any help ?
> I tried several things but only this compiles, and it even 
> works : for i:=0 to MyQuery.FieldDefs.Count-1 do
>   MyQuery.Fields.Fields[i].OnGetText:=@MyQueryDATAGetText;
> 
> I created MyQueryDATAGetText by manually creating a field, creating 
> onGetText by double-clicking on it and putting my code in it. 
> Afterwards I deleted the field.
> 
> Is this OK ? To me it seems a hack.
> 

Normally, when you need to use field events, you would create persistent
fields. With Fielddefs populated, double click on the TSQLQuery and click on
the + sign. You'll see a list of all fielfs in fielddefs. Select all fields
and OK. You have now created persistent fields as opposed to fields created
automatically by opening a dataset. All field settings are now permanent,
including events assigned to them.

BTW, I would replace 
 for i:=0 to MyQuery.FieldDefs.Count-1 do
With
 for i:=0 to MyQuery.Fields.Count-1 do

Ludo

> Thanks.
> 
> Regards,
> 
> Koenraad Lelong
> 
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
> 





More information about the Lazarus mailing list