Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-02

Getting a Field list of a record

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Johann Spies

I see TDataset has a method to get a list of fields. Is there something similar for type: record?

Say for instance I want to check which fields of a record are empty, how can I do it without having to specify each field manually?

Another example: If I want to compare two records of the same type to determine which fields differ. How do I do it and get only a list of the fields involved?

Regards
Johann

Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130214/61aae14a/attachment.html>

Reply by email

Marcos Douglas
to Johann Spies
Johann Spies wrote 9 lines
I see TDataset has a method to get a list of fields. Is there something similar for type: record? Say for instance I want to check which fields of a record are empty, how can I do it without having to specify each field manually? Another example: If I want to compare two records of the same type to determine which fields differ. How do I do it and get only a list of the fields involved?

Instead of record type, try to use TParams class.
The TParams has items of TParam. You can use methods to know if the item is empty, casting .(AsInteger, .AsString,...), loop in all items without specifying the names, etc

Marcos Douglas

Reply by email

Alejandro Gonzalo
to Johann Spies: I see TDataset has a method to get a list of fields. Is there something similar for type:…

You could use a variants instead of records, an enumeration list could keep track of the "field names". Your user clause has to include variants.? Here is part of a procedure I used for another purpose: ?
var aRecord : variant;
? ??? i : integer;
begin???????????
for i := 0 to Dataset.FieldCount-1 do
??? aRecord[i]:= Dataset.Fields[i].Value;
?
A. G.

Show quoted text 28 lines
________________________________ From: Johann Spies To: Lazarus mailing list Sent: Thursday, February 14, 2013 3:00 AM Subject: [Lazarus] Getting a Field list of a record I see TDataset has a method to get a list of fields. Is there something similar for type: record?? Say for instance I want to check which fields of a record are empty, how can I do it without having to specify each field manually? Another example: If I want to compare two records of the same type to determine which fields differ.? How do I do it and get only a list of the fields involved? Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you.? (Psalm 63:3) -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130216/22fbf1fc/attachment-0001.html>

Reply by email

Alejandro Gonzalo
to Alejandro Gonzalo
whoops, forgot you have to include this line before the "for" clause:
?? aRecord:= VarArrayCreate([0, Dataset.FieldCount-1], varVariant);
?
A. G;
Show quoted text 54 lines
________________________________ From: Alejandro Gonzalo To: Lazarus mailing list Sent: Saturday, February 16, 2013 4:09 PM Subject: Re: [Lazarus] Getting a Field list of a record You could use a variants instead of records, an enumeration list could keep track of the "field names". Your user clause has to include variants.? Here is part of a procedure I used for another purpose: ? var aRecord : variant; ? ??? i : integer; begin??????????? for i := 0 to Dataset.FieldCount-1 do ??? aRecord[i]:= Dataset.Fields[i].Value; A. G. >________________________________ > From: Johann Spies >To: Lazarus mailing list >Sent: Thursday, February 14, 2013 3:00 AM >Subject: [Lazarus] Getting a Field list of a record > > >I see TDataset has a method to get a list of fields. Is there something similar for type: record?? > >Say for instance I want to check which fields of a record are empty, how can I do it without having to specify each field manually? > >Another example: If I want to compare two records of the same type to determine which fields differ.? How do I do it and get only a list of the fields involved? > >Regards >Johann > >-- >Because experiencing your loyal love is better than life itself, >my lips will praise you.? (Psalm 63:3) > >-- >_______________________________________________ >Lazarus mailing list > >http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > > > -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130216/6e75f7d8/attachment.html>

Reply by email

Johann Spies
to Alejandro Gonzalo
Alejandro Gonzalo wrote
whoops, forgot you have to include this line before the "for" clause: aRecord:= VarArrayCreate([0, Dataset.FieldCount-1], varVariant);

Thanks.

The replies to my question made me realise that I will have to do do a lot of catchup. I recently came back to pascal after about 18 years of inactivity.

I did not even know about the 'variant' option and I know very little about TDataset and TParams and a lot of the (to me) new stuff added to the language.

Regards
Johann

Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130218/2f19047b/attachment-0001.html>

Reply by email